linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] USB: serial: kl5kusb105: clean up line-status handling
@ 2021-09-21 13:30 Johan Hovold
  2021-09-21 13:30 ` [PATCH 1/3] " Johan Hovold
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Johan Hovold @ 2021-09-21 13:30 UTC (permalink / raw)
  To: Johan Hovold; +Cc: Himadri Pandya, linux-usb, linux-kernel

As a follow up to the usb_control_msg_recv() conversion, this cleans up
the line-status handling some more.

Johan


Johan Hovold (3):
  USB: serial: kl5kusb105: clean up line-status handling
  USB: serial: kl5kusb105: simplify line-status handling
  USB: serial: kl5kusb105: drop line-status helper

 drivers/usb/serial/kl5kusb105.c | 40 ++++++++++-----------------------
 1 file changed, 12 insertions(+), 28 deletions(-)

-- 
2.32.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/3] USB: serial: kl5kusb105: clean up line-status handling
  2021-09-21 13:30 [PATCH 0/3] USB: serial: kl5kusb105: clean up line-status handling Johan Hovold
@ 2021-09-21 13:30 ` Johan Hovold
  2021-09-21 13:30 ` [PATCH 2/3] USB: serial: kl5kusb105: simplify " Johan Hovold
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Johan Hovold @ 2021-09-21 13:30 UTC (permalink / raw)
  To: Johan Hovold; +Cc: Himadri Pandya, linux-usb, linux-kernel

Clean up the line-status handling by dropping redundant initialisations
and returning early on errors.

Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/usb/serial/kl5kusb105.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/drivers/usb/serial/kl5kusb105.c b/drivers/usb/serial/kl5kusb105.c
index 72d3920c9c48..7681671ddb79 100644
--- a/drivers/usb/serial/kl5kusb105.c
+++ b/drivers/usb/serial/kl5kusb105.c
@@ -172,8 +172,6 @@ static int klsi_105_get_line_state(struct usb_serial_port *port,
 	u8 status_buf[KLSI_STATUSBUF_LEN];
 	__u16 status;
 
-	status_buf[0] = 0xff;
-	status_buf[1] = 0xff;
 	rc = usb_control_msg_recv(port->serial->dev, 0,
 				  KL5KUSB105A_SIO_POLL,
 				  USB_TYPE_VENDOR | USB_DIR_IN,
@@ -184,16 +182,17 @@ static int klsi_105_get_line_state(struct usb_serial_port *port,
 				  GFP_KERNEL);
 	if (rc) {
 		dev_err(&port->dev, "reading line status failed: %d\n", rc);
-	} else {
-		status = get_unaligned_le16(status_buf);
+		return rc;
+	}
 
-		dev_dbg(&port->dev, "read status %02x %02x\n",
-			status_buf[0], status_buf[1]);
+	status = get_unaligned_le16(status_buf);
 
-		*line_state_p = klsi_105_status2linestate(status);
-	}
+	dev_dbg(&port->dev, "read status %02x %02x\n",
+		status_buf[0], status_buf[1]);
 
-	return rc;
+	*line_state_p = klsi_105_status2linestate(status);
+
+	return 0;
 }
 
 
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/3] USB: serial: kl5kusb105: simplify line-status handling
  2021-09-21 13:30 [PATCH 0/3] USB: serial: kl5kusb105: clean up line-status handling Johan Hovold
  2021-09-21 13:30 ` [PATCH 1/3] " Johan Hovold
@ 2021-09-21 13:30 ` Johan Hovold
  2021-09-21 13:30 ` [PATCH 3/3] USB: serial: kl5kusb105: drop line-status helper Johan Hovold
  2021-09-21 14:08 ` [PATCH 0/3] USB: serial: kl5kusb105: clean up line-status handling Greg KH
  3 siblings, 0 replies; 5+ messages in thread
From: Johan Hovold @ 2021-09-21 13:30 UTC (permalink / raw)
  To: Johan Hovold; +Cc: Himadri Pandya, linux-usb, linux-kernel

Now that the driver is using usb_control_msg_recv(), the line status
handling can be simplified further by reading directly into the status
variable and doing the endian conversion in place.

Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/usb/serial/kl5kusb105.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/drivers/usb/serial/kl5kusb105.c b/drivers/usb/serial/kl5kusb105.c
index 7681671ddb79..99dffbdd3142 100644
--- a/drivers/usb/serial/kl5kusb105.c
+++ b/drivers/usb/serial/kl5kusb105.c
@@ -163,21 +163,18 @@ static unsigned long klsi_105_status2linestate(const __u16 status)
  * Read line control via vendor command and return result through
  * *line_state_p
  */
-/* It seems that the status buffer has always only 2 bytes length */
-#define KLSI_STATUSBUF_LEN	2
 static int klsi_105_get_line_state(struct usb_serial_port *port,
 				   unsigned long *line_state_p)
 {
+	u16 status;
 	int rc;
-	u8 status_buf[KLSI_STATUSBUF_LEN];
-	__u16 status;
 
 	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,
+				  &status, sizeof(status),
 				  10000,
 				  GFP_KERNEL);
 	if (rc) {
@@ -185,10 +182,9 @@ static int klsi_105_get_line_state(struct usb_serial_port *port,
 		return rc;
 	}
 
-	status = get_unaligned_le16(status_buf);
+	le16_to_cpus(&status);
 
-	dev_dbg(&port->dev, "read status %02x %02x\n",
-		status_buf[0], status_buf[1]);
+	dev_dbg(&port->dev, "read status %04x\n", status);
 
 	*line_state_p = klsi_105_status2linestate(status);
 
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/3] USB: serial: kl5kusb105: drop line-status helper
  2021-09-21 13:30 [PATCH 0/3] USB: serial: kl5kusb105: clean up line-status handling Johan Hovold
  2021-09-21 13:30 ` [PATCH 1/3] " Johan Hovold
  2021-09-21 13:30 ` [PATCH 2/3] USB: serial: kl5kusb105: simplify " Johan Hovold
@ 2021-09-21 13:30 ` Johan Hovold
  2021-09-21 14:08 ` [PATCH 0/3] USB: serial: kl5kusb105: clean up line-status handling Greg KH
  3 siblings, 0 replies; 5+ messages in thread
From: Johan Hovold @ 2021-09-21 13:30 UTC (permalink / raw)
  To: Johan Hovold; +Cc: Himadri Pandya, linux-usb, linux-kernel

Drop the line-status conversion helper and do the conversion in place
instead.

Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/usb/serial/kl5kusb105.c | 19 ++++---------------
 1 file changed, 4 insertions(+), 15 deletions(-)

diff --git a/drivers/usb/serial/kl5kusb105.c b/drivers/usb/serial/kl5kusb105.c
index 99dffbdd3142..edcc57bd9b5e 100644
--- a/drivers/usb/serial/kl5kusb105.c
+++ b/drivers/usb/serial/kl5kusb105.c
@@ -147,24 +147,12 @@ static int klsi_105_chg_port_settings(struct usb_serial_port *port,
 	return rc;
 }
 
-/* translate a 16-bit status value from the device to linux's TIO bits */
-static unsigned long klsi_105_status2linestate(const __u16 status)
-{
-	unsigned long res = 0;
-
-	res =   ((status & KL5KUSB105A_DSR) ? TIOCM_DSR : 0)
-	      | ((status & KL5KUSB105A_CTS) ? TIOCM_CTS : 0)
-	      ;
-
-	return res;
-}
-
 /*
  * Read line control via vendor command and return result through
- * *line_state_p
+ * the state pointer.
  */
 static int klsi_105_get_line_state(struct usb_serial_port *port,
-				   unsigned long *line_state_p)
+				   unsigned long *state)
 {
 	u16 status;
 	int rc;
@@ -186,7 +174,8 @@ static int klsi_105_get_line_state(struct usb_serial_port *port,
 
 	dev_dbg(&port->dev, "read status %04x\n", status);
 
-	*line_state_p = klsi_105_status2linestate(status);
+	*state = ((status & KL5KUSB105A_DSR) ? TIOCM_DSR : 0) |
+		 ((status & KL5KUSB105A_CTS) ? TIOCM_CTS : 0);
 
 	return 0;
 }
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 0/3] USB: serial: kl5kusb105: clean up line-status handling
  2021-09-21 13:30 [PATCH 0/3] USB: serial: kl5kusb105: clean up line-status handling Johan Hovold
                   ` (2 preceding siblings ...)
  2021-09-21 13:30 ` [PATCH 3/3] USB: serial: kl5kusb105: drop line-status helper Johan Hovold
@ 2021-09-21 14:08 ` Greg KH
  3 siblings, 0 replies; 5+ messages in thread
From: Greg KH @ 2021-09-21 14:08 UTC (permalink / raw)
  To: Johan Hovold; +Cc: Himadri Pandya, linux-usb, linux-kernel

On Tue, Sep 21, 2021 at 03:30:06PM +0200, Johan Hovold wrote:
> As a follow up to the usb_control_msg_recv() conversion, this cleans up
> the line-status handling some more.
> 
> Johan
> 
> 
> Johan Hovold (3):
>   USB: serial: kl5kusb105: clean up line-status handling
>   USB: serial: kl5kusb105: simplify line-status handling
>   USB: serial: kl5kusb105: drop line-status helper
> 
>  drivers/usb/serial/kl5kusb105.c | 40 ++++++++++-----------------------
>  1 file changed, 12 insertions(+), 28 deletions(-)


Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-09-21 14:08 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-21 13:30 [PATCH 0/3] USB: serial: kl5kusb105: clean up line-status handling Johan Hovold
2021-09-21 13:30 ` [PATCH 1/3] " Johan Hovold
2021-09-21 13:30 ` [PATCH 2/3] USB: serial: kl5kusb105: simplify " Johan Hovold
2021-09-21 13:30 ` [PATCH 3/3] USB: serial: kl5kusb105: drop line-status helper Johan Hovold
2021-09-21 14:08 ` [PATCH 0/3] USB: serial: kl5kusb105: clean up line-status handling Greg KH

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).