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

xiaoxiang 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 0a381a3ff73 driver/cfi: fix write failed issue for unalign length with 
bankwidth
0a381a3ff73 is described below

commit 0a381a3ff73e854c2059216686624ad740e81f15
Author: dongjiuzhu1 <[email protected]>
AuthorDate: Wed Dec 3 15:34:42 2025 +0800

    driver/cfi: fix write failed issue for unalign length with bankwidth
    
    1. In cfi_write_unalign(): Add additional check to ensure nbytes is
       at least bankwidth size before skipping unaligned start handling.
       This prevents incorrect behavior when writing small amounts of
       data that are less than bankwidth.
    
    2. In cfi_write(): Align down the write size to bankwidth boundary
       when the remaining nbytes is less than the buffer write size.
       This ensures the buffer write operation always works with properly
       aligned data size, preventing write failures.))
    
    Signed-off-by: dongjiuzhu1 <[email protected]>
---
 drivers/mtd/cfi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/cfi.c b/drivers/mtd/cfi.c
index ec0853bfa05..c51f5ed8814 100644
--- a/drivers/mtd/cfi.c
+++ b/drivers/mtd/cfi.c
@@ -810,7 +810,7 @@ static ssize_t cfi_write_unalign(FAR struct cfi_dev_s *cfi, 
off_t offset,
 
   /* handle unaligned start */
 
-  if ((delta = offset - wp) == 0)
+  if ((delta = offset - wp) == 0 && nbytes >= cfi->bankwidth)
     {
       return 0;
     }
@@ -1096,7 +1096,7 @@ int cfi_write(FAR struct cfi_dev_s *cfi, off_t offset, 
size_t nbytes,
 
           if (size > nbytes)
             {
-              size = nbytes;
+              size = ALIGN_DOWN(nbytes, cfi->bankwidth);
             }
 
           ret = cfi_write_buffer(cfi, offset, size, buffer);

Reply via email to