This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new cb1746b4435 drivers/bch: close block driver on setup failure
cb1746b4435 is described below

commit cb1746b4435ebd9b2e76ecd4a96ec5212e4605f4
Author: chao an <[email protected]>
AuthorDate: Wed Oct 21 13:52:59 2026 +0800

    drivers/bch: close block driver on setup failure
    
    bchlib_setup() opens the backing block driver before querying geometry
    and validating write support.  If one of those validation steps failed,
    the error path freed the BCH state structure without closing the block
    driver that had already been opened.
    
    Route post-open validation failures through a cleanup path that closes the
    block driver before freeing the BCH state structure.
    
    Signed-off-by: chao an <[email protected]>
---
 drivers/bch/bchlib_setup.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/bch/bchlib_setup.c b/drivers/bch/bchlib_setup.c
index 7f17fe3e11e..8be5baddeaf 100644
--- a/drivers/bch/bchlib_setup.c
+++ b/drivers/bch/bchlib_setup.c
@@ -89,21 +89,21 @@ int bchlib_setup(FAR const char *blkdev, int oflags, FAR 
void **handle)
   if (ret < 0)
     {
       ferr("ERROR: geometry failed: %d\n", -ret);
-      goto errout_with_bch;
+      goto errout_with_inode;
     }
 
   if (!geo.geo_available)
     {
       ferr("ERROR: geometry failed: %d\n", -ret);
       ret = -ENODEV;
-      goto errout_with_bch;
+      goto errout_with_inode;
     }
 
   if (!readonly && (!bch->inode->u.i_bops->write || !geo.geo_writeenabled))
     {
       ferr("ERROR: write access not supported\n");
       ret = -EACCES;
-      goto errout_with_bch;
+      goto errout_with_inode;
     }
 
   /* Save the geometry info and complete initialization of the structure */
@@ -116,6 +116,9 @@ int bchlib_setup(FAR const char *blkdev, int oflags, FAR 
void **handle)
   *handle = bch;
   return OK;
 
+errout_with_inode:
+  close_blockdriver(bch->inode);
+
 errout_with_bch:
   kmm_free(bch);
   return ret;

Reply via email to