* [PATCH] mtd: jedec_probe: use struct_size() helper for cfiq allocation
@ 2025-09-22 7:11 Rahul Kumar
2025-09-29 16:03 ` Miquel Raynal
0 siblings, 1 reply; 2+ messages in thread
From: Rahul Kumar @ 2025-09-22 7:11 UTC (permalink / raw)
To: miquel.raynal, richard, vigneshr
Cc: linux-mtd, linux-kernel, linux-kernel-mentees, skhan, rk0006818
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@gmail.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
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] mtd: jedec_probe: use struct_size() helper for cfiq allocation
2025-09-22 7:11 [PATCH] mtd: jedec_probe: use struct_size() helper for cfiq allocation Rahul Kumar
@ 2025-09-29 16:03 ` Miquel Raynal
0 siblings, 0 replies; 2+ messages in thread
From: Miquel Raynal @ 2025-09-29 16:03 UTC (permalink / raw)
To: richard, vigneshr, Rahul Kumar
Cc: linux-mtd, linux-kernel, linux-kernel-mentees, skhan
On Mon, 22 Sep 2025 12:41:37 +0530, Rahul Kumar wrote:
> 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.
>
> [...]
Applied to mtd/next, thanks!
[1/1] mtd: jedec_probe: use struct_size() helper for cfiq allocation
commit: 527668868862e0db65efc88fe82040f1e48d4ab3
Patche(s) should be available on mtd/linux.git and will be
part of the next PR (provided that no robot complains by then).
Kind regards,
Miquèl
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-09-29 16:11 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-22 7:11 [PATCH] mtd: jedec_probe: use struct_size() helper for cfiq allocation Rahul Kumar
2025-09-29 16:03 ` Miquel Raynal
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox