* [PATCH] hwmon: (ltc2991) re-order conditions to fix off by one bug
@ 2024-07-04 15:18 Dan Carpenter
2024-07-05 1:15 ` Guenter Roeck
0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2024-07-04 15:18 UTC (permalink / raw)
To: Antoniu Miclaus
Cc: Jean Delvare, Guenter Roeck, linux-hwmon, linux-kernel, kernel-janitors
LTC2991_T_INT_CH_NR is 4. The st->temp_en[] array has LTC2991_MAX_CHANNEL
(4) elements. Thus if "channel" is equal to LTC2991_T_INT_CH_NR then we
have read one element beyond the end of the array. Flip the conditions
around so that we check if "channel" is valid before using it as an array
index.
Fixes: 2b9ea4262ae9 ("hwmon: Add driver for ltc2991")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
drivers/hwmon/ltc2991.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/hwmon/ltc2991.c b/drivers/hwmon/ltc2991.c
index a01f887392f9..573cd8f5721b 100644
--- a/drivers/hwmon/ltc2991.c
+++ b/drivers/hwmon/ltc2991.c
@@ -225,8 +225,8 @@ static umode_t ltc2991_is_visible(const void *data,
case hwmon_temp:
switch (attr) {
case hwmon_temp_input:
- if (st->temp_en[channel] ||
- channel == LTC2991_T_INT_CH_NR)
+ if (channel == LTC2991_T_INT_CH_NR ||
+ st->temp_en[channel])
return 0444;
break;
}
--
2.43.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] hwmon: (ltc2991) re-order conditions to fix off by one bug
2024-07-04 15:18 [PATCH] hwmon: (ltc2991) re-order conditions to fix off by one bug Dan Carpenter
@ 2024-07-05 1:15 ` Guenter Roeck
0 siblings, 0 replies; 2+ messages in thread
From: Guenter Roeck @ 2024-07-05 1:15 UTC (permalink / raw)
To: Dan Carpenter
Cc: Antoniu Miclaus, Jean Delvare, linux-hwmon, linux-kernel,
kernel-janitors
On Thu, Jul 04, 2024 at 10:18:59AM -0500, Dan Carpenter wrote:
> LTC2991_T_INT_CH_NR is 4. The st->temp_en[] array has LTC2991_MAX_CHANNEL
> (4) elements. Thus if "channel" is equal to LTC2991_T_INT_CH_NR then we
> have read one element beyond the end of the array. Flip the conditions
> around so that we check if "channel" is valid before using it as an array
> index.
>
> Fixes: 2b9ea4262ae9 ("hwmon: Add driver for ltc2991")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Applied.
Thanks,
Guenter
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-07-05 1:15 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-04 15:18 [PATCH] hwmon: (ltc2991) re-order conditions to fix off by one bug Dan Carpenter
2024-07-05 1:15 ` Guenter Roeck
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®