mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-01-08 05:24:32 -05:00
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 <christophe.jaillet@wanadoo.fr> Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org> Reviewed-by: Kees Cook <keescook@chromium.org> Acked-by: Heiko Stuebner <heiko@sntech.de> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> Link: https://lore.kernel.org/linux-mtd/481721c2c7fe570b4027dbe231d523961c953d5a.1696146232.git.christophe.jaillet@wanadoo.fr
This commit is contained in:
committed by
Miquel Raynal
parent
f693b6485e
commit
1cfa2f76af
@@ -158,8 +158,7 @@ struct rk_nfc_nand_chip {
|
||||
u32 timing;
|
||||
|
||||
u8 nsels;
|
||||
u8 sels[];
|
||||
/* Nothing after this field. */
|
||||
u8 sels[] __counted_by(nsels);
|
||||
};
|
||||
|
||||
struct rk_nfc {
|
||||
@@ -1119,7 +1118,7 @@ static int rk_nfc_nand_chip_init(struct device *dev, struct rk_nfc *nfc,
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
rknand = devm_kzalloc(dev, sizeof(*rknand) + nsels * sizeof(u8),
|
||||
rknand = devm_kzalloc(dev, struct_size(rknand, sels, nsels),
|
||||
GFP_KERNEL);
|
||||
if (!rknand)
|
||||
return -ENOMEM;
|
||||
|
||||
Reference in New Issue
Block a user