Skip to content

Commit

Permalink
filemtd:Fix teardown return error number EINVAL
Browse files Browse the repository at this point in the history
In previous versions, during the teardown phase, the "open_blockdriver" would call the "mtd proxy" causing the "file mtd" node to be registered in the ftl. " node is registered in ftl.
Therefore, we changed the behavior to find the corresponding inode by node name.

Signed-off-by: chenrun1 <[email protected]>
  • Loading branch information
crafcat7 authored and xiaoxiang781216 committed Oct 14, 2023
1 parent 095c32b commit 73ca090
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions drivers/mtd/filemtd.c
Original file line number Diff line number Diff line change
Expand Up @@ -569,14 +569,12 @@ static int mtd_loop_teardown(FAR const char *devname)
FAR struct inode *inode;
int ret;

/* Open the block driver associated with devname so that we can get the
* inode reference.
*/
/* Find the reference to the inode by devname */

ret = open_blockdriver(devname, MS_RDONLY, &inode);
ret = find_mtddriver(devname, &inode);
if (ret < 0)
{
ferr("ERROR: Failed to open %s: %d\n", devname, -ret);
ferr("ERROR: Failed to find %s: %d\n", devname, -ret);
return ret;
}

Expand All @@ -589,16 +587,16 @@ static int mtd_loop_teardown(FAR const char *devname)
if (!filemtd_isfilemtd(&dev->mtd))
{
ferr("ERROR: Device is not a FILEMTD loop: %s\n", devname);
close_mtddriver(inode);
return -EINVAL;
}

close_blockdriver(inode);
close_mtddriver(inode);

/* Now teardown the filemtd */

filemtd_teardown(&dev->mtd);
unregister_blockdriver(devname);
kmm_free(dev);
unregister_mtddriver(devname);

return OK;
}
Expand Down

0 comments on commit 73ca090

Please sign in to comment.