Skip to content

Commit 53e25b1

Browse files
Daniil Stasgregkh
authored andcommitted
hwmon: (drivetemp) Fix driver producing garbage data when SCSI errors occur
[ Upstream commit 82163d6 ] 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: 5b46903 ("hwmon: Driver for disk and solid state drives with temperature sensors") Signed-off-by: Daniil Stas <[email protected]> Cc: Guenter Roeck <[email protected]> Cc: Chris Healy <[email protected]> Cc: Linus Walleij <[email protected]> Cc: Martin K. Petersen <[email protected]> Cc: Bart Van Assche <[email protected]> Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Link: https://lore.kernel.org/r/[email protected] [groeck: Avoid inline variable declaration for portability] Signed-off-by: Guenter Roeck <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent a4b0137 commit 53e25b1

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

drivers/hwmon/drivetemp.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ static int drivetemp_scsi_command(struct drivetemp_data *st,
165165
{
166166
u8 scsi_cmd[MAX_COMMAND_SIZE];
167167
enum req_op op;
168+
int err;
168169

169170
memset(scsi_cmd, 0, sizeof(scsi_cmd));
170171
scsi_cmd[0] = ATA_16;
@@ -192,8 +193,11 @@ static int drivetemp_scsi_command(struct drivetemp_data *st,
192193
scsi_cmd[12] = lba_high;
193194
scsi_cmd[14] = ata_command;
194195

195-
return scsi_execute_cmd(st->sdev, scsi_cmd, op, st->smartdata,
196-
ATA_SECT_SIZE, HZ, 5, NULL);
196+
err = scsi_execute_cmd(st->sdev, scsi_cmd, op, st->smartdata,
197+
ATA_SECT_SIZE, HZ, 5, NULL);
198+
if (err > 0)
199+
err = -EIO;
200+
return err;
197201
}
198202

199203
static int drivetemp_ata_command(struct drivetemp_data *st, u8 feature,

0 commit comments

Comments
 (0)