[PATCH 09/19] video: backlight-pwm: allocate brightness levels with devm_kcalloc

Ahmad Fatoum a.fatoum at pengutronix.de
Wed Oct 28 02:14:43 PDT 2026


From: Ahmad Fatoum <a.fatoum at barebox.org>

The levels table is allocated with xzalloc(), but freed with
devm_kfree() when it's replaced by the interpolated table. That only
works as long as devm_kfree() is a plain free(), so allocate it with
devm_kcalloc() like Linux does.

Assisted-by: Claude:fable-5.1
Signed-off-by: Ahmad Fatoum <a.fatoum at barebox.org>
---
 drivers/video/backlight-pwm.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/video/backlight-pwm.c b/drivers/video/backlight-pwm.c
index 581fa0237c0f..4ec0f6fe5b23 100644
--- a/drivers/video/backlight-pwm.c
+++ b/drivers/video/backlight-pwm.c
@@ -127,9 +127,9 @@ static int pwm_backlight_parse_dt(struct device *dev,
 
 	/* read brightness levels from DT property */
 	if (length > 0) {
-		size_t size = sizeof(*pwm_backlight->levels) * length;
-
-		pwm_backlight->levels = xzalloc(size);
+		pwm_backlight->levels = devm_kcalloc(dev, length,
+						     sizeof(*pwm_backlight->levels),
+						     GFP_KERNEL);
 
 		ret = of_property_read_u32_array(node, "brightness-levels",
 						 pwm_backlight->levels,
-- 
2.47.3




More information about the barebox mailing list