The "event_char" device attribute value, when written, is interpreted as
an enable bit in bit 8, and an "event character" in bits 7 to 0.

Return an error -EINVAL for out-of-range values.  Use kstrtouint() to
parse the integer instead of the obsolete simple_strtoul().

Signed-off-by: Ian Abbott <abbo...@mev.co.uk>
---
v2:
- As suggested by Johan Hovold, combine with the use of kstrtouint()
from v1 patch 5.
---
 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 da396122ec83..0f3f7bfe9294 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -1737,9 +1737,12 @@ static ssize_t store_event_char(struct device *dev,
        struct usb_serial_port *port = to_usb_serial_port(dev);
        struct ftdi_private *priv = usb_get_serial_port_data(port);
        struct usb_device *udev = port->serial->dev;
-       int v = simple_strtoul(valbuf, NULL, 10);
+       unsigned int v;
        int rv;
 
+       if (kstrtouint(valbuf, 10, &v) || v >= 0x200)
+               return -EINVAL;
+
        dev_dbg(&port->dev, "%s: setting event char = %i\n", __func__, v);
 
        rv = usb_control_msg(udev,
-- 
2.11.0

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

Reply via email to