Commit ba9897a0 authored by Christophe JAILLET's avatar Christophe JAILLET Committed by Lee Jones
Browse files

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: default avatarChristophe JAILLET <christophe.jaillet@wanadoo.fr>
Acked-by: default avatarUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Reviewed-by: default avatarDaniel Thompson <daniel.thompson@linaro.org>
Signed-off-by: default avatarLee Jones <lee.jones@linaro.org>
Link: https://lore.kernel.org/r/bd3d74acfa58d59f6f5f81fc5a9fb409edb8d747.1644046817.git.christophe.jaillet@wanadoo.fr
parent e783362e
Loading
Loading
Loading
Loading
+4 −5
Original line number Original line Diff line number Diff line
@@ -263,9 +263,8 @@ static int pwm_backlight_parse_dt(struct device *dev,


	/* read brightness levels from DT property */
	/* read brightness levels from DT property */
	if (num_levels > 0) {
	if (num_levels > 0) {
		size_t size = sizeof(*data->levels) * num_levels;
		data->levels = devm_kcalloc(dev, num_levels,

					    sizeof(*data->levels), GFP_KERNEL);
		data->levels = devm_kzalloc(dev, size, GFP_KERNEL);
		if (!data->levels)
		if (!data->levels)
			return -ENOMEM;
			return -ENOMEM;


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