From: Thomas Gleixner <tglx@linutronix.de>
To: LKML <linux-kernel@vger.kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>,
Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
Johan Hovold <johan@kernel.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-usb@vger.kernel.org,
Thomas Winischhofer <thomas@winischhofer.net>,
"Ahmed S. Darwish" <a.darwish@linutronix.de>,
Mathias Nyman <mathias.nyman@intel.com>,
Valentina Manea <valentina.manea.m@gmail.com>,
Shuah Khan <shuah@kernel.org>,
Alan Stern <stern@rowland.harvard.edu>,
linux-omap@vger.kernel.org, Kukjin Kim <kgene@kernel.org>,
Krzysztof Kozlowski <krzk@kernel.org>,
linux-arm-kernel@lists.infradead.org,
linux-samsung-soc@vger.kernel.org,
Felipe Balbi <balbi@kernel.org>,
Duncan Sands <duncan.sands@free.fr>
Subject: [patch 03/12] USB: serial: keyspan_pda: Consolidate room query
Date: Wed, 14 Oct 2020 16:52:18 +0200 [thread overview]
Message-ID: <20201014145727.338773481@linutronix.de> (raw)
In-Reply-To: 20201014145215.518912759@linutronix.de
From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Having two copies of the same code doesn't make the code more readable and
allocating a buffer of 1 byte for a synchronous operation is a pointless
exercise.
Add a byte buffer to struct keyspan_pda_private which can be used
instead. The buffer is only used in open() and tty->write(). Console writes
are not calling into the query. open() obviously happens before write() and
the writes are serialized by bit 0 of port->write_urbs_free which protects
also the transaction itself.
Move the actual query into a helper function and cleanup the usage sites in
keyspan_pda_write() and keyspan_pda_open().
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Johan Hovold <johan@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-usb@vger.kernel.org
---
drivers/usb/serial/keyspan_pda.c | 102 ++++++++++++++++-----------------------
1 file changed, 43 insertions(+), 59 deletions(-)
--- a/drivers/usb/serial/keyspan_pda.c
+++ b/drivers/usb/serial/keyspan_pda.c
@@ -47,6 +47,7 @@ struct keyspan_pda_private {
struct work_struct unthrottle_work;
struct usb_serial *serial;
struct usb_serial_port *port;
+ u8 query_buf;
};
@@ -436,6 +437,31 @@ static int keyspan_pda_tiocmset(struct t
return rc;
}
+/*
+ * Using priv->query_buf is safe here because this is only called for TTY
+ * operations open() and write(). write() comes post open() obviously and
+ * write() itself is serialized via bit 0 of port->write_urbs_free. Console
+ * writes are never calling into this.
+ */
+static int keyspan_pda_query_room(struct usb_serial *serial,
+ struct keyspan_pda_private *priv)
+{
+ int res;
+
+ res = 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, /* index */
+ &priv->query_buf,
+ 1,
+ 2000);
+ if (res != 1)
+ return res < 0 ? res : -EIO;
+
+ return (unsigned int)priv->query_buf;
+}
+
static int keyspan_pda_write(struct tty_struct *tty,
struct usb_serial_port *port, const unsigned char *buf, int count)
{
@@ -483,39 +509,16 @@ static int keyspan_pda_write(struct tty_
* usage because the console write can't sleep.
*/
if (count > priv->tx_room && tty) {
- u8 *room;
-
- room = kmalloc(1, GFP_KERNEL);
- if (!room) {
- rc = -ENOMEM;
- goto exit;
- }
-
- 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 > 0) {
- dev_dbg(&port->dev, "roomquery says %d\n", *room);
- priv->tx_room = *room;
- }
- kfree(room);
+ rc = keyspan_pda_query_room(serial, priv);
if (rc < 0) {
- dev_dbg(&port->dev, "roomquery failed\n");
- goto exit;
- }
- if (rc == 0) {
- dev_dbg(&port->dev, "roomquery returned 0 bytes\n");
- rc = -EIO; /* device didn't return any data */
+ dev_dbg(&port->dev, "roomquery failed %d\n", rc);
goto exit;
}
+
+ dev_dbg(&port->dev, "roomquery says %d\n", rc);
+ priv->tx_room = rc;
}
+
if (count > priv->tx_room) {
/* we're about to completely fill the Tx buffer, so
we'll be throttled afterwards. */
@@ -615,45 +618,26 @@ static int keyspan_pda_open(struct tty_s
struct usb_serial_port *port)
{
struct usb_serial *serial = port->serial;
- u8 *room;
- int rc = 0;
struct keyspan_pda_private *priv;
+ int rc;
- /* find out how much room is in the Tx ring */
- room = kmalloc(1, GFP_KERNEL);
- if (!room)
- return -ENOMEM;
+ priv = usb_get_serial_port_data(port);
- 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, /* index */
- room,
- 1,
- 2000);
+ /* find out how much room is in the Tx ring */
+ rc = keyspan_pda_query_room(serial, priv);
if (rc < 0) {
- dev_dbg(&port->dev, "%s - roomquery failed\n", __func__);
- goto error;
- }
- if (rc == 0) {
- dev_dbg(&port->dev, "%s - roomquery returned 0 bytes\n", __func__);
- rc = -EIO;
- goto error;
+ dev_dbg(&port->dev, "roomquery failed %d\n", rc);
+ return rc;
}
- priv = usb_get_serial_port_data(port);
- priv->tx_room = *room;
- priv->tx_throttled = *room ? 0 : 1;
+
+ priv->tx_room = rc;
+ priv->tx_throttled = rc ? 0 : 1;
/*Start reading from the device*/
rc = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
- if (rc) {
+ if (rc)
dev_dbg(&port->dev, "%s - usb_submit_urb(read int) failed\n", __func__);
- goto error;
- }
-error:
- kfree(room);
+
return rc;
}
static void keyspan_pda_close(struct usb_serial_port *port)
WARNING: multiple messages have this Message-ID (diff)
From: Thomas Gleixner <tglx@linutronix.de>
To: LKML <linux-kernel@vger.kernel.org>
Cc: Felipe Balbi <balbi@kernel.org>,
Thomas Winischhofer <thomas@winischhofer.net>,
Mathias Nyman <mathias.nyman@intel.com>,
Peter Zijlstra <peterz@infradead.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
linux-usb@vger.kernel.org, Johan Hovold <johan@kernel.org>,
Krzysztof Kozlowski <krzk@kernel.org>,
Valentina Manea <valentina.manea.m@gmail.com>,
linux-samsung-soc@vger.kernel.org, Kukjin Kim <kgene@kernel.org>,
Alan Stern <stern@rowland.harvard.edu>,
Duncan Sands <duncan.sands@free.fr>,
"Ahmed S. Darwish" <a.darwish@linutronix.de>,
linux-omap@vger.kernel.org, Shuah Khan <shuah@kernel.org>,
linux-arm-kernel@lists.infradead.org
Subject: [patch 03/12] USB: serial: keyspan_pda: Consolidate room query
Date: Wed, 14 Oct 2020 16:52:18 +0200 [thread overview]
Message-ID: <20201014145727.338773481@linutronix.de> (raw)
In-Reply-To: 20201014145215.518912759@linutronix.de
From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Having two copies of the same code doesn't make the code more readable and
allocating a buffer of 1 byte for a synchronous operation is a pointless
exercise.
Add a byte buffer to struct keyspan_pda_private which can be used
instead. The buffer is only used in open() and tty->write(). Console writes
are not calling into the query. open() obviously happens before write() and
the writes are serialized by bit 0 of port->write_urbs_free which protects
also the transaction itself.
Move the actual query into a helper function and cleanup the usage sites in
keyspan_pda_write() and keyspan_pda_open().
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Johan Hovold <johan@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-usb@vger.kernel.org
---
drivers/usb/serial/keyspan_pda.c | 102 ++++++++++++++++-----------------------
1 file changed, 43 insertions(+), 59 deletions(-)
--- a/drivers/usb/serial/keyspan_pda.c
+++ b/drivers/usb/serial/keyspan_pda.c
@@ -47,6 +47,7 @@ struct keyspan_pda_private {
struct work_struct unthrottle_work;
struct usb_serial *serial;
struct usb_serial_port *port;
+ u8 query_buf;
};
@@ -436,6 +437,31 @@ static int keyspan_pda_tiocmset(struct t
return rc;
}
+/*
+ * Using priv->query_buf is safe here because this is only called for TTY
+ * operations open() and write(). write() comes post open() obviously and
+ * write() itself is serialized via bit 0 of port->write_urbs_free. Console
+ * writes are never calling into this.
+ */
+static int keyspan_pda_query_room(struct usb_serial *serial,
+ struct keyspan_pda_private *priv)
+{
+ int res;
+
+ res = 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, /* index */
+ &priv->query_buf,
+ 1,
+ 2000);
+ if (res != 1)
+ return res < 0 ? res : -EIO;
+
+ return (unsigned int)priv->query_buf;
+}
+
static int keyspan_pda_write(struct tty_struct *tty,
struct usb_serial_port *port, const unsigned char *buf, int count)
{
@@ -483,39 +509,16 @@ static int keyspan_pda_write(struct tty_
* usage because the console write can't sleep.
*/
if (count > priv->tx_room && tty) {
- u8 *room;
-
- room = kmalloc(1, GFP_KERNEL);
- if (!room) {
- rc = -ENOMEM;
- goto exit;
- }
-
- 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 > 0) {
- dev_dbg(&port->dev, "roomquery says %d\n", *room);
- priv->tx_room = *room;
- }
- kfree(room);
+ rc = keyspan_pda_query_room(serial, priv);
if (rc < 0) {
- dev_dbg(&port->dev, "roomquery failed\n");
- goto exit;
- }
- if (rc == 0) {
- dev_dbg(&port->dev, "roomquery returned 0 bytes\n");
- rc = -EIO; /* device didn't return any data */
+ dev_dbg(&port->dev, "roomquery failed %d\n", rc);
goto exit;
}
+
+ dev_dbg(&port->dev, "roomquery says %d\n", rc);
+ priv->tx_room = rc;
}
+
if (count > priv->tx_room) {
/* we're about to completely fill the Tx buffer, so
we'll be throttled afterwards. */
@@ -615,45 +618,26 @@ static int keyspan_pda_open(struct tty_s
struct usb_serial_port *port)
{
struct usb_serial *serial = port->serial;
- u8 *room;
- int rc = 0;
struct keyspan_pda_private *priv;
+ int rc;
- /* find out how much room is in the Tx ring */
- room = kmalloc(1, GFP_KERNEL);
- if (!room)
- return -ENOMEM;
+ priv = usb_get_serial_port_data(port);
- 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, /* index */
- room,
- 1,
- 2000);
+ /* find out how much room is in the Tx ring */
+ rc = keyspan_pda_query_room(serial, priv);
if (rc < 0) {
- dev_dbg(&port->dev, "%s - roomquery failed\n", __func__);
- goto error;
- }
- if (rc == 0) {
- dev_dbg(&port->dev, "%s - roomquery returned 0 bytes\n", __func__);
- rc = -EIO;
- goto error;
+ dev_dbg(&port->dev, "roomquery failed %d\n", rc);
+ return rc;
}
- priv = usb_get_serial_port_data(port);
- priv->tx_room = *room;
- priv->tx_throttled = *room ? 0 : 1;
+
+ priv->tx_room = rc;
+ priv->tx_throttled = rc ? 0 : 1;
/*Start reading from the device*/
rc = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
- if (rc) {
+ if (rc)
dev_dbg(&port->dev, "%s - usb_submit_urb(read int) failed\n", __func__);
- goto error;
- }
-error:
- kfree(room);
+
return rc;
}
static void keyspan_pda_close(struct usb_serial_port *port)
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2020-10-14 15:18 UTC|newest]
Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-14 14:52 [patch 00/12] UBS: Cleanup in_interupt/in_irq/in_atomic() usage Thomas Gleixner
2020-10-14 14:52 ` Thomas Gleixner
2020-10-14 14:52 ` [patch 01/12] USB: sisusbvga: Make console support depend on BROKEN Thomas Gleixner
2020-10-14 14:52 ` [patch 02/12] USB: serial: keyspan_pda: Replace in_interrupt() usage Thomas Gleixner
2020-10-14 14:52 ` Thomas Gleixner
2020-10-14 14:52 ` Thomas Gleixner [this message]
2020-10-14 14:52 ` [patch 03/12] USB: serial: keyspan_pda: Consolidate room query Thomas Gleixner
2020-10-14 16:14 ` Alan Stern
2020-10-14 16:14 ` Alan Stern
2020-10-14 16:17 ` Thomas Gleixner
2020-10-14 16:17 ` Thomas Gleixner
2020-10-14 16:27 ` Sebastian Andrzej Siewior
2020-10-14 16:27 ` Sebastian Andrzej Siewior
2020-10-14 16:34 ` Alan Stern
2020-10-14 16:34 ` Alan Stern
2020-10-14 16:44 ` Sebastian Andrzej Siewior
2020-10-14 16:44 ` Sebastian Andrzej Siewior
2020-10-14 14:52 ` [patch 04/12] USB: serial: digi_acceleport: Remove in_interrupt() usage Thomas Gleixner
2020-10-14 14:52 ` Thomas Gleixner
2020-10-14 14:52 ` [patch 05/12] usb: xhci: Remove in_interrupt() checks Thomas Gleixner
2020-10-14 14:52 ` Thomas Gleixner
2020-10-23 13:38 ` Mathias Nyman
2020-10-23 13:38 ` Mathias Nyman
2020-10-14 14:52 ` [patch 06/12] usb: host: isp1362: Replace in_interrupt() usage Thomas Gleixner
2020-10-14 14:52 ` Thomas Gleixner
2020-10-14 18:49 ` kernel test robot
2020-10-14 18:49 ` kernel test robot
2020-10-14 14:52 ` [patch 07/12] usbip: Remove in_interrupt() check Thomas Gleixner
2020-10-14 14:52 ` Thomas Gleixner
2020-10-14 15:45 ` Shuah Khan
2020-10-14 15:45 ` Shuah Khan
2020-10-14 14:52 ` [patch 08/12] usb: hosts: Remove in_interrupt() from comments Thomas Gleixner
2020-10-14 14:52 ` Thomas Gleixner
2020-10-14 15:24 ` Krzysztof Kozlowski
2020-10-14 15:24 ` Krzysztof Kozlowski
2020-10-14 16:20 ` Alan Stern
2020-10-14 16:20 ` Alan Stern
2020-10-14 14:52 ` [patch 09/12] usb: gadget: pxa27x_udc: Replace in_interrupt() usage in comments Thomas Gleixner
2020-10-14 14:52 ` Thomas Gleixner
2020-10-14 14:52 ` [patch 10/12] usb: gadget: udc: Remove in_interrupt()/in_irq() from comments Thomas Gleixner
2020-10-14 14:52 ` Thomas Gleixner
2020-10-14 16:22 ` Alan Stern
2020-10-14 16:22 ` Alan Stern
2020-10-14 14:52 ` [patch 11/12] usb: core: Replace in_interrupt() in comments Thomas Gleixner
2020-10-14 14:52 ` Thomas Gleixner
2020-10-14 16:27 ` Alan Stern
2020-10-14 16:27 ` Alan Stern
2020-10-14 16:41 ` Sebastian Andrzej Siewior
2020-10-14 16:41 ` Sebastian Andrzej Siewior
2020-10-14 18:13 ` Alan Stern
2020-10-14 18:13 ` Alan Stern
2020-10-14 14:52 ` [patch 12/12] usb: atm: Replace in_interrupt() usage in comment Thomas Gleixner
2020-10-14 14:52 ` Thomas Gleixner
2020-10-23 8:01 ` [patch 00/12] UBS: Cleanup in_interupt/in_irq/in_atomic() usage Pavel Machek
2020-10-23 8:01 ` Pavel Machek
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=20201014145727.338773481@linutronix.de \
--to=tglx@linutronix.de \
--cc=a.darwish@linutronix.de \
--cc=balbi@kernel.org \
--cc=bigeasy@linutronix.de \
--cc=duncan.sands@free.fr \
--cc=gregkh@linuxfoundation.org \
--cc=johan@kernel.org \
--cc=kgene@kernel.org \
--cc=krzk@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-omap@vger.kernel.org \
--cc=linux-samsung-soc@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=mathias.nyman@intel.com \
--cc=peterz@infradead.org \
--cc=shuah@kernel.org \
--cc=stern@rowland.harvard.edu \
--cc=thomas@winischhofer.net \
--cc=valentina.manea.m@gmail.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.