diff mbox series

[hwmon-next,1/1] hwmon: (mlxreg-fan) Fix defect reported by Coverity Scan for linux-next

Message ID 20210920174119.1080488-1-vadimp@nvidia.com (mailing list archive)
State Not Applicable
Headers show
Series [hwmon-next,1/1] hwmon: (mlxreg-fan) Fix defect reported by Coverity Scan for linux-next | expand

Commit Message

Vadim Pasternak Sept. 20, 2021, 5:41 p.m. UTC
Fix counter limit in 'for' loop in mlxreg_fan_cooling_config().
The issue found in the report on new defect(s) introduced to linux-next
weekly scan found with Coverity Scan - memory access violation.

** CID 1507571:  Memory - illegal accesses  (OVERRUN)
/drivers/hwmon/mlxreg-fan.c: 560 in mlxreg_fan_cooling_config()

>>> Overrunning array of 160 bytes at byte offset 160 by dereferencing
	pointer "pwm".

Signed-off-by: Vadim Pasternak <vadimp@nvidia.com>
---
 drivers/hwmon/mlxreg-fan.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Guenter Roeck Sept. 24, 2021, 1:09 a.m. UTC | #1
On Mon, Sep 20, 2021 at 08:41:18PM +0300, Vadim Pasternak wrote:
> Fix counter limit in 'for' loop in mlxreg_fan_cooling_config().
> The issue found in the report on new defect(s) introduced to linux-next
> weekly scan found with Coverity Scan - memory access violation.
> 
> ** CID 1507571:  Memory - illegal accesses  (OVERRUN)
> /drivers/hwmon/mlxreg-fan.c: 560 in mlxreg_fan_cooling_config()
> 
> >>> Overrunning array of 160 bytes at byte offset 160 by dereferencing
> 	pointer "pwm".
> 
> Signed-off-by: Vadim Pasternak <vadimp@nvidia.com>

I just applied a similar patch. I added you as Reported-by: to that patch.

Thanks,
Guenter

> ---
>  drivers/hwmon/mlxreg-fan.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/hwmon/mlxreg-fan.c b/drivers/hwmon/mlxreg-fan.c
> index 35228ed112d7..feab9ec6a6ca 100644
> --- a/drivers/hwmon/mlxreg-fan.c
> +++ b/drivers/hwmon/mlxreg-fan.c
> @@ -554,7 +554,7 @@ static int mlxreg_fan_cooling_config(struct device *dev, struct mlxreg_fan *fan)
>  {
>  	int i, j;
>  
> -	for (i = 0; i <= MLXREG_FAN_MAX_PWM; i++) {
> +	for (i = 0; i < MLXREG_FAN_MAX_PWM; i++) {
>  		struct mlxreg_fan_pwm *pwm = &fan->pwm[i];
>  
>  		if (!pwm->connected)
diff mbox series

Patch

diff --git a/drivers/hwmon/mlxreg-fan.c b/drivers/hwmon/mlxreg-fan.c
index 35228ed112d7..feab9ec6a6ca 100644
--- a/drivers/hwmon/mlxreg-fan.c
+++ b/drivers/hwmon/mlxreg-fan.c
@@ -554,7 +554,7 @@  static int mlxreg_fan_cooling_config(struct device *dev, struct mlxreg_fan *fan)
 {
 	int i, j;
 
-	for (i = 0; i <= MLXREG_FAN_MAX_PWM; i++) {
+	for (i = 0; i < MLXREG_FAN_MAX_PWM; i++) {
 		struct mlxreg_fan_pwm *pwm = &fan->pwm[i];
 
 		if (!pwm->connected)