mirror of
https://github.com/linux-msm/laptops-kernel.git
synced 2026-08-13 14:19:53 -07:00
backlight: led_bl: Use devm_kcalloc() for array space allocation
Replace calls of devm_kzalloc() with devm_kcalloc() in led_bl_get_leds() and led_bl_parse_levels() for safer memory allocation with built-in overflow protection. Signed-off-by: Qianfeng Rong <rongqianfeng@vivo.com> Reviewed-by: "Daniel Thompson (RISCstar)" <danielt@kernel.org> Link: https://lore.kernel.org/r/20250819035804.433615-1-rongqianfeng@vivo.com Signed-off-by: Lee Jones <lee@kernel.org>
This commit is contained in:
@@ -89,7 +89,7 @@ static int led_bl_get_leds(struct device *dev,
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
leds = devm_kzalloc(dev, sizeof(struct led_classdev *) * nb_leds,
|
||||
leds = devm_kcalloc(dev, nb_leds, sizeof(struct led_classdev *),
|
||||
GFP_KERNEL);
|
||||
if (!leds)
|
||||
return -ENOMEM;
|
||||
@@ -137,7 +137,7 @@ static int led_bl_parse_levels(struct device *dev,
|
||||
unsigned int db;
|
||||
u32 *levels = NULL;
|
||||
|
||||
levels = devm_kzalloc(dev, sizeof(u32) * num_levels,
|
||||
levels = devm_kcalloc(dev, num_levels, sizeof(u32),
|
||||
GFP_KERNEL);
|
||||
if (!levels)
|
||||
return -ENOMEM;
|
||||
|
||||
Reference in New Issue
Block a user