Skip to content

Commit 867e4b1

Browse files
bvanasschemartinkpetersen
authored andcommitted
scsi: core: Improve sdev_store_timeout()
Check whether or not the conversion of the argument to an integer succeeded. Reject invalid timeout values. Signed-off-by: Bart Van Assche <bvanassche@acm.org> Link: https://patch.msgid.link/20251031221844.2921694-1-bvanassche@acm.org Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent 61deab8 commit 867e4b1

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

drivers/scsi/scsi_sysfs.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -648,10 +648,14 @@ static ssize_t
648648
sdev_store_timeout (struct device *dev, struct device_attribute *attr,
649649
const char *buf, size_t count)
650650
{
651-
struct scsi_device *sdev;
652-
int timeout;
653-
sdev = to_scsi_device(dev);
654-
sscanf (buf, "%d\n", &timeout);
651+
struct scsi_device *sdev = to_scsi_device(dev);
652+
int ret, timeout;
653+
654+
ret = kstrtoint(buf, 0, &timeout);
655+
if (ret)
656+
return ret;
657+
if (timeout <= 0)
658+
return -EINVAL;
655659
blk_queue_rq_timeout(sdev->request_queue, timeout * HZ);
656660
return count;
657661
}

0 commit comments

Comments
 (0)