Re: [PATCH] divide by 3*sizeof(u32) when computing array_size

From: Philipp Hahn
Date: Tue Jul 13 2021 - 02:02:40 EST


Hello,

Disclaimer: I have no idea what 'pwm-stm32' is or does

Am 13.07.21 um 01:19 schrieb Salah Triki:
Divide by 3*sizeof(u32) when computing array_size, since stm32_breakinput
has 3 fields of type u32.
...
--- 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));

Maybe it's too early in the morning for me, but this does not look right:

struct stm32_breakinput {
u32 index;
u32 level;
u32 filter;
};

then "sizeof(struct stm32_breakinput)" == "(3 * sizeof(u32))", which would simply make "arrray_site := nb" ?

Philipp