Commit 045391a0 authored by Kees Cook's avatar Kees Cook Committed by Lee Jones
Browse files

leds: gpio: Set num_leds after allocation



With the new __counted_by annotation, the "num_leds" variable needs to
valid for accesses to the "leds" array. This requirement is not met in
gpio_leds_create(), since "num_leds" starts at "0", so "leds" index "0"
will not be considered valid (num_leds would need to be "1" to access
index "0").

Fix this by setting the allocation size after allocation, and then update
the final count based on how many were actually added to the array.

Fixes: 52cd7510 ("leds: gpio: Annotate struct gpio_leds_priv with __counted_by")
Signed-off-by: default avatarKees Cook <kees@kernel.org>
Reviewed-by: default avatarGustavo A. R. Silva <gustavoars@kernel.org>
Link: https://lore.kernel.org/r/20240716212455.work.809-kees@kernel.org


Signed-off-by: default avatarLee Jones <lee@kernel.org>
parent e5ae4083
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment