[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20250922071137.900508-1-rk0006818@gmail.com>
Date: Mon, 22 Sep 2025 12:41:37 +0530
From: Rahul Kumar <rk0006818@...il.com>
To: miquel.raynal@...tlin.com,
richard@....at,
vigneshr@...com
Cc: linux-mtd@...ts.infradead.org,
linux-kernel@...r.kernel.org,
linux-kernel-mentees@...ts.linuxfoundation.org,
skhan@...uxfoundation.org,
rk0006818@...il.com
Subject: [PATCH] mtd: jedec_probe: use struct_size() helper for cfiq allocation
Documentation/process/deprecated.rst recommends against performing
dynamic size calculations in the arguments of memory allocator
functions due to the risk of overflow. Such calculations can wrap
around and result in a smaller allocation than expected.
Replace the size calculation in cfiq allocation with struct_size()
helper to make the code clearer and handle overflows correctly.
Signed-off-by: Rahul Kumar <rk0006818@...il.com>
---
drivers/mtd/chips/jedec_probe.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/mtd/chips/jedec_probe.c b/drivers/mtd/chips/jedec_probe.c
index 23c32fe584b7..a5d1137ca5ab 100644
--- a/drivers/mtd/chips/jedec_probe.c
+++ b/drivers/mtd/chips/jedec_probe.c
@@ -1985,7 +1985,7 @@ static int cfi_jedec_setup(struct map_info *map, struct cfi_private *cfi, int in
num_erase_regions = jedec_table[index].nr_regions;
- cfi->cfiq = kmalloc(sizeof(struct cfi_ident) + num_erase_regions * 4, GFP_KERNEL);
+ cfi->cfiq = kmalloc(struct_size(cfi->cfiq, EraseRegionInfo, num_erase_regions), GFP_KERNEL);
if (!cfi->cfiq) {
//xx printk(KERN_WARNING "%s: kmalloc failed for CFI ident structure\n", map->name);
return 0;
--
2.43.0
Powered by blists - more mailing lists