Commit 867e4b1b authored by Bart Van Assche's avatar Bart Van Assche Committed by Martin K. Petersen
Browse files

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: default avatarBart Van Assche <bvanassche@acm.org>
Link: https://patch.msgid.link/20251031221844.2921694-1-bvanassche@acm.org


Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
parent 61deab8a
Loading
Loading
Loading
Loading
+8 −4
Original line number Diff line number Diff line
@@ -648,10 +648,14 @@ static ssize_t
sdev_store_timeout (struct device *dev, struct device_attribute *attr,
		    const char *buf, size_t count)
{
	struct scsi_device *sdev;
	int timeout;
	sdev = to_scsi_device(dev);
	sscanf (buf, "%d\n", &timeout);
	struct scsi_device *sdev = to_scsi_device(dev);
	int ret, timeout;

	ret = kstrtoint(buf, 0, &timeout);
	if (ret)
		return ret;
	if (timeout <= 0)
		return -EINVAL;
	blk_queue_rq_timeout(sdev->request_queue, timeout * HZ);
	return count;
}