Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <christophe.jaillet@wanadoo.fr>
Acked-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Reviewed-by: Daniel Thompson <daniel.thompson@linaro.org>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
Link: https://lore.kernel.org/r/bd3d74acfa58d59f6f5f81fc5a9fb409edb8d747.1644046817.git.christophe.jaillet@wanadoo.fr

authored by

Christophe JAILLET and committed by
Lee Jones
ba9897a0 e783362e

+4 -5
+4 -5
drivers/video/backlight/pwm_bl.c
··· 263 263 264 264 /* read brightness levels from DT property */ 265 265 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); 269 268 if (!data->levels) 270 269 return -ENOMEM; 271 270 ··· 319 320 * Create a new table of brightness levels with all the 320 321 * interpolated steps. 321 322 */ 322 - size = sizeof(*table) * num_levels; 323 - table = devm_kzalloc(dev, size, GFP_KERNEL); 323 + table = devm_kcalloc(dev, num_levels, sizeof(*table), 324 + GFP_KERNEL); 324 325 if (!table) 325 326 return -ENOMEM; 326 327 /*