linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Himadri Pandya <himadrispandya@gmail.com>
To: johan@kernel.org, gregkh@linuxfoundation.org,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Himadri Pandya <himadrispandya@gmail.com>
Subject: [PATCH v2 5/6] USB: serial: keyspan_pda: use usb_control_msg_recv()
Date: Mon,  2 Aug 2021 02:01:21 +0530	[thread overview]
Message-ID: <20210801203122.3515-6-himadrispandya@gmail.com> (raw)
In-Reply-To: <20210801203122.3515-1-himadrispandya@gmail.com>

Use the wrapper function usb_control_msg_recv() that accepts stack
variables and remove dma buffers from callers of usb_control_msg().

Signed-off-by: Himadri Pandya <himadrispandya@gmail.com>
---
Changes in v2:
 - Rebase the patch on top of recent changes
 - Drop unrelated style changes
---
 drivers/usb/serial/keyspan_pda.c | 70 ++++++++++++++------------------
 1 file changed, 31 insertions(+), 39 deletions(-)

diff --git a/drivers/usb/serial/keyspan_pda.c b/drivers/usb/serial/keyspan_pda.c
index 39b0f5f344c2..831dc5f42dea 100644
--- a/drivers/usb/serial/keyspan_pda.c
+++ b/drivers/usb/serial/keyspan_pda.c
@@ -77,35 +77,28 @@ static int keyspan_pda_get_write_room(struct keyspan_pda_private *priv)
 {
 	struct usb_serial_port *port = priv->port;
 	struct usb_serial *serial = port->serial;
-	u8 *room;
+	u8 room;
 	int rc;
 
-	room = kmalloc(1, GFP_KERNEL);
-	if (!room)
-		return -ENOMEM;
-
-	rc = usb_control_msg(serial->dev,
-			     usb_rcvctrlpipe(serial->dev, 0),
-			     6, /* write_room */
-			     USB_TYPE_VENDOR | USB_RECIP_INTERFACE
-			     | USB_DIR_IN,
-			     0, /* value: 0 means "remaining room" */
-			     0, /* index */
-			     room,
-			     1,
-			     2000);
-	if (rc != 1) {
-		if (rc >= 0)
-			rc = -EIO;
+	rc = usb_control_msg_recv(serial->dev,
+				  0,
+				  6, /* write_room */
+				  USB_TYPE_VENDOR | USB_RECIP_INTERFACE
+				  | USB_DIR_IN,
+				  0, /* value: 0 means "remaining room" */
+				  0, /* index */
+				  &room,
+				  1,
+				  2000,
+				  GFP_KERNEL);
+	if (rc) {
 		dev_dbg(&port->dev, "roomquery failed: %d\n", rc);
-		goto out_free;
+		goto out;
 	}
 
-	dev_dbg(&port->dev, "roomquery says %d\n", *room);
-	rc = *room;
-out_free:
-	kfree(room);
-
+	dev_dbg(&port->dev, "roomquery says %d\n", room);
+	rc = room;
+out:
 	return rc;
 }
 
@@ -381,22 +374,21 @@ static int keyspan_pda_get_modem_info(struct usb_serial *serial,
 				      unsigned char *value)
 {
 	int rc;
-	u8 *data;
-
-	data = kmalloc(1, GFP_KERNEL);
-	if (!data)
-		return -ENOMEM;
-
-	rc = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
-			     3, /* get pins */
-			     USB_TYPE_VENDOR|USB_RECIP_INTERFACE|USB_DIR_IN,
-			     0, 0, data, 1, 2000);
-	if (rc == 1)
-		*value = *data;
-	else if (rc >= 0)
-		rc = -EIO;
+	u8 data;
+
+	rc = usb_control_msg_recv(serial->dev, 0,
+				  3, /* get pins */
+				  USB_TYPE_VENDOR | USB_RECIP_INTERFACE |
+				  USB_DIR_IN,
+				  0,
+				  0,
+				  &data,
+				  1,
+				  2000,
+				  GFP_KERNEL);
+	if (rc == 0)
+		*value = data;
 
-	kfree(data);
 	return rc;
 }
 
-- 
2.17.1


  parent reply	other threads:[~2021-08-01 20:33 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-01 20:31 [PATCH v2 0/6] USB: serial: use wrappers for usb_control_msg() Himadri Pandya
2021-08-01 20:31 ` [PATCH v2 1/6] USB: serial: ch314: use usb_control_msg_recv() and usb_control_msg_send() Himadri Pandya
2021-09-21 11:26   ` Johan Hovold
2021-08-01 20:31 ` [PATCH v2 2/6] USB: serial: cp210x: " Himadri Pandya
2021-09-21 11:34   ` Johan Hovold
2021-08-01 20:31 ` [PATCH v2 3/6] USB: serial: f81232: " Himadri Pandya
2021-09-21 12:06   ` Johan Hovold
2021-08-01 20:31 ` [PATCH v2 4/6] USB: serial: ftdi_sio: use usb_control_msg_recv() Himadri Pandya
2021-09-21 12:17   ` Johan Hovold
2021-08-01 20:31 ` Himadri Pandya [this message]
2021-09-21 12:27   ` [PATCH v2 5/6] USB: serial: keyspan_pda: " Johan Hovold
2021-08-01 20:31 ` [PATCH v2 6/6] USB: serial: kl5kusb105: use usb_control_msg_recv() and usb_control_msg_send() Himadri Pandya
2021-09-21 12:41   ` Johan Hovold
2021-09-26 13:00     ` Himadri Pandya
2021-09-21 11:10 ` [PATCH v2 0/6] USB: serial: use wrappers for usb_control_msg() Johan Hovold

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210801203122.3515-6-himadrispandya@gmail.com \
    --to=himadrispandya@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=johan@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).