[PATCH v2 3/5] USB: serial: ftdi_sio: only allow valid latency timer values

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Valid latency timer values are between 1 ms and 255 ms in 1 ms steps.
The store function for the "latency_timer" device attribute currently
allows any value, although only the lower 16 bits will be sent to the
device, and the device only stores the lower 8 bits.  The hardware
appears to accept the (invalid) value 0 and treats it the same as 1
(resulting in a latency of 1 ms).

Change the latency_timer_store() function to accept only the values 0 to
255, returning an error -EINVAL for out-of-range values.  Call
kstrtou8() to parse the integer instead of the obsolete
simple_strtoul().

Signed-off-by: Ian Abbott <abbotti@xxxxxxxxx>
---
v2:
- As suggested by Johan Hovold, accept 0 as valid, and combine with the
use of kstrtouint() from v1 patch 5, except that I replaced it with
kstrtou8() instead to avoid having to do a separate range check.
---
 drivers/usb/serial/ftdi_sio.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index be2c77380320..da396122ec83 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -1715,9 +1715,12 @@ static ssize_t latency_timer_store(struct device *dev,
 {
 	struct usb_serial_port *port = to_usb_serial_port(dev);
 	struct ftdi_private *priv = usb_get_serial_port_data(port);
-	int v = simple_strtoul(valbuf, NULL, 10);
+	u8 v;
 	int rv;
 
+	if (kstrtou8(valbuf, 10, &v))
+		return -EINVAL;
+
 	priv->latency = v;
 	rv = write_latency_timer(port);
 	if (rv < 0)
-- 
2.11.0

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux