Skip to content

Commit a738859

Browse files
himadricsjhovold
authored andcommitted
USB: serial: ftdi_sio: use usb_control_msg_recv()
usb_control_msg_recv() nicely wraps usb_control_msg() and removes the compulsion of using DMA buffers for USB messages. It also includes proper error check for possible short read. So use the wrapper where appropriate and remove DMA buffers from the callers. Signed-off-by: Himadri Pandya <[email protected]> Link: https://lore.kernel.org/r/[email protected] [ johan: amend commit message ] Signed-off-by: Johan Hovold <[email protected]>
1 parent 0d027ee commit a738859

File tree

1 file changed

+15
-38
lines changed

1 file changed

+15
-38
lines changed

drivers/usb/serial/ftdi_sio.c

Lines changed: 15 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,27 +1437,15 @@ static int _read_latency_timer(struct usb_serial_port *port)
14371437
{
14381438
struct ftdi_private *priv = usb_get_serial_port_data(port);
14391439
struct usb_device *udev = port->serial->dev;
1440-
unsigned char *buf;
1440+
u8 buf;
14411441
int rv;
14421442

1443-
buf = kmalloc(1, GFP_KERNEL);
1444-
if (!buf)
1445-
return -ENOMEM;
1446-
1447-
rv = usb_control_msg(udev,
1448-
usb_rcvctrlpipe(udev, 0),
1449-
FTDI_SIO_GET_LATENCY_TIMER_REQUEST,
1450-
FTDI_SIO_GET_LATENCY_TIMER_REQUEST_TYPE,
1451-
0, priv->interface,
1452-
buf, 1, WDR_TIMEOUT);
1453-
if (rv < 1) {
1454-
if (rv >= 0)
1455-
rv = -EIO;
1456-
} else {
1457-
rv = buf[0];
1458-
}
1459-
1460-
kfree(buf);
1443+
rv = usb_control_msg_recv(udev, 0, FTDI_SIO_GET_LATENCY_TIMER_REQUEST,
1444+
FTDI_SIO_GET_LATENCY_TIMER_REQUEST_TYPE, 0,
1445+
priv->interface, &buf, 1, WDR_TIMEOUT,
1446+
GFP_KERNEL);
1447+
if (rv == 0)
1448+
rv = buf;
14611449

14621450
return rv;
14631451
}
@@ -1852,32 +1840,21 @@ static int ftdi_read_cbus_pins(struct usb_serial_port *port)
18521840
{
18531841
struct ftdi_private *priv = usb_get_serial_port_data(port);
18541842
struct usb_serial *serial = port->serial;
1855-
unsigned char *buf;
1843+
u8 buf;
18561844
int result;
18571845

18581846
result = usb_autopm_get_interface(serial->interface);
18591847
if (result)
18601848
return result;
18611849

1862-
buf = kmalloc(1, GFP_KERNEL);
1863-
if (!buf) {
1864-
usb_autopm_put_interface(serial->interface);
1865-
return -ENOMEM;
1866-
}
1867-
1868-
result = usb_control_msg(serial->dev,
1869-
usb_rcvctrlpipe(serial->dev, 0),
1870-
FTDI_SIO_READ_PINS_REQUEST,
1871-
FTDI_SIO_READ_PINS_REQUEST_TYPE, 0,
1872-
priv->interface, buf, 1, WDR_TIMEOUT);
1873-
if (result < 1) {
1874-
if (result >= 0)
1875-
result = -EIO;
1876-
} else {
1877-
result = buf[0];
1878-
}
1850+
result = usb_control_msg_recv(serial->dev, 0,
1851+
FTDI_SIO_READ_PINS_REQUEST,
1852+
FTDI_SIO_READ_PINS_REQUEST_TYPE, 0,
1853+
priv->interface, &buf, 1, WDR_TIMEOUT,
1854+
GFP_KERNEL);
1855+
if (result == 0)
1856+
result = buf;
18791857

1880-
kfree(buf);
18811858
usb_autopm_put_interface(serial->interface);
18821859

18831860
return result;

0 commit comments

Comments
 (0)