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

commit 8b25fff8b0f65ec0c0e24f7ad40d1ee4243540e4
Author: dengwenqi <[email protected]>
AuthorDate: Thu May 14 21:04:29 2026 +0800

    drivers/misc: Fix Coverity dead code in dev_mem.c
    
    Once f_pos is localized to a memory region but the per-region permission
    flag (PROT_READ/PROT_WRITE) is not set or buflen is zero, break out of
    the loop rather than continuing to iterate. Subsequent iterations cannot
    produce a valid mapping for the same f_pos: offset_in_region would
    underflow and len would be non-positive on every remaining region.
    Control falls through to the existing return -EINVAL at the bottom of
    the function, so behavior is preserved.
    
    This eliminates the logically dead iterations that Coverity flagged as
    DEADCODE.DEFAULT (MISRA C-2012 Rule 2.1). The same fix is applied
    symmetrically to both devmem_read and devmem_write.
    
    Coverity CID: 2806523
    Type: DEADCODE.DEFAULT / Logical dead code / Control flow
    File: drivers/misc/dev_mem.c
    
    Signed-off-by: dengwenqi <[email protected]>
    Signed-off-by: fangxinyong <[email protected]>
    Signed-off-by: wangjianyu3 <[email protected]>
---
 drivers/misc/dev_mem.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/drivers/misc/dev_mem.c b/drivers/misc/dev_mem.c
index e35bf79d699..b7da50b9413 100644
--- a/drivers/misc/dev_mem.c
+++ b/drivers/misc/dev_mem.c
@@ -127,6 +127,13 @@ static ssize_t devmem_read(FAR struct file *filep, FAR 
char *buffer,
               filep->f_pos += len;
               return len;
             }
+
+          /* f_pos maps to this region but read is not permitted or
+           * buflen is 0; further iterations cannot yield a valid
+           * mapping for the same f_pos, so stop scanning.
+           */
+
+          break;
         }
 
       /* Accumulate this region's size for next iteration */
@@ -174,6 +181,13 @@ static ssize_t devmem_write(FAR struct file *filep, FAR 
const char *buffer,
               filep->f_pos += len;
               return len;
             }
+
+          /* f_pos maps to this region but write is not permitted or
+           * buflen is 0; further iterations cannot yield a valid
+           * mapping for the same f_pos, so stop scanning.
+           */
+
+          break;
         }
 
       /* Accumulate this region's size for next iteration */

Reply via email to