drivers/video/backlight/led_bl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
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
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 [李琼斯]
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.
在 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
© 2016 - 2025 Red Hat, Inc.