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

GUIDINGLI 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 82f15194826 mtd_partition: fix NULL erase dereference in part_ioctl()
82f15194826 is described below

commit 82f1519482667a0fe1e49480b3e7bf02ba4a3246
Author: zhaoxingyu1 <[email protected]>
AuthorDate: Thu Nov 19 00:34:04 2026 +0800

    mtd_partition: fix NULL erase dereference in part_ioctl()
    
    part_ioctl() calls priv->parent->erase directly for MTDIOC_BULKERASE
    and, through part_erase(), for MTDIOC_ERASESECTORS, but the parent
    erase method is NULL on memories without an erase operation, such as
    RRAM, so the ioctl would call through a NULL pointer.
    Return -ENOSYS instead.
    
    Signed-off-by: zhaoxingyu1 <[email protected]>
    Signed-off-by: jingfei <[email protected]>
---
 drivers/mtd/mtd_partition.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/drivers/mtd/mtd_partition.c b/drivers/mtd/mtd_partition.c
index f52c2a6bde7..8ade4816ca2 100644
--- a/drivers/mtd/mtd_partition.c
+++ b/drivers/mtd/mtd_partition.c
@@ -460,6 +460,12 @@ static int part_ioctl(FAR struct mtd_dev_s *dev, int cmd, 
unsigned long arg)
         {
           /* Erase the entire partition */
 
+          if (priv->parent->erase == NULL)
+            {
+              ret = -ENOSYS;
+              break;
+            }
+
           ret = priv->parent->erase(priv->parent,
                                     priv->firstblock / priv->blkpererase,
                                     priv->geo.neraseblocks);
@@ -472,6 +478,12 @@ static int part_ioctl(FAR struct mtd_dev_s *dev, int cmd, 
unsigned long arg)
 
           FAR struct mtd_erase_s *erase = (FAR struct mtd_erase_s *)arg;
 
+          if (priv->parent->erase == NULL)
+            {
+              ret = -ENOSYS;
+              break;
+            }
+
           ret = part_erase(dev, erase->startblock, erase->nblocks);
         }
         break;

Reply via email to