USB: serial: kl5kusb105: clean up line-status handling
Subsystems (2)
Johan Hovold
maintainerPATCH 1/3 USB: serial: kl5kusb105: clean up line-status handling
In reply to Johan HovoldClean up the line-status handling by dropping redundant initialisations and returning early on errors.
--- drivers/usb/serial/kl5kusb105.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-)
drivers/usb/serial/kl5kusb105.c +8 -9
@@ -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 ; }
Signature · 1 line
2.32.0
Johan Hovold
maintainerPATCH 2/3 USB: serial: kl5kusb105: simplify line-status handling
In reply to Johan HovoldNow 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.
--- drivers/usb/serial/kl5kusb105.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
drivers/usb/serial/kl5kusb105.c +4 -8
@@ -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 2static 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);
Signature · 1 line
2.32.0
Johan Hovold
maintainercover USB: serial: kl5kusb105: clean up line-status handling
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(-)
Signature · 1 line
2.32.0
Johan Hovold
maintainerPATCH 3/3 USB: serial: kl5kusb105: drop line-status helper
Drop the line-status conversion helper and do the conversion in place instead.
--- drivers/usb/serial/kl5kusb105.c | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-)
drivers/usb/serial/kl5kusb105.c +4 -15
@@ -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 ; }
Signature · 1 line
2.32.0
Quoted 6 lines · Johan Hovold
As a follow up to the
usb_control_msg_recv()conversion, this cleans up the line-status handling some more.Johan
Quoted 7 lines
Johan Hovold (3):
USB: serial: kl5kusb105: clean up line-status handling
USB: serial: kl5kusb105: simplify line-status handling
USB: serial: kl5kusb105: drop line-status helperdrivers/usb/serial/kl5kusb105.c | 40 ++++++++++----------------------- 1 file changed, 12 insertions(+), 28 deletions(-)