Skip to contentSkip to conversation

Smatch report for Cadence PWM

DISCUSSION Andrew Goodbody 2 participants 3 messages Aug 8, 2025 – Sep 1, 2025

lore
Share & tools
lore
#0 lore raw

I have the following Smatch report.

drivers/pwm/pwm-cadence-ttc.c:73 cadence_ttc_pwm_set_invert() error: buffer overflow 'priv->invert' 2 <= 2 drivers/pwm/pwm-cadence-ttc.c:138 cadence_ttc_pwm_set_config() error: buffer overflow 'priv->invert' 2 <= 2

Indeed yes, the code allows a maximum index of 2 into an array with 2 elements, so that is out of bounds. My question is which is wrong? Should the array have 3 elements or should the index be limited to 1, or is the value being checked 1 based?

Thanks,
Andrew

#1 lore raw

Hi Andrew,

Quoted 6 lines · Andrew Goodbody

I have the following Smatch report.

drivers/pwm/pwm-cadence-ttc.c:73 cadence_ttc_pwm_set_invert() error: buffer overflow 'priv->invert' 2 <= 2 drivers/pwm/pwm-cadence-ttc.c:138 cadence_ttc_pwm_set_config() error: buffer overflow 'priv->invert' 2 <= 2

Indeed yes, the code allows a maximum index of 2 into an array with 2 elements, so that is out of bounds. My question is which is wrong? Should the array have 3 elements or should the index be limited to 1, or is the value being checked 1 based?

There are maximum 3 PWMs.

I think the best way to fix would be to create macro with number 3 and use it in array and in boundary check too.

Thanks,
Michal

#2 lore raw
Quoted 8 lines · Michal Simek

Hi Andrew,

Quoted 5 lines · Andrew Goodbody

I have the following Smatch report.

drivers/pwm/pwm-cadence-ttc.c:73 cadence_ttc_pwm_set_invert() error: buffer overflow 'priv->invert' 2 <= 2 drivers/pwm/pwm-cadence-ttc.c:138 cadence_ttc_pwm_set_config() error: buffer overflow 'priv->invert' 2 <= 2

Quoted 9 lines
Quoted 1 line

Indeed yes, the code allows a maximum index of 2 into an array with 2 elements, so that is out of bounds. My question is which is wrong? Should the array have 3 elements or should the index be limited to 1, or is the value being checked 1 based?

There are maximum 3 PWMs.

I think the best way to fix would be to create macro with number 3 and use it in array and in boundary check too.

Thanks,
Michal

Thanks. Patch on its way.

Andrew