diff mbox series

[v2,6/6] USB: serial: kl5kusb105: use usb_control_msg_recv() and usb_control_msg_send()

Message ID 20210801203122.3515-7-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
The wrappers usb_control_msg_send/recv eliminate the need of allocating
dma buffers for usb message. They also impose proper error checks on the
return value of usb_control_msg() to handle short read/write. Hence use
the wrappers and remove dma allocations.

Signed-off-by: Himadri Pandya <himadrispandya@gmail.com>
---
Changes in v2:
 - Fix the caller of klsi_105_chg_port_settings()
 - Drop unnecessary use of the wrappers
---
 drivers/usb/serial/kl5kusb105.c | 79 ++++++++++++++-------------------
 1 file changed, 34 insertions(+), 45 deletions(-)

Comments

Johan Hovold Sept. 21, 2021, 12:41 p.m. UTC | #1
On Mon, Aug 02, 2021 at 02:01:22AM +0530, Himadri Pandya wrote:
> The wrappers usb_control_msg_send/recv eliminate the need of allocating

> dma buffers for usb message. They also impose proper error checks on the

> return value of usb_control_msg() to handle short read/write. Hence use

> the wrappers and remove dma allocations.

> 

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

> ---

> Changes in v2:

>  - Fix the caller of klsi_105_chg_port_settings()

>  - Drop unnecessary use of the wrappers


Now applied with an amended commit message:

    USB: serial: kl5kusb105: use usb_control_msg_recv() and usb_control_msg_send()
    
    The wrappers usb_control_msg_send/recv eliminate the need of
    manually allocating DMA buffers for USB messages. They also treat
    short reads as an error. Hence use the wrappers and remove DMA
    allocations.
    
    Note that short reads are now logged as -EREMOTEIO instead of the amount
    of data read.

I've applied all but the first two patches in the series now. Would you
mind respinning those two?

Thanks,
Johan
Himadri Pandya Sept. 26, 2021, 1 p.m. UTC | #2
On Tue, Sep 21, 2021 at 2:41 PM Johan Hovold <johan@kernel.org> wrote:
>

> On Mon, Aug 02, 2021 at 02:01:22AM +0530, Himadri Pandya wrote:

> > The wrappers usb_control_msg_send/recv eliminate the need of allocating

> > dma buffers for usb message. They also impose proper error checks on the

> > return value of usb_control_msg() to handle short read/write. Hence use

> > the wrappers and remove dma allocations.

> >

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

> > ---

> > Changes in v2:

> >  - Fix the caller of klsi_105_chg_port_settings()

> >  - Drop unnecessary use of the wrappers

>

> Now applied with an amended commit message:

>

>     USB: serial: kl5kusb105: use usb_control_msg_recv() and usb_control_msg_send()

>

>     The wrappers usb_control_msg_send/recv eliminate the need of

>     manually allocating DMA buffers for USB messages. They also treat

>     short reads as an error. Hence use the wrappers and remove DMA

>     allocations.

>

>     Note that short reads are now logged as -EREMOTEIO instead of the amount

>     of data read.

>

> I've applied all but the first two patches in the series now. Would you

> mind respinning those two?

>

> Thanks,

> Johan


Thanks for reviewing and applying these patches. And yes, I'm sending
the revised version for the first two.

Regards,
Himadri
diff mbox series

Patch

diff --git a/drivers/usb/serial/kl5kusb105.c b/drivers/usb/serial/kl5kusb105.c
index f1e9628a9907..72d3920c9c48 100644
--- a/drivers/usb/serial/kl5kusb105.c
+++ b/drivers/usb/serial/kl5kusb105.c
@@ -124,16 +124,18 @@  static int klsi_105_chg_port_settings(struct usb_serial_port *port,
 {
 	int rc;
 
-	rc = usb_control_msg(port->serial->dev,
-			usb_sndctrlpipe(port->serial->dev, 0),
-			KL5KUSB105A_SIO_SET_DATA,
-			USB_TYPE_VENDOR | USB_DIR_OUT | USB_RECIP_INTERFACE,
-			0, /* value */
-			0, /* index */
-			settings,
-			sizeof(struct klsi_105_port_settings),
-			KLSI_TIMEOUT);
-	if (rc < 0)
+	rc = usb_control_msg_send(port->serial->dev,
+				  0,
+				  KL5KUSB105A_SIO_SET_DATA,
+				  USB_TYPE_VENDOR | USB_DIR_OUT |
+				  USB_RECIP_INTERFACE,
+				  0, /* value */
+				  0, /* index */
+				  settings,
+				  sizeof(struct klsi_105_port_settings),
+				  KLSI_TIMEOUT,
+				  GFP_KERNEL);
+	if (rc)
 		dev_err(&port->dev,
 			"Change port settings failed (error = %d)\n", rc);
 
@@ -167,28 +169,21 @@  static int klsi_105_get_line_state(struct usb_serial_port *port,
 				   unsigned long *line_state_p)
 {
 	int rc;
-	u8 *status_buf;
+	u8 status_buf[KLSI_STATUSBUF_LEN];
 	__u16 status;
 
-	status_buf = kmalloc(KLSI_STATUSBUF_LEN, GFP_KERNEL);
-	if (!status_buf)
-		return -ENOMEM;
-
 	status_buf[0] = 0xff;
 	status_buf[1] = 0xff;
-	rc = usb_control_msg(port->serial->dev,
-			     usb_rcvctrlpipe(port->serial->dev, 0),
-			     KL5KUSB105A_SIO_POLL,
-			     USB_TYPE_VENDOR | USB_DIR_IN,
-			     0, /* value */
-			     0, /* index */
-			     status_buf, KLSI_STATUSBUF_LEN,
-			     10000
-			     );
-	if (rc != KLSI_STATUSBUF_LEN) {
+	rc = usb_control_msg_recv(port->serial->dev, 0,
+				  KL5KUSB105A_SIO_POLL,
+				  USB_TYPE_VENDOR | USB_DIR_IN,
+				  0, /* value */
+				  0, /* index */
+				  status_buf, KLSI_STATUSBUF_LEN,
+				  10000,
+				  GFP_KERNEL);
+	if (rc) {
 		dev_err(&port->dev, "reading line status failed: %d\n", rc);
-		if (rc >= 0)
-			rc = -EIO;
 	} else {
 		status = get_unaligned_le16(status_buf);
 
@@ -198,7 +193,6 @@  static int klsi_105_get_line_state(struct usb_serial_port *port,
 		*line_state_p = klsi_105_status2linestate(status);
 	}
 
-	kfree(status_buf);
 	return rc;
 }
 
@@ -245,7 +239,7 @@  static int  klsi_105_open(struct tty_struct *tty, struct usb_serial_port *port)
 	int retval = 0;
 	int rc;
 	unsigned long line_state;
-	struct klsi_105_port_settings *cfg;
+	struct klsi_105_port_settings cfg;
 	unsigned long flags;
 
 	/* Do a defined restart:
@@ -255,27 +249,22 @@  static int  klsi_105_open(struct tty_struct *tty, struct usb_serial_port *port)
 	 * Then read the modem line control and store values in
 	 * priv->line_state.
 	 */
-	cfg = kmalloc(sizeof(*cfg), GFP_KERNEL);
-	if (!cfg)
-		return -ENOMEM;
 
-	cfg->pktlen   = 5;
-	cfg->baudrate = kl5kusb105a_sio_b9600;
-	cfg->databits = kl5kusb105a_dtb_8;
-	cfg->unknown1 = 0;
-	cfg->unknown2 = 1;
-	klsi_105_chg_port_settings(port, cfg);
+	cfg.pktlen   = 5;
+	cfg.baudrate = kl5kusb105a_sio_b9600;
+	cfg.databits = kl5kusb105a_dtb_8;
+	cfg.unknown1 = 0;
+	cfg.unknown2 = 1;
+	klsi_105_chg_port_settings(port, &cfg);
 
 	spin_lock_irqsave(&priv->lock, flags);
-	priv->cfg.pktlen   = cfg->pktlen;
-	priv->cfg.baudrate = cfg->baudrate;
-	priv->cfg.databits = cfg->databits;
-	priv->cfg.unknown1 = cfg->unknown1;
-	priv->cfg.unknown2 = cfg->unknown2;
+	priv->cfg.pktlen   = cfg.pktlen;
+	priv->cfg.baudrate = cfg.baudrate;
+	priv->cfg.databits = cfg.databits;
+	priv->cfg.unknown1 = cfg.unknown1;
+	priv->cfg.unknown2 = cfg.unknown2;
 	spin_unlock_irqrestore(&priv->lock, flags);
 
-	kfree(cfg);
-
 	/* READ_ON and urb submission */
 	rc = usb_serial_generic_open(tty, port);
 	if (rc)