Skip to content

Commit 7b30196

Browse files
GustavoARSilvamiquelraynal
authored andcommitted
mtd: rawnand: marvell: use struct_size() in devm_kzalloc()
One of the more common cases of allocation size calculations is finding the size of a structure that has a zero-sized array at the end, along with memory for some number of elements for that array. For example: struct foo { int stuff; void *entry[]; }; instance = devm_kzalloc(dev, sizeof(struct foo) + sizeof(void *) * count, GFP_KERNEL); Instead of leaving these open-coded and prone to type mistakes, we can now use the new struct_size() helper: instance = devm_kzalloc(dev, struct_size(instance, entry, count), GFP_KERNEL); This code was detected with the help of Coccinelle. Signed-off-by: Gustavo A. R. Silva <[email protected]> Signed-off-by: Miquel Raynal <[email protected]>
1 parent 511d05e commit 7b30196

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

drivers/mtd/nand/raw/marvell_nand.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2550,9 +2550,8 @@ static int marvell_nand_chip_init(struct device *dev, struct marvell_nfc *nfc,
25502550
}
25512551

25522552
/* Alloc the nand chip structure */
2553-
marvell_nand = devm_kzalloc(dev, sizeof(*marvell_nand) +
2554-
(nsels *
2555-
sizeof(struct marvell_nand_chip_sel)),
2553+
marvell_nand = devm_kzalloc(dev,
2554+
struct_size(marvell_nand, sels, nsels),
25562555
GFP_KERNEL);
25572556
if (!marvell_nand) {
25582557
dev_err(dev, "could not allocate chip structure\n");

0 commit comments

Comments
 (0)