linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] backlight: led_bl: Use devm_kcalloc() for array space allocation
@ 2025-08-19  3:58 Qianfeng Rong
  2025-08-19 13:20 ` Daniel Thompson
  2025-09-02 10:40 ` (subset) " Lee Jones
  0 siblings, 2 replies; 4+ messages in thread
From: Qianfeng Rong @ 2025-08-19  3:58 UTC (permalink / raw)
  To: Lee Jones, Daniel Thompson, Jingoo Han, Helge Deller, dri-devel,
	linux-fbdev, linux-kernel
  Cc: Qianfeng Rong

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>
---
 drivers/video/backlight/led_bl.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/video/backlight/led_bl.c b/drivers/video/backlight/led_bl.c
index d2db157b2c29..dd03d91a6e50 100644
--- a/drivers/video/backlight/led_bl.c
+++ b/drivers/video/backlight/led_bl.c
@@ -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;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-09-02 10:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-19  3:58 [PATCH] backlight: led_bl: Use devm_kcalloc() for array space allocation Qianfeng Rong
2025-08-19 13:20 ` Daniel Thompson
2025-08-19 13:29   ` Qianfeng Rong
2025-09-02 10:40 ` (subset) " Lee Jones

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).