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 29729d61c77 drivers/mtd: fix rwbuffer bulk erase error check
29729d61c77 is described below

commit 29729d61c774507154f38103c73d816be026da16
Author: chao an <[email protected]>
AuthorDate: Wed Oct 21 13:50:15 2026 +0800

    drivers/mtd: fix rwbuffer bulk erase error check
    
    mtd_ioctl() in the rwbuffer wrapper handles MTDIOC_BULKERASE by first
    forwarding the erase request to the wrapped MTD device and then
    invalidating the read/write buffer cache.
    
    The error check after the wrapped device ioctl was inverted, so a
    successful bulk erase was treated as a failure and the cache invalidation
    step was skipped.  Check for a negative return value instead so the cache
    is invalidated after a successful erase.
    
    Signed-off-by: chao an <[email protected]>
---
 drivers/mtd/mtd_rwbuffer.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/drivers/mtd/mtd_rwbuffer.c b/drivers/mtd/mtd_rwbuffer.c
index 566f7fd665f..872251b6c15 100644
--- a/drivers/mtd/mtd_rwbuffer.c
+++ b/drivers/mtd/mtd_rwbuffer.c
@@ -145,6 +145,7 @@ static ssize_t mtd_reload(FAR void *dev,
                           size_t nblocks)
 {
   FAR struct mtd_rwbuffer_s *priv = (FAR struct mtd_rwbuffer_s *)dev;
+
   DEBUGASSERT(priv && priv->dev);
 
   /* This is just a pass-through to the contained MTD */
@@ -166,6 +167,7 @@ static ssize_t mtd_flush(FAR void *dev,
                          size_t nblocks)
 {
   FAR struct mtd_rwbuffer_s *priv = (FAR struct mtd_rwbuffer_s *)dev;
+
   DEBUGASSERT(priv && priv->dev);
 
   /* This is just a pass-through to the contained MTD */
@@ -276,6 +278,7 @@ static int mtd_ioctl(FAR struct mtd_dev_s *dev, int cmd, 
unsigned long arg)
         {
           FAR struct mtd_geometry_s *geo = (FAR struct mtd_geometry_s *)
                                            ((uintptr_t)arg);
+
           if (geo)
             {
               memset(geo, 0, sizeof(*geo));
@@ -306,6 +309,7 @@ static int mtd_ioctl(FAR struct mtd_dev_s *dev, int cmd, 
unsigned long arg)
         {
           FAR struct partition_info_s *info =
             (FAR struct partition_info_s *)arg;
+
           if (info != NULL)
             {
               info->numsectors  = priv->rwb.nblocks;
@@ -322,7 +326,7 @@ static int mtd_ioctl(FAR struct mtd_dev_s *dev, int cmd, 
unsigned long arg)
           /* Erase the entire device */
 
           ret = priv->dev->ioctl(priv->dev, MTDIOC_BULKERASE, 0);
-          if (ret >= 0)
+          if (ret < 0)
             {
               ferr("ERROR: Device ioctl failed: %d\n", ret);
               break;
@@ -330,11 +334,11 @@ static int mtd_ioctl(FAR struct mtd_dev_s *dev, int cmd, 
unsigned long arg)
 
           /* Then invalidate in cached data */
 
-         ret = rwb_invalidate(&priv->rwb, 0, priv->rwb.nblocks);
-         if (ret < 0)
-           {
+          ret = rwb_invalidate(&priv->rwb, 0, priv->rwb.nblocks);
+          if (ret < 0)
+            {
               ferr("ERROR: rwb_invalidate failed: %d\n", ret);
-           }
+            }
         }
         break;
 

Reply via email to