Commit d0fa8751 authored by Qianfeng Rong's avatar Qianfeng Rong Committed by Lee Jones
Browse files

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: default avatarQianfeng Rong <rongqianfeng@vivo.com>
Reviewed-by: default avatar"Daniel Thompson (RISCstar)" <danielt@kernel.org>
Link: https://lore.kernel.org/r/20250819035804.433615-1-rongqianfeng@vivo.com


Signed-off-by: default avatarLee Jones <lee@kernel.org>
parent fe85a39d
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -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;