Skip to content

Commit ddf8160

Browse files
committed
USB: serial: kobil_sct: clean up tiocmset()
Clean up the tiocmset() implementation by simplifying the flag check, dropping some dev_dbg(), logging errors using dev_err() and using a common control message call for both DTR and RTS to make the existing logic easier to follow. Note that the modem control lines are currently only manipulated in this function, which therefore does not require any locking. Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Johan Hovold <johan@kernel.org>
1 parent 66b1c55 commit ddf8160

1 file changed

Lines changed: 26 additions & 35 deletions

File tree

drivers/usb/serial/kobil_sct.c

Lines changed: 26 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -418,58 +418,49 @@ static int kobil_tiocmset(struct tty_struct *tty,
418418
struct usb_serial_port *port = tty->driver_data;
419419
struct device *dev = &port->dev;
420420
struct kobil_private *priv;
421-
int result = 0;
422-
int dtr = 0;
423-
int rts = 0;
421+
int dtr, rts;
422+
int result;
423+
u16 val = 0;
424424

425-
/* FIXME: locking ? */
426425
priv = usb_get_serial_port_data(port);
427426
if (priv->device_type == KOBIL_USBTWIN_PRODUCT_ID
428427
|| priv->device_type == KOBIL_KAAN_SIM_PRODUCT_ID) {
429428
/* This device doesn't support ioctl calls */
430429
return -EINVAL;
431430
}
432431

433-
if (set & TIOCM_RTS)
434-
rts = 1;
435-
if (set & TIOCM_DTR)
436-
dtr = 1;
437-
if (clear & TIOCM_RTS)
438-
rts = 1;
439-
if (clear & TIOCM_DTR)
440-
dtr = 1;
432+
dtr = (set | clear) & TIOCM_DTR;
433+
rts = (set | clear) & TIOCM_RTS;
441434

442435
if (dtr && priv->device_type == KOBIL_ADAPTER_B_PRODUCT_ID) {
443436
if (set & TIOCM_DTR)
444-
dev_dbg(dev, "%s - Setting DTR\n", __func__);
437+
val = SUSBCR_SSL_SETDTR;
445438
else
446-
dev_dbg(dev, "%s - Clearing DTR\n", __func__);
447-
result = usb_control_msg(port->serial->dev,
448-
usb_sndctrlpipe(port->serial->dev, 0),
449-
SUSBCRequest_SetStatusLinesOrQueues,
450-
USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_OUT,
451-
((set & TIOCM_DTR) ? SUSBCR_SSL_SETDTR : SUSBCR_SSL_CLRDTR),
452-
0,
453-
NULL,
454-
0,
455-
KOBIL_TIMEOUT);
439+
val = SUSBCR_SSL_CLRDTR;
456440
} else if (rts) {
457441
if (set & TIOCM_RTS)
458-
dev_dbg(dev, "%s - Setting RTS\n", __func__);
442+
val = SUSBCR_SSL_SETRTS;
459443
else
460-
dev_dbg(dev, "%s - Clearing RTS\n", __func__);
444+
val = SUSBCR_SSL_CLRRTS;
445+
}
446+
447+
if (val) {
461448
result = usb_control_msg(port->serial->dev,
462-
usb_sndctrlpipe(port->serial->dev, 0),
463-
SUSBCRequest_SetStatusLinesOrQueues,
464-
USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_OUT,
465-
((set & TIOCM_RTS) ? SUSBCR_SSL_SETRTS : SUSBCR_SSL_CLRRTS),
466-
0,
467-
NULL,
468-
0,
469-
KOBIL_TIMEOUT);
449+
usb_sndctrlpipe(port->serial->dev, 0),
450+
SUSBCRequest_SetStatusLinesOrQueues,
451+
USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_OUT,
452+
val,
453+
0,
454+
NULL,
455+
0,
456+
KOBIL_TIMEOUT);
457+
if (result < 0) {
458+
dev_err(dev, "failed to set status lines: %d\n", result);
459+
return result;
460+
}
470461
}
471-
dev_dbg(dev, "%s - Send set_status_line URB returns: %i\n", __func__, result);
472-
return (result < 0) ? result : 0;
462+
463+
return 0;
473464
}
474465

475466
static void kobil_set_termios(struct tty_struct *tty,

0 commit comments

Comments
 (0)