diff mbox series

[v2,4/6] USB: serial: ftdi_sio: use usb_control_msg_recv()

Message ID 20210801203122.3515-5-himadrispandya@gmail.com
State New
Headers show
Series USB: serial: use wrappers for usb_control_msg() | expand

Commit Message

Himadri Pandya Aug. 1, 2021, 8:31 p.m. UTC
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 and remove dma
buffers from the callers.

Signed-off-by: Himadri Pandya <himadrispandya@gmail.com>
---
Changes in v2:
 - Drop unnecessary use of wrappers
---
 drivers/usb/serial/ftdi_sio.c | 53 ++++++++++-------------------------
 1 file changed, 15 insertions(+), 38 deletions(-)

Comments

Johan Hovold Sept. 21, 2021, 12:17 p.m. UTC | #1
On Mon, Aug 02, 2021 at 02:01:20AM +0530, Himadri Pandya wrote:
> 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 and remove dma

> buffers from the callers.

> 

> Signed-off-by: Himadri Pandya <himadrispandya@gmail.com>

> ---

> Changes in v2:

>  - Drop unnecessary use of wrappers


Now applied, with a slightly amended commit message:

    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.

Johan
diff mbox series

Patch

diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index 4a1f3a95d017..d4c61568b549 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -1436,27 +1436,15 @@  static int _read_latency_timer(struct usb_serial_port *port)
 {
 	struct ftdi_private *priv = usb_get_serial_port_data(port);
 	struct usb_device *udev = port->serial->dev;
-	unsigned char *buf;
+	u8 buf;
 	int rv;
 
-	buf = kmalloc(1, GFP_KERNEL);
-	if (!buf)
-		return -ENOMEM;
-
-	rv = usb_control_msg(udev,
-			     usb_rcvctrlpipe(udev, 0),
-			     FTDI_SIO_GET_LATENCY_TIMER_REQUEST,
-			     FTDI_SIO_GET_LATENCY_TIMER_REQUEST_TYPE,
-			     0, priv->interface,
-			     buf, 1, WDR_TIMEOUT);
-	if (rv < 1) {
-		if (rv >= 0)
-			rv = -EIO;
-	} else {
-		rv = buf[0];
-	}
-
-	kfree(buf);
+	rv = usb_control_msg_recv(udev, 0, FTDI_SIO_GET_LATENCY_TIMER_REQUEST,
+				  FTDI_SIO_GET_LATENCY_TIMER_REQUEST_TYPE, 0,
+				  priv->interface, &buf, 1, WDR_TIMEOUT,
+				  GFP_KERNEL);
+	if (rv == 0)
+		rv = buf;
 
 	return rv;
 }
@@ -1851,32 +1839,21 @@  static int ftdi_read_cbus_pins(struct usb_serial_port *port)
 {
 	struct ftdi_private *priv = usb_get_serial_port_data(port);
 	struct usb_serial *serial = port->serial;
-	unsigned char *buf;
+	u8 buf;
 	int result;
 
 	result = usb_autopm_get_interface(serial->interface);
 	if (result)
 		return result;
 
-	buf = kmalloc(1, GFP_KERNEL);
-	if (!buf) {
-		usb_autopm_put_interface(serial->interface);
-		return -ENOMEM;
-	}
-
-	result = usb_control_msg(serial->dev,
-				 usb_rcvctrlpipe(serial->dev, 0),
-				 FTDI_SIO_READ_PINS_REQUEST,
-				 FTDI_SIO_READ_PINS_REQUEST_TYPE, 0,
-				 priv->interface, buf, 1, WDR_TIMEOUT);
-	if (result < 1) {
-		if (result >= 0)
-			result = -EIO;
-	} else {
-		result = buf[0];
-	}
+	result = usb_control_msg_recv(serial->dev, 0,
+				      FTDI_SIO_READ_PINS_REQUEST,
+				      FTDI_SIO_READ_PINS_REQUEST_TYPE, 0,
+				      priv->interface, &buf, 1, WDR_TIMEOUT,
+				      GFP_KERNEL);
+	if (result == 0)
+		result = buf;
 
-	kfree(buf);
 	usb_autopm_put_interface(serial->interface);
 
 	return result;