Linux Hardware Monitor development
 help / color / mirror / Atom feed
* [PATCH 5.10, 5.15, 6.1] hwmon: (drivetemp) Fix driver producing garbage data when SCSI errors occur
@ 2026-10-23  4:38 Nobuhiro Iwamatsu
  2026-10-23  4:43 ` sashiko-bot
  2026-10-23 20:02 ` Sasha Levin
  0 siblings, 2 replies; 3+ messages in thread
From: Nobuhiro Iwamatsu @ 2026-10-23  4:38 UTC (permalink / raw)
  To: stable
  Cc: gregkh, sashal, Daniil Stas, Guenter Roeck, Chris Healy,
	Linus Walleij, Martin K . Petersen, Bart Van Assche, linux-kernel,
	linux-scsi, linux-ide, linux-hwmon, Nobuhiro Iwamatsu

From: Daniil Stas <daniil.stas@posteo.net>

commit 82163d63ae7a4c36142cd252388737205bb7e4b9 upstream.

scsi_execute_cmd() function can return both negative (linux codes) and
positive (scsi_cmnd result field) error codes.

Currently the driver just passes error codes of scsi_execute_cmd() to
hwmon core, which is incorrect because hwmon only checks for negative
error codes. This leads to hwmon reporting uninitialized data to
userspace in case of SCSI errors (for example if the disk drive was
disconnected).

This patch checks scsi_execute_cmd() output and returns -EIO if it's
error code is positive.

Fixes: 5b46903d8bf37 ("hwmon: Driver for disk and solid state drives with temperature sensors")
Signed-off-by: Daniil Stas <daniil.stas@posteo.net>
Cc: Guenter Roeck <linux@roeck-us.net>
Cc: Chris Healy <cphealy@gmail.com>
Cc: Linus Walleij <linus.walleij@linaro.org>
Cc: Martin K. Petersen <martin.petersen@oracle.com>
Cc: Bart Van Assche <bvanassche@acm.org>
Cc: linux-kernel@vger.kernel.org
Cc: linux-scsi@vger.kernel.org
Cc: linux-ide@vger.kernel.org
Cc: linux-hwmon@vger.kernel.org
Link: https://lore.kernel.org/r/20250105213618.531691-1-daniil.stas@posteo.net
[groeck: Avoid inline variable declaration for portability]
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Nobuhiro Iwamatsu (CIP) <nobuhiro.iwamatsu.x90@mail.toshiba>
---
 drivers/hwmon/drivetemp.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/hwmon/drivetemp.c b/drivers/hwmon/drivetemp.c
index 5bac2b0fc7bb6a..b3de637a3a1f29 100644
--- a/drivers/hwmon/drivetemp.c
+++ b/drivers/hwmon/drivetemp.c
@@ -165,6 +165,7 @@ static int drivetemp_scsi_command(struct drivetemp_data *st,
 {
 	u8 scsi_cmd[MAX_COMMAND_SIZE];
 	int data_dir;
+	int err;
 
 	memset(scsi_cmd, 0, sizeof(scsi_cmd));
 	scsi_cmd[0] = ATA_16;
@@ -192,9 +193,12 @@ static int drivetemp_scsi_command(struct drivetemp_data *st,
 	scsi_cmd[12] = lba_high;
 	scsi_cmd[14] = ata_command;
 
-	return scsi_execute_req(st->sdev, scsi_cmd, data_dir,
-				st->smartdata, ATA_SECT_SIZE, NULL, HZ, 5,
-				NULL);
+	err = scsi_execute_req(st->sdev, scsi_cmd, data_dir,
+			       st->smartdata, ATA_SECT_SIZE, NULL, HZ, 5,
+			       NULL);
+	if (err > 0)
+		err = -EIO;
+	return err;
 }
 
 static int drivetemp_ata_command(struct drivetemp_data *st, u8 feature,
-- 
2.55.0



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 5.10, 5.15, 6.1] hwmon: (drivetemp) Fix driver producing garbage data when SCSI errors occur
  2026-10-23  4:38 [PATCH 5.10, 5.15, 6.1] hwmon: (drivetemp) Fix driver producing garbage data when SCSI errors occur Nobuhiro Iwamatsu
@ 2026-10-23  4:43 ` sashiko-bot
  2026-10-23 20:02 ` Sasha Levin
  1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-10-23  4:43 UTC (permalink / raw)
  To: Nobuhiro Iwamatsu; +Cc: linux-hwmon

> From: Daniil Stas <daniil.stas@posteo.net>
> 
> commit 82163d63ae7a4c36142cd252388737205bb7e4b9 upstream.
> 
> scsi_execute_cmd() function can return both negative (linux codes) and
> positive (scsi_cmnd result field) error codes.
> 
> Currently the driver just passes error codes of scsi_execute_cmd() to
> hwmon core, which is incorrect because hwmon only checks for negative
> error codes. This leads to hwmon reporting uninitialized data to
> userspace in case of SCSI errors (for example if the disk drive was
> disconnected).
> 
> This patch checks scsi_execute_cmd() output and returns -EIO if it's
> error code is positive.
> [ ... ]
> Cc: linux-hwmon@vger.kernel.org
> Link: https://lore.kernel.org/r/20250105213618.531691-1-daniil.stas@posteo.net
> [groeck: Avoid inline variable declaration for portability]
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
> Signed-off-by: Nobuhiro Iwamatsu (CIP) <nobuhiro.iwamatsu.x90@mail.toshiba>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/1792730299-21490-1-git-send-email-nobuhiro.iwamatsu.x90@mail.toshiba?part=1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 5.10, 5.15, 6.1] hwmon: (drivetemp) Fix driver producing garbage data when SCSI errors occur
  2026-10-23  4:38 [PATCH 5.10, 5.15, 6.1] hwmon: (drivetemp) Fix driver producing garbage data when SCSI errors occur Nobuhiro Iwamatsu
  2026-10-23  4:43 ` sashiko-bot
@ 2026-10-23 20:02 ` Sasha Levin
  1 sibling, 0 replies; 3+ messages in thread
From: Sasha Levin @ 2026-10-23 20:02 UTC (permalink / raw)
  To: stable
  Cc: Sasha Levin, gregkh, Daniil Stas, Guenter Roeck, Chris Healy,
	Linus Walleij, Martin K . Petersen, Bart Van Assche, linux-kernel,
	linux-scsi, linux-ide, linux-hwmon, Nobuhiro Iwamatsu

> Currently the driver just passes error codes of scsi_execute_cmd() to
> hwmon core, which is incorrect because hwmon only checks for negative
> error codes.

Queued for 6.1, 5.15 and 5.10, thanks.

-- 
Thanks,
Sasha

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-10-23 20:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-23  4:38 [PATCH 5.10, 5.15, 6.1] hwmon: (drivetemp) Fix driver producing garbage data when SCSI errors occur Nobuhiro Iwamatsu
2026-10-23  4:43 ` sashiko-bot
2026-10-23 20:02 ` Sasha Levin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox