[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20210713063053.qqttzxlopvpnadj3@pengutronix.de>
Date: Tue, 13 Jul 2021 08:30:53 +0200
From: Uwe Kleine-König <u.kleine-koenig@...gutronix.de>
To: Salah Triki <salah.triki@...il.com>
Cc: fabrice.gasnier@...s.st.com, thierry.reding@...il.com,
lee.jones@...aro.org, mcoquelin.stm32@...il.com,
alexandre.torgue@...s.st.com, linux-pwm@...r.kernel.org,
linux-stm32@...md-mailman.stormreply.com,
linux-arm-kernel@...ts.infradead.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] divide by 3*sizeof(u32) when computing array_size
Hello Salah,
On Tue, Jul 13, 2021 at 12:19:10AM +0100, Salah Triki wrote:
> Divide by 3*sizeof(u32) when computing array_size, since stm32_breakinput
> has 3 fields of type u32.
>
> Signed-off-by: Salah Triki <salah.triki@...il.com>
> ---
> drivers/pwm/pwm-stm32.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/pwm/pwm-stm32.c b/drivers/pwm/pwm-stm32.c
> index 794ca5b02968..fb21bc2b2dd6 100644
> --- a/drivers/pwm/pwm-stm32.c
> +++ b/drivers/pwm/pwm-stm32.c
> @@ -544,7 +544,7 @@ static int stm32_pwm_probe_breakinputs(struct stm32_pwm *priv,
> return -EINVAL;
>
> priv->num_breakinputs = nb;
> - array_size = nb * sizeof(struct stm32_breakinput) / sizeof(u32);
> + array_size = nb * sizeof(struct stm32_breakinput) / (3 * sizeof(u32));
> ret = of_property_read_u32_array(np, "st,breakinput",
> (u32 *)priv->breakinputs, array_size);
> if (ret)
I agree with Philipp here; this looks strange and needs a better
description.
Looking a bit more in details:
- priv->breakinputs has type struct stm32_breakinput[MAX_BREAKINPUT]
- nb is in [0 .. MAX_BREAKINPUT]
- sizeof(struct stm32_breakinput) == 3 * sizeof(u32)
- of_property_read_u32_array reads $array_size u32 quantities
so to read $nb members of type stm32_breakinput array_size must be a
multiple of 3 which isn't given any more after your patch. This makes me
believe your suggested change to be wrong.
Best regards
Uwe
--
Pengutronix e.K. | Uwe Kleine-König |
Industrial Linux Solutions | https://www.pengutronix.de/ |
Download attachment "signature.asc" of type "application/pgp-signature" (489 bytes)
Powered by blists - more mailing lists