Skip to content

Commit 1cfa2f7

Browse files
tititiou36miquelraynal
authored andcommitted
mtd: rawnand: rockchip: Use struct_size()
Use struct_size() instead of hand writing it. This is less verbose and more robust. While at it, prepare for the coming implementation by GCC and Clang of the __counted_by attribute. Flexible array members annotated with __counted_by can have their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family functions). Also remove a useless comment about the position of a flex-array in a structure. Signed-off-by: Christophe JAILLET <[email protected]> Reviewed-by: Gustavo A. R. Silva <[email protected]> Reviewed-by: Kees Cook <[email protected]> Acked-by: Heiko Stuebner <[email protected]> Signed-off-by: Miquel Raynal <[email protected]> Link: https://lore.kernel.org/linux-mtd/481721c2c7fe570b4027dbe231d523961c953d5a.1696146232.git.christophe.jaillet@wanadoo.fr
1 parent f693b64 commit 1cfa2f7

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

drivers/mtd/nand/raw/rockchip-nand-controller.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,7 @@ struct rk_nfc_nand_chip {
158158
u32 timing;
159159

160160
u8 nsels;
161-
u8 sels[];
162-
/* Nothing after this field. */
161+
u8 sels[] __counted_by(nsels);
163162
};
164163

165164
struct rk_nfc {
@@ -1119,7 +1118,7 @@ static int rk_nfc_nand_chip_init(struct device *dev, struct rk_nfc *nfc,
11191118
return -EINVAL;
11201119
}
11211120

1122-
rknand = devm_kzalloc(dev, sizeof(*rknand) + nsels * sizeof(u8),
1121+
rknand = devm_kzalloc(dev, struct_size(rknand, sels, nsels),
11231122
GFP_KERNEL);
11241123
if (!rknand)
11251124
return -ENOMEM;

0 commit comments

Comments
 (0)