mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Luiz Angelo Daros de Luca <luizluca@gmail.com>
To: Guenter Roeck <linux@roeck-us.net>,
	 Chris Packham <chris.packham@alliedtelesis.co.nz>,
	 Andrew Morton <akpm@linux-foundation.org>,
	 "Darrick J. Wong" <djwong@us.ibm.com>,
	 "Mark M. Hoffman" <mhoffman@lightlink.com>
Cc: linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org,
	 Luiz Angelo Daros de Luca <luizluca@gmail.com>,
	sashiko-bot@kernel.org
Subject: [hwmon PATCH v2 5/8] hwmon: (adt7470) Fix temperature alarm logic in hwmon_temp_read()
Date: Mon, 27 Jul 2026 21:22:21 -0300	[thread overview]
Message-ID: <20260727-adt7470_fixes-v2-5-598e38a46ba6@gmail.com> (raw)
In-Reply-To: <20260727-adt7470_fixes-v2-0-598e38a46ba6@gmail.com>

During the conversion the alarm callback started interpreting the
channel index as an alarm bitmask, resulting in incorrect alarm
reporting. Compute the proper alarm bit instead.

Reported-by: sashiko-bot@kernel.org
Closes: https://lore.kernel.org/r/20260717211224.B9E291F000E9@smtp.kernel.org
Fixes: fc958a61ff6d ("hwmon: (adt7470) Convert to devm_hwmon_device_register_with_info API")
Signed-off-by: Luiz Angelo Daros de Luca <luizluca@gmail.com>
---
 drivers/hwmon/adt7470.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/drivers/hwmon/adt7470.c b/drivers/hwmon/adt7470.c
index a34635526aaa..c6fc7d38d698 100644
--- a/drivers/hwmon/adt7470.c
+++ b/drivers/hwmon/adt7470.c
@@ -110,6 +110,21 @@ static const unsigned short normal_i2c[] = { 0x2C, 0x2E, 0x2F, I2C_CLIENT_END };
 
 #define ALARM2(x)		((x) << 8)
 
+/* TEMP1..TEMP7 (ch 0..6) are, respectively BIT(0)..BIT(6) of reg 0x41 and
+ * 0x72, or BIT(0)..BIT(6) of data->alarm.
+ * TEMP8..TEMP9 (ch 7..9) are, respectively BIT(0)..BIT(2) of reg 0x42 and
+ * 0x73, or BIT(8)..BIT(10) of data->alarm.
+ */
+#define TEMP_ALARM_BIT(ch)	({		\
+	typeof(ch) _ch = (ch);			\
+	(1 << (_ch < 7 ? _ch : _ch + 1));	\
+})
+
+/* FAN1..FAN4 (ch 0..3) are respectively BIT(4)..BIT(7) in
+ * reg 0x42 and 0x73 or BIT(12)..BIT(15) in data->alarm.
+ */
+#define FAN_ALARM_BIT(ch)	(1 << (12 + (ch)))
+
 #define ADT7470_VENDOR		0x41
 #define ADT7470_DEVICE		0x70
 /* datasheet only mentions a revision 2 */
@@ -569,7 +584,7 @@ static int adt7470_temp_read(struct device *dev, u32 attr, int channel, long *va
 		*val = 1000 * data->temp_max[channel];
 		break;
 	case hwmon_temp_alarm:
-		*val = !!(data->alarm & channel);
+		*val = !!(data->alarm & TEMP_ALARM_BIT(channel));
 		break;
 	default:
 		return -EOPNOTSUPP;
@@ -668,7 +683,7 @@ static int adt7470_fan_read(struct device *dev, u32 attr, int channel, long *val
 			*val = 0;
 		break;
 	case hwmon_fan_alarm:
-		*val = !!(data->alarm & (1 << (12 + channel)));
+		*val = !!(data->alarm & FAN_ALARM_BIT(channel));
 		break;
 	default:
 		return -EOPNOTSUPP;

-- 
2.55.0


  parent reply	other threads:[~2026-07-28  0:23 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-28  0:22 [hwmon PATCH v2 0/8] hwmon: (adt7470): Multiple fixes Luiz Angelo Daros de Luca
2026-07-28  0:22 ` [hwmon PATCH v2 1/8] hwmon: (adt7470) Fix fans stuck in manual mode on I2C errors Luiz Angelo Daros de Luca
2026-07-28  0:53   ` Guenter Roeck
2026-07-28  0:22 ` [hwmon PATCH v2 2/8] hwmon: (adt7470) Fix cache updated before hardware write on I2C error Luiz Angelo Daros de Luca
2026-07-28  0:54   ` Guenter Roeck
2026-07-28  0:22 ` [hwmon PATCH v2 3/8] hwmon: (adt7470) Fix busy-loop and I2C flooding in update thread Luiz Angelo Daros de Luca
2026-07-28  0:55   ` Guenter Roeck
2026-07-28  0:22 ` [hwmon PATCH v2 4/8] hwmon: (adt7470) Fix swapped PWM3 and PWM4 auto mode masks Luiz Angelo Daros de Luca
2026-07-28  0:57   ` Guenter Roeck
2026-07-28  0:22 ` Luiz Angelo Daros de Luca [this message]
2026-07-28  0:55   ` [hwmon PATCH v2 5/8] hwmon: (adt7470) Fix temperature alarm logic in hwmon_temp_read() Guenter Roeck
2026-07-28  0:22 ` [hwmon PATCH v2 6/8] hwmon: (adt7470) Use cached PWM frequency value Luiz Angelo Daros de Luca
2026-07-28  0:57   ` Guenter Roeck
2026-07-28  0:22 ` [hwmon PATCH v2 7/8] hwmon: (adt7470) Fix divide-by-zero TOCTOU crash in fan speed read Luiz Angelo Daros de Luca
2026-07-28  0:58   ` Guenter Roeck
2026-07-28  0:22 ` [hwmon PATCH v2 8/8] hwmon: (adt7470) Fix PWM auto temp state array and bounds check Luiz Angelo Daros de Luca
2026-07-28  0:58   ` Guenter Roeck
2026-07-28  1:04 ` [hwmon PATCH v2 0/8] hwmon: (adt7470): Multiple fixes Guenter Roeck
2026-07-28  1:08   ` Luiz Angelo Daros de Luca
2026-07-28  3:35     ` Guenter Roeck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260727-adt7470_fixes-v2-5-598e38a46ba6@gmail.com \
    --to=luizluca@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=chris.packham@alliedtelesis.co.nz \
    --cc=djwong@us.ibm.com \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=mhoffman@lightlink.com \
    --cc=sashiko-bot@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®