linux-fbdev.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

* Re: [PATCH] backlight: led_bl: Use devm_kcalloc() for array space allocation
  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
  1 sibling, 1 reply; 4+ messages in thread
From: Daniel Thompson @ 2025-08-19 13:20 UTC (permalink / raw)
  To: Qianfeng Rong
  Cc: Lee Jones, Daniel Thompson, Jingoo Han, Helge Deller, dri-devel,
	linux-fbdev, linux-kernel

On Tue, Aug 19, 2025 at 11:58:03AM +0800, Qianfeng Rong wrote:
> 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>
> ---

I assume you scanned drivers/video/backlight to look for similar code
patterns in other backlight drivers? If you did it would have been
really helpful to say so in this part of the patch (because in it's
absence I had to do that myself).

However, the code changes are fine:
Reviewed-by: Daniel Thompson (RISCstar) <danielt@kernel.org>


Daniel.

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

* Re: [PATCH] backlight: led_bl: Use devm_kcalloc() for array space allocation
  2025-08-19 13:20 ` Daniel Thompson
@ 2025-08-19 13:29   ` Qianfeng Rong
  0 siblings, 0 replies; 4+ messages in thread
From: Qianfeng Rong @ 2025-08-19 13:29 UTC (permalink / raw)
  To: Daniel Thompson
  Cc: Lee Jones, Daniel Thompson, Jingoo Han, Helge Deller, dri-devel,
	linux-fbdev, linux-kernel


在 2025/8/19 21:20, Daniel Thompson 写道:
> [You don't often get email from daniel@riscstar.com. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
>
> On Tue, Aug 19, 2025 at 11:58:03AM +0800, Qianfeng Rong wrote:
>> 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>
>> ---
> I assume you scanned drivers/video/backlight to look for similar code
> patterns in other backlight drivers? If you did it would have been
> really helpful to say so in this part of the patch (because in it's
> absence I had to do that myself).
Yes, I scanned the entire system and there was only this one in 
drivers/video/backlight.
>
> However, the code changes are fine:
> Reviewed-by: Daniel Thompson (RISCstar) <danielt@kernel.org>
>
Best regards,
Qianfeng

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

* Re: (subset) [PATCH] backlight: led_bl: Use devm_kcalloc() for array space allocation
  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-09-02 10:40 ` Lee Jones
  1 sibling, 0 replies; 4+ messages in thread
From: Lee Jones @ 2025-09-02 10:40 UTC (permalink / raw)
  To: Lee Jones, Daniel Thompson, Jingoo Han, Helge Deller, dri-devel,
	linux-fbdev, linux-kernel, Qianfeng Rong

On Tue, 19 Aug 2025 11:58:03 +0800, Qianfeng Rong wrote:
> 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.
> 
> 

Applied, thanks!

[1/1] backlight: led_bl: Use devm_kcalloc() for array space allocation
      commit: 7a5e9040f418c2dd5d30fbdc2cad4446a004c6c5

--
Lee Jones [李琼斯]


^ permalink raw reply	[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).