Skip to content

Commit ba9897a

Browse files
tititiou36Lee Jones
authored andcommitted
backlight: pwm_bl: Avoid open coded arithmetic in memory allocation
kmalloc_array()/kcalloc() should be used to avoid potential overflow when a multiplication is needed to compute the size of the requested memory. So turn a kzalloc()+explicit size computation into an equivalent kcalloc(). Signed-off-by: Christophe JAILLET <[email protected]> Acked-by: Uwe Kleine-König <[email protected]> Reviewed-by: Daniel Thompson <[email protected]> Signed-off-by: Lee Jones <[email protected]> Link: https://lore.kernel.org/r/bd3d74acfa58d59f6f5f81fc5a9fb409edb8d747.1644046817.git.christophe.jaillet@wanadoo.fr
1 parent e783362 commit ba9897a

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

drivers/video/backlight/pwm_bl.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,8 @@ static int pwm_backlight_parse_dt(struct device *dev,
263263

264264
/* read brightness levels from DT property */
265265
if (num_levels > 0) {
266-
size_t size = sizeof(*data->levels) * num_levels;
267-
268-
data->levels = devm_kzalloc(dev, size, GFP_KERNEL);
266+
data->levels = devm_kcalloc(dev, num_levels,
267+
sizeof(*data->levels), GFP_KERNEL);
269268
if (!data->levels)
270269
return -ENOMEM;
271270

@@ -320,8 +319,8 @@ static int pwm_backlight_parse_dt(struct device *dev,
320319
* Create a new table of brightness levels with all the
321320
* interpolated steps.
322321
*/
323-
size = sizeof(*table) * num_levels;
324-
table = devm_kzalloc(dev, size, GFP_KERNEL);
322+
table = devm_kcalloc(dev, num_levels, sizeof(*table),
323+
GFP_KERNEL);
325324
if (!table)
326325
return -ENOMEM;
327326
/*

0 commit comments

Comments
 (0)