From 94cc7aeaf6c0cff0b8aeb7cb3579cee46b923560 Mon Sep 17 00:00:00 2001 From: Jiri Slaby Date: Wed, 5 May 2021 11:19:16 +0200 Subject: USB: serial: make usb_serial_driver::write_room return uint Line disciplines expect a positive value or zero returned from tty->ops->write_room (invoked by tty_write_room). Both of them are being updated to return an unsigned int. Switch also usb_serial_driver::write_room and all its users. Signed-off-by: Jiri Slaby [ johan: amend commit message, drop unrelated comment change ] Signed-off-by: Johan Hovold --- drivers/usb/serial/cyberjack.c | 4 ++-- drivers/usb/serial/cypress_m8.c | 8 ++++---- drivers/usb/serial/digi_acceleport.c | 8 ++++---- drivers/usb/serial/garmin_gps.c | 2 +- drivers/usb/serial/generic.c | 6 +++--- drivers/usb/serial/io_edgeport.c | 6 +++--- drivers/usb/serial/io_ti.c | 6 +++--- drivers/usb/serial/ir-usb.c | 6 +++--- drivers/usb/serial/keyspan.c | 4 ++-- drivers/usb/serial/kobil_sct.c | 4 ++-- drivers/usb/serial/mos7720.c | 6 +++--- drivers/usb/serial/mos7840.c | 6 +++--- drivers/usb/serial/opticon.c | 2 +- drivers/usb/serial/oti6858.c | 6 +++--- drivers/usb/serial/quatech2.c | 4 ++-- drivers/usb/serial/sierra.c | 2 +- drivers/usb/serial/ti_usb_3410_5052.c | 8 ++++---- drivers/usb/serial/usb-wwan.h | 2 +- drivers/usb/serial/usb_wwan.c | 6 +++--- 19 files changed, 48 insertions(+), 48 deletions(-) (limited to 'drivers/usb') diff --git a/drivers/usb/serial/cyberjack.c b/drivers/usb/serial/cyberjack.c index cf389224d528..51e5aac3bf4c 100644 --- a/drivers/usb/serial/cyberjack.c +++ b/drivers/usb/serial/cyberjack.c @@ -53,7 +53,7 @@ static int cyberjack_open(struct tty_struct *tty, static void cyberjack_close(struct usb_serial_port *port); static int cyberjack_write(struct tty_struct *tty, struct usb_serial_port *port, const unsigned char *buf, int count); -static int cyberjack_write_room(struct tty_struct *tty); +static unsigned int cyberjack_write_room(struct tty_struct *tty); static void cyberjack_read_int_callback(struct urb *urb); static void cyberjack_read_bulk_callback(struct urb *urb); static void cyberjack_write_bulk_callback(struct urb *urb); @@ -240,7 +240,7 @@ static int cyberjack_write(struct tty_struct *tty, return count; } -static int cyberjack_write_room(struct tty_struct *tty) +static unsigned int cyberjack_write_room(struct tty_struct *tty) { /* FIXME: .... */ return CYBERJACK_LOCAL_BUF_SIZE; diff --git a/drivers/usb/serial/cypress_m8.c b/drivers/usb/serial/cypress_m8.c index 166ee2286fda..5e7d2f9fa0c2 100644 --- a/drivers/usb/serial/cypress_m8.c +++ b/drivers/usb/serial/cypress_m8.c @@ -122,7 +122,7 @@ static void cypress_dtr_rts(struct usb_serial_port *port, int on); static int cypress_write(struct tty_struct *tty, struct usb_serial_port *port, const unsigned char *buf, int count); static void cypress_send(struct usb_serial_port *port); -static int cypress_write_room(struct tty_struct *tty); +static unsigned int cypress_write_room(struct tty_struct *tty); static void cypress_earthmate_init_termios(struct tty_struct *tty); static void cypress_set_termios(struct tty_struct *tty, struct usb_serial_port *port, struct ktermios *old); @@ -789,18 +789,18 @@ send: /* returns how much space is available in the soft buffer */ -static int cypress_write_room(struct tty_struct *tty) +static unsigned int cypress_write_room(struct tty_struct *tty) { struct usb_serial_port *port = tty->driver_data; struct cypress_private *priv = usb_get_serial_port_data(port); - int room = 0; + unsigned int room; unsigned long flags; spin_lock_irqsave(&priv->lock, flags); room = kfifo_avail(&priv->write_fifo); spin_unlock_irqrestore(&priv->lock, flags); - dev_dbg(&port->dev, "%s - returns %d\n", __func__, room); + dev_dbg(&port->dev, "%s - returns %u\n", __func__, room); return room; } diff --git a/drivers/usb/serial/digi_acceleport.c b/drivers/usb/serial/digi_acceleport.c index 8b2f06539f2c..5deb900450ee 100644 --- a/drivers/usb/serial/digi_acceleport.c +++ b/drivers/usb/serial/digi_acceleport.c @@ -223,7 +223,7 @@ static int digi_tiocmset(struct tty_struct *tty, unsigned int set, static int digi_write(struct tty_struct *tty, struct usb_serial_port *port, const unsigned char *buf, int count); static void digi_write_bulk_callback(struct urb *urb); -static int digi_write_room(struct tty_struct *tty); +static unsigned int digi_write_room(struct tty_struct *tty); static int digi_chars_in_buffer(struct tty_struct *tty); static int digi_open(struct tty_struct *tty, struct usb_serial_port *port); static void digi_close(struct usb_serial_port *port); @@ -1020,11 +1020,11 @@ static void digi_write_bulk_callback(struct urb *urb) tty_port_tty_wakeup(&port->port); } -static int digi_write_room(struct tty_struct *tty) +static unsigned int digi_write_room(struct tty_struct *tty) { struct usb_serial_port *port = tty->driver_data; struct digi_port *priv = usb_get_serial_port_data(port); - int room; + unsigned int room; unsigned long flags = 0; spin_lock_irqsave(&priv->dp_port_lock, flags); @@ -1035,7 +1035,7 @@ static int digi_write_room(struct tty_struct *tty) room = port->bulk_out_size - 2 - priv->dp_out_buf_len; spin_unlock_irqrestore(&priv->dp_port_lock, flags); - dev_dbg(&port->dev, "digi_write_room: port=%d, room=%d\n", priv->dp_port_num, room); + dev_dbg(&port->dev, "digi_write_room: port=%d, room=%u\n", priv->dp_port_num, room); return room; } diff --git a/drivers/usb/serial/garmin_gps.c b/drivers/usb/serial/garmin_gps.c index 50e8bdc77e71..756d1ac7e96f 100644 --- a/drivers/usb/serial/garmin_gps.c +++ b/drivers/usb/serial/garmin_gps.c @@ -1113,7 +1113,7 @@ static int garmin_write(struct tty_struct *tty, struct usb_serial_port *port, } -static int garmin_write_room(struct tty_struct *tty) +static unsigned int garmin_write_room(struct tty_struct *tty) { struct usb_serial_port *port = tty->driver_data; /* diff --git a/drivers/usb/serial/generic.c b/drivers/usb/serial/generic.c index d10aa3d2ee49..bc3cf66af0de 100644 --- a/drivers/usb/serial/generic.c +++ b/drivers/usb/serial/generic.c @@ -230,11 +230,11 @@ int usb_serial_generic_write(struct tty_struct *tty, } EXPORT_SYMBOL_GPL(usb_serial_generic_write); -int usb_serial_generic_write_room(struct tty_struct *tty) +unsigned int usb_serial_generic_write_room(struct tty_struct *tty) { struct usb_serial_port *port = tty->driver_data; unsigned long flags; - int room; + unsigned int room; if (!port->bulk_out_size) return 0; @@ -243,7 +243,7 @@ int usb_serial_generic_write_room(struct tty_struct *tty) room = kfifo_avail(&port->write_fifo); spin_unlock_irqrestore(&port->lock, flags); - dev_dbg(&port->dev, "%s - returns %d\n", __func__, room); + dev_dbg(&port->dev, "%s - returns %u\n", __func__, room); return room; } diff --git a/drivers/usb/serial/io_edgeport.c b/drivers/usb/serial/io_edgeport.c index e6fe3882bf69..f6cedc87d3e4 100644 --- a/drivers/usb/serial/io_edgeport.c +++ b/drivers/usb/serial/io_edgeport.c @@ -1355,11 +1355,11 @@ exit_send: * we return the amount of room that we have for this port (the txCredits) * otherwise we return a negative error number. *****************************************************************************/ -static int edge_write_room(struct tty_struct *tty) +static unsigned int edge_write_room(struct tty_struct *tty) { struct usb_serial_port *port = tty->driver_data; struct edgeport_port *edge_port = usb_get_serial_port_data(port); - int room; + unsigned int room; unsigned long flags; if (edge_port == NULL) @@ -1377,7 +1377,7 @@ static int edge_write_room(struct tty_struct *tty) room = edge_port->txCredits - edge_port->txfifo.count; spin_unlock_irqrestore(&edge_port->ep_lock, flags); - dev_dbg(&port->dev, "%s - returns %d\n", __func__, room); + dev_dbg(&port->dev, "%s - returns %u\n", __func__, room); return room; } diff --git a/drivers/usb/serial/io_ti.c b/drivers/usb/serial/io_ti.c index 39503fdccebf..94c82c33e629 100644 --- a/drivers/usb/serial/io_ti.c +++ b/drivers/usb/serial/io_ti.c @@ -2067,11 +2067,11 @@ static void edge_send(struct usb_serial_port *port, struct tty_struct *tty) tty_wakeup(tty); } -static int edge_write_room(struct tty_struct *tty) +static unsigned int edge_write_room(struct tty_struct *tty) { struct usb_serial_port *port = tty->driver_data; struct edgeport_port *edge_port = usb_get_serial_port_data(port); - int room = 0; + unsigned int room; unsigned long flags; if (edge_port == NULL) @@ -2083,7 +2083,7 @@ static int edge_write_room(struct tty_struct *tty) room = kfifo_avail(&port->write_fifo); spin_unlock_irqrestore(&edge_port->ep_lock, flags); - dev_dbg(&port->dev, "%s - returns %d\n", __func__, room); + dev_dbg(&port->dev, "%s - returns %u\n", __func__, room); return room; } diff --git a/drivers/usb/serial/ir-usb.c b/drivers/usb/serial/ir-usb.c index 172261a908d8..7b44dbea95cd 100644 --- a/drivers/usb/serial/ir-usb.c +++ b/drivers/usb/serial/ir-usb.c @@ -47,7 +47,7 @@ static int xbof = -1; static int ir_startup (struct usb_serial *serial); static int ir_write(struct tty_struct *tty, struct usb_serial_port *port, const unsigned char *buf, int count); -static int ir_write_room(struct tty_struct *tty); +static unsigned int ir_write_room(struct tty_struct *tty); static void ir_write_bulk_callback(struct urb *urb); static void ir_process_read_urb(struct urb *urb); static void ir_set_termios(struct tty_struct *tty, @@ -339,10 +339,10 @@ static void ir_write_bulk_callback(struct urb *urb) usb_serial_port_softint(port); } -static int ir_write_room(struct tty_struct *tty) +static unsigned int ir_write_room(struct tty_struct *tty) { struct usb_serial_port *port = tty->driver_data; - int count = 0; + unsigned int count = 0; if (port->bulk_out_size == 0) return 0; diff --git a/drivers/usb/serial/keyspan.c b/drivers/usb/serial/keyspan.c index b04a029e3657..87b89c99d517 100644 --- a/drivers/usb/serial/keyspan.c +++ b/drivers/usb/serial/keyspan.c @@ -1453,13 +1453,13 @@ static void usa67_glocont_callback(struct urb *urb) } } -static int keyspan_write_room(struct tty_struct *tty) +static unsigned int keyspan_write_room(struct tty_struct *tty) { struct usb_serial_port *port = tty->driver_data; struct keyspan_port_private *p_priv; const struct keyspan_device_details *d_details; int flip; - int data_len; + unsigned int data_len; struct urb *this_urb; p_priv = usb_get_serial_port_data(port); diff --git a/drivers/usb/serial/kobil_sct.c b/drivers/usb/serial/kobil_sct.c index a9bc546626ab..4ed8b8b0a361 100644 --- a/drivers/usb/serial/kobil_sct.c +++ b/drivers/usb/serial/kobil_sct.c @@ -53,7 +53,7 @@ static int kobil_open(struct tty_struct *tty, struct usb_serial_port *port); static void kobil_close(struct usb_serial_port *port); static int kobil_write(struct tty_struct *tty, struct usb_serial_port *port, const unsigned char *buf, int count); -static int kobil_write_room(struct tty_struct *tty); +static unsigned int kobil_write_room(struct tty_struct *tty); static int kobil_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg); static int kobil_tiocmget(struct tty_struct *tty); @@ -358,7 +358,7 @@ static int kobil_write(struct tty_struct *tty, struct usb_serial_port *port, } -static int kobil_write_room(struct tty_struct *tty) +static unsigned int kobil_write_room(struct tty_struct *tty) { /* FIXME */ return 8; diff --git a/drivers/usb/serial/mos7720.c b/drivers/usb/serial/mos7720.c index 6ee83886e2c9..d9cc7f840d48 100644 --- a/drivers/usb/serial/mos7720.c +++ b/drivers/usb/serial/mos7720.c @@ -1033,11 +1033,11 @@ static void mos7720_break(struct tty_struct *tty, int break_state) * If successful, we return the amount of room that we have for this port * Otherwise we return a negative error number. */ -static int mos7720_write_room(struct tty_struct *tty) +static unsigned int mos7720_write_room(struct tty_struct *tty) { struct usb_serial_port *port = tty->driver_data; struct moschip_port *mos7720_port; - int room = 0; + unsigned int room = 0; int i; mos7720_port = usb_get_serial_port_data(port); @@ -1051,7 +1051,7 @@ static int mos7720_write_room(struct tty_struct *tty) room += URB_TRANSFER_BUFFER_SIZE; } - dev_dbg(&port->dev, "%s - returns %d\n", __func__, room); + dev_dbg(&port->dev, "%s - returns %u\n", __func__, room); return room; } diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c index 28e4093794e0..609799aaba72 100644 --- a/drivers/usb/serial/mos7840.c +++ b/drivers/usb/serial/mos7840.c @@ -818,12 +818,12 @@ static void mos7840_break(struct tty_struct *tty, int break_state) * Otherwise we return a negative error number. *****************************************************************************/ -static int mos7840_write_room(struct tty_struct *tty) +static unsigned int mos7840_write_room(struct tty_struct *tty) { struct usb_serial_port *port = tty->driver_data; struct moschip_port *mos7840_port = usb_get_serial_port_data(port); int i; - int room = 0; + unsigned int room = 0; unsigned long flags; spin_lock_irqsave(&mos7840_port->pool_lock, flags); @@ -834,7 +834,7 @@ static int mos7840_write_room(struct tty_struct *tty) spin_unlock_irqrestore(&mos7840_port->pool_lock, flags); room = (room == 0) ? 0 : room - URB_TRANSFER_BUFFER_SIZE + 1; - dev_dbg(&mos7840_port->port->dev, "%s - returns %d\n", __func__, room); + dev_dbg(&mos7840_port->port->dev, "%s - returns %u\n", __func__, room); return room; } diff --git a/drivers/usb/serial/opticon.c b/drivers/usb/serial/opticon.c index 40c713fae0c3..37b51947bd0b 100644 --- a/drivers/usb/serial/opticon.c +++ b/drivers/usb/serial/opticon.c @@ -267,7 +267,7 @@ error_no_buffer: return ret; } -static int opticon_write_room(struct tty_struct *tty) +static unsigned int opticon_write_room(struct tty_struct *tty) { struct usb_serial_port *port = tty->driver_data; struct opticon_private *priv = usb_get_serial_port_data(port); diff --git a/drivers/usb/serial/oti6858.c b/drivers/usb/serial/oti6858.c index 65cd0341fa78..4ab9f335dd0e 100644 --- a/drivers/usb/serial/oti6858.c +++ b/drivers/usb/serial/oti6858.c @@ -126,7 +126,7 @@ static void oti6858_read_bulk_callback(struct urb *urb); static void oti6858_write_bulk_callback(struct urb *urb); static int oti6858_write(struct tty_struct *tty, struct usb_serial_port *port, const unsigned char *buf, int count); -static int oti6858_write_room(struct tty_struct *tty); +static unsigned int oti6858_write_room(struct tty_struct *tty); static int oti6858_chars_in_buffer(struct tty_struct *tty); static int oti6858_tiocmget(struct tty_struct *tty); static int oti6858_tiocmset(struct tty_struct *tty, @@ -363,10 +363,10 @@ static int oti6858_write(struct tty_struct *tty, struct usb_serial_port *port, return count; } -static int oti6858_write_room(struct tty_struct *tty) +static unsigned int oti6858_write_room(struct tty_struct *tty) { struct usb_serial_port *port = tty->driver_data; - int room = 0; + unsigned int room; unsigned long flags; spin_lock_irqsave(&port->lock, flags); diff --git a/drivers/usb/serial/quatech2.c b/drivers/usb/serial/quatech2.c index 5f2e7f668e68..3b5f2032ecdb 100644 --- a/drivers/usb/serial/quatech2.c +++ b/drivers/usb/serial/quatech2.c @@ -870,12 +870,12 @@ static void qt2_update_lsr(struct usb_serial_port *port, unsigned char *ch) } -static int qt2_write_room(struct tty_struct *tty) +static unsigned int qt2_write_room(struct tty_struct *tty) { struct usb_serial_port *port = tty->driver_data; struct qt2_port_private *port_priv; unsigned long flags = 0; - int r; + unsigned int r; port_priv = usb_get_serial_port_data(port); diff --git a/drivers/usb/serial/sierra.c b/drivers/usb/serial/sierra.c index 54e16ffc30a0..753cee5d17a1 100644 --- a/drivers/usb/serial/sierra.c +++ b/drivers/usb/serial/sierra.c @@ -613,7 +613,7 @@ static void sierra_instat_callback(struct urb *urb) } } -static int sierra_write_room(struct tty_struct *tty) +static unsigned int sierra_write_room(struct tty_struct *tty) { struct usb_serial_port *port = tty->driver_data; struct sierra_port_private *portdata = usb_get_serial_port_data(port); diff --git a/drivers/usb/serial/ti_usb_3410_5052.c b/drivers/usb/serial/ti_usb_3410_5052.c index caa46ac23db9..2c543c175296 100644 --- a/drivers/usb/serial/ti_usb_3410_5052.c +++ b/drivers/usb/serial/ti_usb_3410_5052.c @@ -307,7 +307,7 @@ static int ti_open(struct tty_struct *tty, struct usb_serial_port *port); static void ti_close(struct usb_serial_port *port); static int ti_write(struct tty_struct *tty, struct usb_serial_port *port, const unsigned char *data, int count); -static int ti_write_room(struct tty_struct *tty); +static unsigned int ti_write_room(struct tty_struct *tty); static int ti_chars_in_buffer(struct tty_struct *tty); static bool ti_tx_empty(struct usb_serial_port *port); static void ti_throttle(struct tty_struct *tty); @@ -810,18 +810,18 @@ static int ti_write(struct tty_struct *tty, struct usb_serial_port *port, } -static int ti_write_room(struct tty_struct *tty) +static unsigned int ti_write_room(struct tty_struct *tty) { struct usb_serial_port *port = tty->driver_data; struct ti_port *tport = usb_get_serial_port_data(port); - int room = 0; + unsigned int room; unsigned long flags; spin_lock_irqsave(&tport->tp_lock, flags); room = kfifo_avail(&port->write_fifo); spin_unlock_irqrestore(&tport->tp_lock, flags); - dev_dbg(&port->dev, "%s - returns %d\n", __func__, room); + dev_dbg(&port->dev, "%s - returns %u\n", __func__, room); return room; } diff --git a/drivers/usb/serial/usb-wwan.h b/drivers/usb/serial/usb-wwan.h index b5331d03092f..6c7c9f3309b0 100644 --- a/drivers/usb/serial/usb-wwan.h +++ b/drivers/usb/serial/usb-wwan.h @@ -11,7 +11,7 @@ extern int usb_wwan_open(struct tty_struct *tty, struct usb_serial_port *port); extern void usb_wwan_close(struct usb_serial_port *port); extern int usb_wwan_port_probe(struct usb_serial_port *port); extern void usb_wwan_port_remove(struct usb_serial_port *port); -extern int usb_wwan_write_room(struct tty_struct *tty); +extern unsigned int usb_wwan_write_room(struct tty_struct *tty); extern int usb_wwan_tiocmget(struct tty_struct *tty); extern int usb_wwan_tiocmset(struct tty_struct *tty, unsigned int set, unsigned int clear); diff --git a/drivers/usb/serial/usb_wwan.c b/drivers/usb/serial/usb_wwan.c index 3eb72c59ede6..06212f08d9f9 100644 --- a/drivers/usb/serial/usb_wwan.c +++ b/drivers/usb/serial/usb_wwan.c @@ -278,12 +278,12 @@ static void usb_wwan_outdat_callback(struct urb *urb) } } -int usb_wwan_write_room(struct tty_struct *tty) +unsigned int usb_wwan_write_room(struct tty_struct *tty) { struct usb_serial_port *port = tty->driver_data; struct usb_wwan_port_private *portdata; int i; - int data_len = 0; + unsigned int data_len = 0; struct urb *this_urb; portdata = usb_get_serial_port_data(port); @@ -294,7 +294,7 @@ int usb_wwan_write_room(struct tty_struct *tty) data_len += OUT_BUFLEN; } - dev_dbg(&port->dev, "%s: %d\n", __func__, data_len); + dev_dbg(&port->dev, "%s: %u\n", __func__, data_len); return data_len; } EXPORT_SYMBOL(usb_wwan_write_room); -- cgit v1.2.3 From 155591d3ceeec2cd6a50b40278e2014c45f6b5f6 Mon Sep 17 00:00:00 2001 From: Jiri Slaby Date: Wed, 5 May 2021 11:19:20 +0200 Subject: USB: serial: make usb_serial_driver::chars_in_buffer return uint tty_operations::chars_in_buffer is being switched to return uint. Do the same for usb_serial_driver's chars_in_buffer. Signed-off-by: Jiri Slaby [ johan: amend commit message ] Signed-off-by: Johan Hovold --- drivers/usb/serial/cypress_m8.c | 8 ++++---- drivers/usb/serial/digi_acceleport.c | 4 ++-- drivers/usb/serial/generic.c | 6 +++--- drivers/usb/serial/io_edgeport.c | 6 +++--- drivers/usb/serial/io_ti.c | 6 +++--- drivers/usb/serial/mos7720.c | 6 +++--- drivers/usb/serial/mos7840.c | 6 +++--- drivers/usb/serial/opticon.c | 4 ++-- drivers/usb/serial/oti6858.c | 6 +++--- drivers/usb/serial/sierra.c | 6 +++--- drivers/usb/serial/ti_usb_3410_5052.c | 8 ++++---- drivers/usb/serial/usb-wwan.h | 2 +- drivers/usb/serial/usb_wwan.c | 6 +++--- 13 files changed, 37 insertions(+), 37 deletions(-) (limited to 'drivers/usb') diff --git a/drivers/usb/serial/cypress_m8.c b/drivers/usb/serial/cypress_m8.c index 5e7d2f9fa0c2..1dca04e1519d 100644 --- a/drivers/usb/serial/cypress_m8.c +++ b/drivers/usb/serial/cypress_m8.c @@ -129,7 +129,7 @@ static void cypress_set_termios(struct tty_struct *tty, static int cypress_tiocmget(struct tty_struct *tty); static int cypress_tiocmset(struct tty_struct *tty, unsigned int set, unsigned int clear); -static int cypress_chars_in_buffer(struct tty_struct *tty); +static unsigned int cypress_chars_in_buffer(struct tty_struct *tty); static void cypress_throttle(struct tty_struct *tty); static void cypress_unthrottle(struct tty_struct *tty); static void cypress_set_dead(struct usb_serial_port *port); @@ -970,18 +970,18 @@ static void cypress_set_termios(struct tty_struct *tty, /* returns amount of data still left in soft buffer */ -static int cypress_chars_in_buffer(struct tty_struct *tty) +static unsigned int cypress_chars_in_buffer(struct tty_struct *tty) { struct usb_serial_port *port = tty->driver_data; struct cypress_private *priv = usb_get_serial_port_data(port); - int chars = 0; + unsigned int chars; unsigned long flags; spin_lock_irqsave(&priv->lock, flags); chars = kfifo_len(&priv->write_fifo); spin_unlock_irqrestore(&priv->lock, flags); - dev_dbg(&port->dev, "%s - returns %d\n", __func__, chars); + dev_dbg(&port->dev, "%s - returns %u\n", __func__, chars); return chars; } diff --git a/drivers/usb/serial/digi_acceleport.c b/drivers/usb/serial/digi_acceleport.c index 5deb900450ee..19ee8191647c 100644 --- a/drivers/usb/serial/digi_acceleport.c +++ b/drivers/usb/serial/digi_acceleport.c @@ -224,7 +224,7 @@ static int digi_write(struct tty_struct *tty, struct usb_serial_port *port, const unsigned char *buf, int count); static void digi_write_bulk_callback(struct urb *urb); static unsigned int digi_write_room(struct tty_struct *tty); -static int digi_chars_in_buffer(struct tty_struct *tty); +static unsigned int digi_chars_in_buffer(struct tty_struct *tty); static int digi_open(struct tty_struct *tty, struct usb_serial_port *port); static void digi_close(struct usb_serial_port *port); static void digi_dtr_rts(struct usb_serial_port *port, int on); @@ -1040,7 +1040,7 @@ static unsigned int digi_write_room(struct tty_struct *tty) } -static int digi_chars_in_buffer(struct tty_struct *tty) +static unsigned int digi_chars_in_buffer(struct tty_struct *tty) { struct usb_serial_port *port = tty->driver_data; struct digi_port *priv = usb_get_serial_port_data(port); diff --git a/drivers/usb/serial/generic.c b/drivers/usb/serial/generic.c index bc3cf66af0de..15b6dee3a8e5 100644 --- a/drivers/usb/serial/generic.c +++ b/drivers/usb/serial/generic.c @@ -247,11 +247,11 @@ unsigned int usb_serial_generic_write_room(struct tty_struct *tty) return room; } -int usb_serial_generic_chars_in_buffer(struct tty_struct *tty) +unsigned int usb_serial_generic_chars_in_buffer(struct tty_struct *tty) { struct usb_serial_port *port = tty->driver_data; unsigned long flags; - int chars; + unsigned int chars; if (!port->bulk_out_size) return 0; @@ -260,7 +260,7 @@ int usb_serial_generic_chars_in_buffer(struct tty_struct *tty) chars = kfifo_len(&port->write_fifo) + port->tx_bytes; spin_unlock_irqrestore(&port->lock, flags); - dev_dbg(&port->dev, "%s - returns %d\n", __func__, chars); + dev_dbg(&port->dev, "%s - returns %u\n", __func__, chars); return chars; } EXPORT_SYMBOL_GPL(usb_serial_generic_chars_in_buffer); diff --git a/drivers/usb/serial/io_edgeport.c b/drivers/usb/serial/io_edgeport.c index f6cedc87d3e4..1f8dff4390c7 100644 --- a/drivers/usb/serial/io_edgeport.c +++ b/drivers/usb/serial/io_edgeport.c @@ -1391,11 +1391,11 @@ static unsigned int edge_write_room(struct tty_struct *tty) * system, * Otherwise we return a negative error number. *****************************************************************************/ -static int edge_chars_in_buffer(struct tty_struct *tty) +static unsigned int edge_chars_in_buffer(struct tty_struct *tty) { struct usb_serial_port *port = tty->driver_data; struct edgeport_port *edge_port = usb_get_serial_port_data(port); - int num_chars; + unsigned int num_chars; unsigned long flags; if (edge_port == NULL) @@ -1413,7 +1413,7 @@ static int edge_chars_in_buffer(struct tty_struct *tty) edge_port->txfifo.count; spin_unlock_irqrestore(&edge_port->ep_lock, flags); if (num_chars) { - dev_dbg(&port->dev, "%s - returns %d\n", __func__, num_chars); + dev_dbg(&port->dev, "%s - returns %u\n", __func__, num_chars); } return num_chars; diff --git a/drivers/usb/serial/io_ti.c b/drivers/usb/serial/io_ti.c index 94c82c33e629..84b848d2794e 100644 --- a/drivers/usb/serial/io_ti.c +++ b/drivers/usb/serial/io_ti.c @@ -2087,11 +2087,11 @@ static unsigned int edge_write_room(struct tty_struct *tty) return room; } -static int edge_chars_in_buffer(struct tty_struct *tty) +static unsigned int edge_chars_in_buffer(struct tty_struct *tty) { struct usb_serial_port *port = tty->driver_data; struct edgeport_port *edge_port = usb_get_serial_port_data(port); - int chars = 0; + unsigned int chars; unsigned long flags; if (edge_port == NULL) return 0; @@ -2100,7 +2100,7 @@ static int edge_chars_in_buffer(struct tty_struct *tty) chars = kfifo_len(&port->write_fifo); spin_unlock_irqrestore(&edge_port->ep_lock, flags); - dev_dbg(&port->dev, "%s - returns %d\n", __func__, chars); + dev_dbg(&port->dev, "%s - returns %u\n", __func__, chars); return chars; } diff --git a/drivers/usb/serial/mos7720.c b/drivers/usb/serial/mos7720.c index d9cc7f840d48..ce41009756f3 100644 --- a/drivers/usb/serial/mos7720.c +++ b/drivers/usb/serial/mos7720.c @@ -949,11 +949,11 @@ static int mos7720_open(struct tty_struct *tty, struct usb_serial_port *port) * system, * Otherwise we return a negative error number. */ -static int mos7720_chars_in_buffer(struct tty_struct *tty) +static unsigned int mos7720_chars_in_buffer(struct tty_struct *tty) { struct usb_serial_port *port = tty->driver_data; int i; - int chars = 0; + unsigned int chars = 0; struct moschip_port *mos7720_port; mos7720_port = usb_get_serial_port_data(port); @@ -965,7 +965,7 @@ static int mos7720_chars_in_buffer(struct tty_struct *tty) mos7720_port->write_urb_pool[i]->status == -EINPROGRESS) chars += URB_TRANSFER_BUFFER_SIZE; } - dev_dbg(&port->dev, "%s - returns %d\n", __func__, chars); + dev_dbg(&port->dev, "%s - returns %u\n", __func__, chars); return chars; } diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c index 609799aaba72..b22ccbd98998 100644 --- a/drivers/usb/serial/mos7840.c +++ b/drivers/usb/serial/mos7840.c @@ -735,12 +735,12 @@ err: * Otherwise we return zero. *****************************************************************************/ -static int mos7840_chars_in_buffer(struct tty_struct *tty) +static unsigned int mos7840_chars_in_buffer(struct tty_struct *tty) { struct usb_serial_port *port = tty->driver_data; struct moschip_port *mos7840_port = usb_get_serial_port_data(port); int i; - int chars = 0; + unsigned int chars = 0; unsigned long flags; spin_lock_irqsave(&mos7840_port->pool_lock, flags); @@ -751,7 +751,7 @@ static int mos7840_chars_in_buffer(struct tty_struct *tty) } } spin_unlock_irqrestore(&mos7840_port->pool_lock, flags); - dev_dbg(&port->dev, "%s - returns %d\n", __func__, chars); + dev_dbg(&port->dev, "%s - returns %u\n", __func__, chars); return chars; } diff --git a/drivers/usb/serial/opticon.c b/drivers/usb/serial/opticon.c index 37b51947bd0b..aed28c35caff 100644 --- a/drivers/usb/serial/opticon.c +++ b/drivers/usb/serial/opticon.c @@ -289,12 +289,12 @@ static unsigned int opticon_write_room(struct tty_struct *tty) return 2048; } -static int opticon_chars_in_buffer(struct tty_struct *tty) +static unsigned int opticon_chars_in_buffer(struct tty_struct *tty) { struct usb_serial_port *port = tty->driver_data; struct opticon_private *priv = usb_get_serial_port_data(port); unsigned long flags; - int count; + unsigned int count; spin_lock_irqsave(&priv->lock, flags); count = priv->outstanding_bytes; diff --git a/drivers/usb/serial/oti6858.c b/drivers/usb/serial/oti6858.c index 4ab9f335dd0e..a5caedbe72e2 100644 --- a/drivers/usb/serial/oti6858.c +++ b/drivers/usb/serial/oti6858.c @@ -127,7 +127,7 @@ static void oti6858_write_bulk_callback(struct urb *urb); static int oti6858_write(struct tty_struct *tty, struct usb_serial_port *port, const unsigned char *buf, int count); static unsigned int oti6858_write_room(struct tty_struct *tty); -static int oti6858_chars_in_buffer(struct tty_struct *tty); +static unsigned int oti6858_chars_in_buffer(struct tty_struct *tty); static int oti6858_tiocmget(struct tty_struct *tty); static int oti6858_tiocmset(struct tty_struct *tty, unsigned int set, unsigned int clear); @@ -376,10 +376,10 @@ static unsigned int oti6858_write_room(struct tty_struct *tty) return room; } -static int oti6858_chars_in_buffer(struct tty_struct *tty) +static unsigned int oti6858_chars_in_buffer(struct tty_struct *tty) { struct usb_serial_port *port = tty->driver_data; - int chars = 0; + unsigned int chars; unsigned long flags; spin_lock_irqsave(&port->lock, flags); diff --git a/drivers/usb/serial/sierra.c b/drivers/usb/serial/sierra.c index 753cee5d17a1..4b49b7c33364 100644 --- a/drivers/usb/serial/sierra.c +++ b/drivers/usb/serial/sierra.c @@ -632,19 +632,19 @@ static unsigned int sierra_write_room(struct tty_struct *tty) return 2048; } -static int sierra_chars_in_buffer(struct tty_struct *tty) +static unsigned int sierra_chars_in_buffer(struct tty_struct *tty) { struct usb_serial_port *port = tty->driver_data; struct sierra_port_private *portdata = usb_get_serial_port_data(port); unsigned long flags; - int chars; + unsigned int chars; /* NOTE: This overcounts somewhat. */ spin_lock_irqsave(&portdata->lock, flags); chars = portdata->outstanding_urbs * MAX_TRANSFER; spin_unlock_irqrestore(&portdata->lock, flags); - dev_dbg(&port->dev, "%s - %d\n", __func__, chars); + dev_dbg(&port->dev, "%s - %u\n", __func__, chars); return chars; } diff --git a/drivers/usb/serial/ti_usb_3410_5052.c b/drivers/usb/serial/ti_usb_3410_5052.c index 2c543c175296..34f8ed224abe 100644 --- a/drivers/usb/serial/ti_usb_3410_5052.c +++ b/drivers/usb/serial/ti_usb_3410_5052.c @@ -308,7 +308,7 @@ static void ti_close(struct usb_serial_port *port); static int ti_write(struct tty_struct *tty, struct usb_serial_port *port, const unsigned char *data, int count); static unsigned int ti_write_room(struct tty_struct *tty); -static int ti_chars_in_buffer(struct tty_struct *tty); +static unsigned int ti_chars_in_buffer(struct tty_struct *tty); static bool ti_tx_empty(struct usb_serial_port *port); static void ti_throttle(struct tty_struct *tty); static void ti_unthrottle(struct tty_struct *tty); @@ -826,18 +826,18 @@ static unsigned int ti_write_room(struct tty_struct *tty) } -static int ti_chars_in_buffer(struct tty_struct *tty) +static unsigned int ti_chars_in_buffer(struct tty_struct *tty) { struct usb_serial_port *port = tty->driver_data; struct ti_port *tport = usb_get_serial_port_data(port); - int chars = 0; + unsigned int chars; unsigned long flags; spin_lock_irqsave(&tport->tp_lock, flags); chars = kfifo_len(&port->write_fifo); spin_unlock_irqrestore(&tport->tp_lock, flags); - dev_dbg(&port->dev, "%s - returns %d\n", __func__, chars); + dev_dbg(&port->dev, "%s - returns %u\n", __func__, chars); return chars; } diff --git a/drivers/usb/serial/usb-wwan.h b/drivers/usb/serial/usb-wwan.h index 6c7c9f3309b0..519101945769 100644 --- a/drivers/usb/serial/usb-wwan.h +++ b/drivers/usb/serial/usb-wwan.h @@ -17,7 +17,7 @@ extern int usb_wwan_tiocmset(struct tty_struct *tty, unsigned int set, unsigned int clear); extern int usb_wwan_write(struct tty_struct *tty, struct usb_serial_port *port, const unsigned char *buf, int count); -extern int usb_wwan_chars_in_buffer(struct tty_struct *tty); +extern unsigned int usb_wwan_chars_in_buffer(struct tty_struct *tty); #ifdef CONFIG_PM extern int usb_wwan_suspend(struct usb_serial *serial, pm_message_t message); extern int usb_wwan_resume(struct usb_serial *serial); diff --git a/drivers/usb/serial/usb_wwan.c b/drivers/usb/serial/usb_wwan.c index 06212f08d9f9..cb01283d4d15 100644 --- a/drivers/usb/serial/usb_wwan.c +++ b/drivers/usb/serial/usb_wwan.c @@ -299,12 +299,12 @@ unsigned int usb_wwan_write_room(struct tty_struct *tty) } EXPORT_SYMBOL(usb_wwan_write_room); -int usb_wwan_chars_in_buffer(struct tty_struct *tty) +unsigned int usb_wwan_chars_in_buffer(struct tty_struct *tty) { struct usb_serial_port *port = tty->driver_data; struct usb_wwan_port_private *portdata; int i; - int data_len = 0; + unsigned int data_len = 0; struct urb *this_urb; portdata = usb_get_serial_port_data(port); @@ -316,7 +316,7 @@ int usb_wwan_chars_in_buffer(struct tty_struct *tty) if (this_urb && test_bit(i, &portdata->out_busy)) data_len += this_urb->transfer_buffer_length; } - dev_dbg(&port->dev, "%s: %d\n", __func__, data_len); + dev_dbg(&port->dev, "%s: %u\n", __func__, data_len); return data_len; } EXPORT_SYMBOL(usb_wwan_chars_in_buffer); -- cgit v1.2.3 From 3aed3af202aa2f8246d07875809b9bc07a02131b Mon Sep 17 00:00:00 2001 From: Johan Hovold Date: Wed, 19 May 2021 11:20:01 +0200 Subject: USB: serial: digi_acceleport: reduce chars_in_buffer over-reporting Due to an ancient quirk in n_tty poll implementation, the digi_acceleport driver has been reporting that its queue contains 256 (WAKEUP_CHARS) characters whenever its write URB is in use. This has not been necessary since 2003 when the line-discipline started taking the write room into account so let's return the maximum transfer size again in order to over-report a little less and incidentally fix the related debug statement. Reviewed-by: Greg Kroah-Hartman Signed-off-by: Johan Hovold --- drivers/usb/serial/digi_acceleport.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'drivers/usb') diff --git a/drivers/usb/serial/digi_acceleport.c b/drivers/usb/serial/digi_acceleport.c index 19ee8191647c..a4194b70a6fe 100644 --- a/drivers/usb/serial/digi_acceleport.c +++ b/drivers/usb/serial/digi_acceleport.c @@ -1048,8 +1048,7 @@ static unsigned int digi_chars_in_buffer(struct tty_struct *tty) if (priv->dp_write_urb_in_use) { dev_dbg(&port->dev, "digi_chars_in_buffer: port=%d, chars=%d\n", priv->dp_port_num, port->bulk_out_size - 2); - /* return(port->bulk_out_size - 2); */ - return 256; + return port->bulk_out_size - 2; } else { dev_dbg(&port->dev, "digi_chars_in_buffer: port=%d, chars=%d\n", priv->dp_port_num, priv->dp_out_buf_len); -- cgit v1.2.3 From dcbc0ae4f8fcdd4c873e7a9bac49ab84b0453813 Mon Sep 17 00:00:00 2001 From: Johan Hovold Date: Wed, 19 May 2021 11:20:02 +0200 Subject: USB: serial: digi_acceleport: add chars_in_buffer locking Both the dp_write_urb_in_use flag and dp_out_buf_len counter should be accessed while holding the driver port lock. Add the missing locking to chars_in_buffer and clean up the implementation somewhat by using a common exit path. Reviewed-by: Greg Kroah-Hartman Signed-off-by: Johan Hovold --- drivers/usb/serial/digi_acceleport.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'drivers/usb') diff --git a/drivers/usb/serial/digi_acceleport.c b/drivers/usb/serial/digi_acceleport.c index a4194b70a6fe..754c66ff0fc1 100644 --- a/drivers/usb/serial/digi_acceleport.c +++ b/drivers/usb/serial/digi_acceleport.c @@ -1044,17 +1044,19 @@ static unsigned int digi_chars_in_buffer(struct tty_struct *tty) { struct usb_serial_port *port = tty->driver_data; struct digi_port *priv = usb_get_serial_port_data(port); + unsigned long flags; + unsigned int chars; - if (priv->dp_write_urb_in_use) { - dev_dbg(&port->dev, "digi_chars_in_buffer: port=%d, chars=%d\n", - priv->dp_port_num, port->bulk_out_size - 2); - return port->bulk_out_size - 2; - } else { - dev_dbg(&port->dev, "digi_chars_in_buffer: port=%d, chars=%d\n", - priv->dp_port_num, priv->dp_out_buf_len); - return priv->dp_out_buf_len; - } + spin_lock_irqsave(&priv->dp_port_lock, flags); + if (priv->dp_write_urb_in_use) + chars = port->bulk_out_size - 2; + else + chars = priv->dp_out_buf_len; + spin_unlock_irqrestore(&priv->dp_port_lock, flags); + dev_dbg(&port->dev, "%s: port=%d, chars=%d\n", __func__, + priv->dp_port_num, chars); + return chars; } static void digi_dtr_rts(struct usb_serial_port *port, int on) -- cgit v1.2.3 From 9a8253a7c2da1d78183029a46bf04fb7beb933eb Mon Sep 17 00:00:00 2001 From: Johan Hovold Date: Wed, 19 May 2021 11:20:03 +0200 Subject: USB: serial: io_edgeport: drop buffer-callback sanity checks The driver write_room and chars_in_buffer callbacks used to incorrectly return a negative errno in case they were called while or after the port had been closed. The return value was later changed to zero by commit d76f2f4462bb ("io_edgeport: Fix various bogus returns to the tty layer") but the bogus sanity checks were left in place as were the outdated function-header comments. These callbacks will never be called for an uninitialised port so drop the unnecessary sanity checks and the outdated comments. Reviewed-by: Greg Kroah-Hartman Signed-off-by: Johan Hovold --- drivers/usb/serial/io_edgeport.c | 27 +-------------------------- 1 file changed, 1 insertion(+), 26 deletions(-) (limited to 'drivers/usb') diff --git a/drivers/usb/serial/io_edgeport.c b/drivers/usb/serial/io_edgeport.c index 1f8dff4390c7..ea4edf5eed27 100644 --- a/drivers/usb/serial/io_edgeport.c +++ b/drivers/usb/serial/io_edgeport.c @@ -1351,9 +1351,7 @@ exit_send: /***************************************************************************** * edge_write_room * this function is called by the tty driver when it wants to know how - * many bytes of data we can accept for a specific port. If successful, - * we return the amount of room that we have for this port (the txCredits) - * otherwise we return a negative error number. + * many bytes of data we can accept for a specific port. *****************************************************************************/ static unsigned int edge_write_room(struct tty_struct *tty) { @@ -1362,16 +1360,6 @@ static unsigned int edge_write_room(struct tty_struct *tty) unsigned int room; unsigned long flags; - if (edge_port == NULL) - return 0; - if (edge_port->closePending) - return 0; - - if (!edge_port->open) { - dev_dbg(&port->dev, "%s - port not opened\n", __func__); - return 0; - } - /* total of both buffers is still txCredit */ spin_lock_irqsave(&edge_port->ep_lock, flags); room = edge_port->txCredits - edge_port->txfifo.count; @@ -1387,9 +1375,6 @@ static unsigned int edge_write_room(struct tty_struct *tty) * this function is called by the tty driver when it wants to know how * many bytes of data we currently have outstanding in the port (data that * has been written, but hasn't made it out the port yet) - * If successful, we return the number of bytes left to be written in the - * system, - * Otherwise we return a negative error number. *****************************************************************************/ static unsigned int edge_chars_in_buffer(struct tty_struct *tty) { @@ -1398,16 +1383,6 @@ static unsigned int edge_chars_in_buffer(struct tty_struct *tty) unsigned int num_chars; unsigned long flags; - if (edge_port == NULL) - return 0; - if (edge_port->closePending) - return 0; - - if (!edge_port->open) { - dev_dbg(&port->dev, "%s - port not opened\n", __func__); - return 0; - } - spin_lock_irqsave(&edge_port->ep_lock, flags); num_chars = edge_port->maxTxCredits - edge_port->txCredits + edge_port->txfifo.count; -- cgit v1.2.3 From 683c5cfa5d1c050c698654e9bb13b12c8e60e174 Mon Sep 17 00:00:00 2001 From: Johan Hovold Date: Wed, 19 May 2021 11:20:04 +0200 Subject: USB: serial: mos7720: drop buffer-callback sanity checks The driver write_room and chars_in_buffer callbacks used to incorrectly return a negative errno in case they were ever called with a NULL port driver-data pointer. The return value was later changed to zero by commit 23198fda7182 ("tty: fix chars_in_buffers") but the bogus sanity checks were left in place as were the outdated function-header comments. The port driver data isn't cleared until after the port has been deregistered and all open ttys have been hung up so drop the unnecessary sanity checks and the outdated comments. Reviewed-by: Greg Kroah-Hartman Signed-off-by: Johan Hovold --- drivers/usb/serial/mos7720.c | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) (limited to 'drivers/usb') diff --git a/drivers/usb/serial/mos7720.c b/drivers/usb/serial/mos7720.c index ce41009756f3..227f43d2bd56 100644 --- a/drivers/usb/serial/mos7720.c +++ b/drivers/usb/serial/mos7720.c @@ -945,20 +945,13 @@ static int mos7720_open(struct tty_struct *tty, struct usb_serial_port *port) * this function is called by the tty driver when it wants to know how many * bytes of data we currently have outstanding in the port (data that has * been written, but hasn't made it out the port yet) - * If successful, we return the number of bytes left to be written in the - * system, - * Otherwise we return a negative error number. */ static unsigned int mos7720_chars_in_buffer(struct tty_struct *tty) { struct usb_serial_port *port = tty->driver_data; + struct moschip_port *mos7720_port = usb_get_serial_port_data(port); int i; unsigned int chars = 0; - struct moschip_port *mos7720_port; - - mos7720_port = usb_get_serial_port_data(port); - if (mos7720_port == NULL) - return 0; for (i = 0; i < NUM_URBS; ++i) { if (mos7720_port->write_urb_pool[i] && @@ -1030,20 +1023,14 @@ static void mos7720_break(struct tty_struct *tty, int break_state) * mos7720_write_room * this function is called by the tty driver when it wants to know how many * bytes of data we can accept for a specific port. - * If successful, we return the amount of room that we have for this port - * Otherwise we return a negative error number. */ static unsigned int mos7720_write_room(struct tty_struct *tty) { struct usb_serial_port *port = tty->driver_data; - struct moschip_port *mos7720_port; + struct moschip_port *mos7720_port = usb_get_serial_port_data(port); unsigned int room = 0; int i; - mos7720_port = usb_get_serial_port_data(port); - if (mos7720_port == NULL) - return 0; - /* FIXME: Locking */ for (i = 0; i < NUM_URBS; ++i) { if (mos7720_port->write_urb_pool[i] && -- cgit v1.2.3 From 661867161f63bc5cc22b0d1e8ea59a682779a0ef Mon Sep 17 00:00:00 2001 From: Johan Hovold Date: Wed, 19 May 2021 11:20:05 +0200 Subject: USB: serial: mos7840: drop buffer-callback return-value comments The driver write_room and chars_in_buffer callbacks used to incorrectly return a negative errno in case they were called with a NULL port driver-data pointer or if some other always-true sanity checks failed. The bogus sanity checks were later removed by commit ce039bd4b21f ("USB: serial: mos7840: drop paranoid port checks") and 7b2faede671a ("USB: serial: mos7840: drop port driver data accessors") but the function-header comments were never updated to match. Drop the outdated return-value comments. Reviewed-by: Greg Kroah-Hartman Signed-off-by: Johan Hovold --- drivers/usb/serial/mos7840.c | 5 ----- 1 file changed, 5 deletions(-) (limited to 'drivers/usb') diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c index b22ccbd98998..d7fe33ca73e4 100644 --- a/drivers/usb/serial/mos7840.c +++ b/drivers/usb/serial/mos7840.c @@ -730,9 +730,6 @@ err: * this function is called by the tty driver when it wants to know how many * bytes of data we currently have outstanding in the port (data that has * been written, but hasn't made it out the port yet) - * If successful, we return the number of bytes left to be written in the - * system, - * Otherwise we return zero. *****************************************************************************/ static unsigned int mos7840_chars_in_buffer(struct tty_struct *tty) @@ -814,8 +811,6 @@ static void mos7840_break(struct tty_struct *tty, int break_state) * mos7840_write_room * this function is called by the tty driver when it wants to know how many * bytes of data we can accept for a specific port. - * If successful, we return the amount of room that we have for this port - * Otherwise we return a negative error number. *****************************************************************************/ static unsigned int mos7840_write_room(struct tty_struct *tty) -- cgit v1.2.3 From 17cd3a106e9762cd97883cce884a8bfcf5a476ad Mon Sep 17 00:00:00 2001 From: Johan Hovold Date: Wed, 19 May 2021 11:20:06 +0200 Subject: USB: serial: drop irq-flags initialisations There's no need to initialise irq-flags variables before saving the interrupt state. Drop the redundant initialisations from the three drivers that got this wrong. Reviewed-by: Greg Kroah-Hartman Signed-off-by: Johan Hovold --- drivers/usb/serial/digi_acceleport.c | 13 ++++++------- drivers/usb/serial/metro-usb.c | 12 ++++++------ drivers/usb/serial/quatech2.c | 2 +- 3 files changed, 13 insertions(+), 14 deletions(-) (limited to 'drivers/usb') diff --git a/drivers/usb/serial/digi_acceleport.c b/drivers/usb/serial/digi_acceleport.c index 754c66ff0fc1..af65eb863d70 100644 --- a/drivers/usb/serial/digi_acceleport.c +++ b/drivers/usb/serial/digi_acceleport.c @@ -372,7 +372,7 @@ static int digi_write_oob_command(struct usb_serial_port *port, int len; struct usb_serial_port *oob_port = (struct usb_serial_port *)((struct digi_serial *)(usb_get_serial_data(port->serial)))->ds_oob_port; struct digi_port *oob_priv = usb_get_serial_port_data(oob_port); - unsigned long flags = 0; + unsigned long flags; dev_dbg(&port->dev, "digi_write_oob_command: TOP: port=%d, count=%d\n", @@ -430,7 +430,7 @@ static int digi_write_inb_command(struct usb_serial_port *port, int len; struct digi_port *priv = usb_get_serial_port_data(port); unsigned char *data = port->write_urb->transfer_buffer; - unsigned long flags = 0; + unsigned long flags; dev_dbg(&port->dev, "digi_write_inb_command: TOP: port=%d, count=%d\n", priv->dp_port_num, count); @@ -511,8 +511,7 @@ static int digi_set_modem_signals(struct usb_serial_port *port, struct usb_serial_port *oob_port = (struct usb_serial_port *) ((struct digi_serial *)(usb_get_serial_data(port->serial)))->ds_oob_port; struct digi_port *oob_priv = usb_get_serial_port_data(oob_port); unsigned char *data = oob_port->write_urb->transfer_buffer; - unsigned long flags = 0; - + unsigned long flags; dev_dbg(&port->dev, "digi_set_modem_signals: TOP: port=%d, modem_signals=0x%x\n", @@ -577,7 +576,7 @@ static int digi_transmit_idle(struct usb_serial_port *port, int ret; unsigned char buf[2]; struct digi_port *priv = usb_get_serial_port_data(port); - unsigned long flags = 0; + unsigned long flags; spin_lock_irqsave(&priv->dp_port_lock, flags); priv->dp_transmit_idle = 0; @@ -887,7 +886,7 @@ static int digi_write(struct tty_struct *tty, struct usb_serial_port *port, int ret, data_len, new_len; struct digi_port *priv = usb_get_serial_port_data(port); unsigned char *data = port->write_urb->transfer_buffer; - unsigned long flags = 0; + unsigned long flags; dev_dbg(&port->dev, "digi_write: TOP: port=%d, count=%d\n", priv->dp_port_num, count); @@ -1024,8 +1023,8 @@ static unsigned int digi_write_room(struct tty_struct *tty) { struct usb_serial_port *port = tty->driver_data; struct digi_port *priv = usb_get_serial_port_data(port); + unsigned long flags; unsigned int room; - unsigned long flags = 0; spin_lock_irqsave(&priv->dp_port_lock, flags); diff --git a/drivers/usb/serial/metro-usb.c b/drivers/usb/serial/metro-usb.c index f9ce9e7b9b80..30ab565e0738 100644 --- a/drivers/usb/serial/metro-usb.c +++ b/drivers/usb/serial/metro-usb.c @@ -109,9 +109,9 @@ static void metrousb_read_int_callback(struct urb *urb) struct usb_serial_port *port = urb->context; struct metrousb_private *metro_priv = usb_get_serial_port_data(port); unsigned char *data = urb->transfer_buffer; + unsigned long flags; int throttled = 0; int result = 0; - unsigned long flags = 0; dev_dbg(&port->dev, "%s\n", __func__); @@ -171,7 +171,7 @@ static int metrousb_open(struct tty_struct *tty, struct usb_serial_port *port) { struct usb_serial *serial = port->serial; struct metrousb_private *metro_priv = usb_get_serial_port_data(port); - unsigned long flags = 0; + unsigned long flags; int result = 0; /* Set the private data information for the port. */ @@ -268,7 +268,7 @@ static void metrousb_throttle(struct tty_struct *tty) { struct usb_serial_port *port = tty->driver_data; struct metrousb_private *metro_priv = usb_get_serial_port_data(port); - unsigned long flags = 0; + unsigned long flags; /* Set the private information for the port to stop reading data. */ spin_lock_irqsave(&metro_priv->lock, flags); @@ -281,7 +281,7 @@ static int metrousb_tiocmget(struct tty_struct *tty) unsigned long control_state = 0; struct usb_serial_port *port = tty->driver_data; struct metrousb_private *metro_priv = usb_get_serial_port_data(port); - unsigned long flags = 0; + unsigned long flags; spin_lock_irqsave(&metro_priv->lock, flags); control_state = metro_priv->control_state; @@ -296,7 +296,7 @@ static int metrousb_tiocmset(struct tty_struct *tty, struct usb_serial_port *port = tty->driver_data; struct usb_serial *serial = port->serial; struct metrousb_private *metro_priv = usb_get_serial_port_data(port); - unsigned long flags = 0; + unsigned long flags; unsigned long control_state = 0; dev_dbg(&port->dev, "%s - set=%d, clear=%d\n", __func__, set, clear); @@ -323,7 +323,7 @@ static void metrousb_unthrottle(struct tty_struct *tty) { struct usb_serial_port *port = tty->driver_data; struct metrousb_private *metro_priv = usb_get_serial_port_data(port); - unsigned long flags = 0; + unsigned long flags; int result = 0; /* Set the private information for the port to resume reading data. */ diff --git a/drivers/usb/serial/quatech2.c b/drivers/usb/serial/quatech2.c index 3b5f2032ecdb..d3377f3b5a23 100644 --- a/drivers/usb/serial/quatech2.c +++ b/drivers/usb/serial/quatech2.c @@ -874,7 +874,7 @@ static unsigned int qt2_write_room(struct tty_struct *tty) { struct usb_serial_port *port = tty->driver_data; struct qt2_port_private *port_priv; - unsigned long flags = 0; + unsigned long flags; unsigned int r; port_priv = usb_get_serial_port_data(port); -- cgit v1.2.3 From 8051334e901f2f7ab9fa30a15b74cdc8e58dfde2 Mon Sep 17 00:00:00 2001 From: Pho Tran Date: Thu, 10 Jun 2021 15:28:44 +0200 Subject: USB: serial: cp210x: add support for GPIOs on CP2108 Similar to some other CP210x device types, CP2108 has a number of GPIO pins that can be exposed through gpiolib. CP2108 has four serial interfaces but only one set of GPIO pins, which is modelled as a single gpio chip and registered as a child of the first interface. CP2108 has 16 GPIOs so the width of the state variables needs to be extended to 16 bits and this is also reflected in the control requests. Like CP2104, CP2108 have GPIO pins with configurable alternate functions and pins unavailable for GPIO use are determined and reported to gpiolib at probe. Signed-off-by: Pho Tran Co-developed-by: Tung Pham Signed-off-by: Tung Pham [ johan: rewrite gpio get() and set(); misc cleanups; amend commit message ] Link: https://lore.kernel.org/r/20210610132844.25495-1-johan@kernel.org Signed-off-by: Johan Hovold --- drivers/usb/serial/cp210x.c | 189 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 170 insertions(+), 19 deletions(-) (limited to 'drivers/usb') diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c index ee595d1bea0a..3d376c0b6537 100644 --- a/drivers/usb/serial/cp210x.c +++ b/drivers/usb/serial/cp210x.c @@ -247,9 +247,9 @@ struct cp210x_serial_private { #ifdef CONFIG_GPIOLIB struct gpio_chip gc; bool gpio_registered; - u8 gpio_pushpull; - u8 gpio_altfunc; - u8 gpio_input; + u16 gpio_pushpull; + u16 gpio_altfunc; + u16 gpio_input; #endif u8 partnum; speed_t min_speed; @@ -531,18 +531,72 @@ struct cp210x_single_port_config { #define CP2104_GPIO1_RXLED_MODE BIT(1) #define CP2104_GPIO2_RS485_MODE BIT(2) +struct cp210x_quad_port_state { + __le16 gpio_mode_pb0; + __le16 gpio_mode_pb1; + __le16 gpio_mode_pb2; + __le16 gpio_mode_pb3; + __le16 gpio_mode_pb4; + + __le16 gpio_lowpower_pb0; + __le16 gpio_lowpower_pb1; + __le16 gpio_lowpower_pb2; + __le16 gpio_lowpower_pb3; + __le16 gpio_lowpower_pb4; + + __le16 gpio_latch_pb0; + __le16 gpio_latch_pb1; + __le16 gpio_latch_pb2; + __le16 gpio_latch_pb3; + __le16 gpio_latch_pb4; +}; + +/* + * CP210X_VENDOR_SPECIFIC, CP210X_GET_PORTCONFIG call reads these 0x49 bytes + * on a CP2108 chip. + * + * See https://www.silabs.com/documents/public/application-notes/an978-cp210x-usb-to-uart-api-specification.pdf + */ +struct cp210x_quad_port_config { + struct cp210x_quad_port_state reset_state; + struct cp210x_quad_port_state suspend_state; + u8 ipdelay_ifc[4]; + u8 enhancedfxn_ifc[4]; + u8 enhancedfxn_device; + u8 extclkfreq[4]; +} __packed; + +#define CP2108_EF_IFC_GPIO_TXLED 0x01 +#define CP2108_EF_IFC_GPIO_RXLED 0x02 +#define CP2108_EF_IFC_GPIO_RS485 0x04 +#define CP2108_EF_IFC_GPIO_RS485_LOGIC 0x08 +#define CP2108_EF_IFC_GPIO_CLOCK 0x10 +#define CP2108_EF_IFC_DYNAMIC_SUSPEND 0x40 + /* CP2102N configuration array indices */ #define CP210X_2NCONFIG_CONFIG_VERSION_IDX 2 #define CP210X_2NCONFIG_GPIO_MODE_IDX 581 #define CP210X_2NCONFIG_GPIO_RSTLATCH_IDX 587 #define CP210X_2NCONFIG_GPIO_CONTROL_IDX 600 -/* CP210X_VENDOR_SPECIFIC, CP210X_WRITE_LATCH call writes these 0x2 bytes. */ +/* + * CP210X_VENDOR_SPECIFIC, CP210X_WRITE_LATCH call writes these 0x02 bytes + * for CP2102N, CP2103, CP2104 and CP2105. + */ struct cp210x_gpio_write { u8 mask; u8 state; }; +/* + * CP210X_VENDOR_SPECIFIC, CP210X_WRITE_LATCH call writes these 0x04 bytes + * for CP2108. + */ +struct cp210x_gpio_write16 { + __le16 mask; + __le16 state; +}; + /* * Helper to get interface number when we only have struct usb_serial. */ @@ -1414,52 +1468,84 @@ static int cp210x_gpio_get(struct gpio_chip *gc, unsigned int gpio) { struct usb_serial *serial = gpiochip_get_data(gc); struct cp210x_serial_private *priv = usb_get_serial_data(serial); - u8 req_type = REQTYPE_DEVICE_TO_HOST; + u8 req_type; + u16 mask; int result; - u8 buf; - - if (priv->partnum == CP210X_PARTNUM_CP2105) - req_type = REQTYPE_INTERFACE_TO_HOST; + int len; result = usb_autopm_get_interface(serial->interface); if (result) return result; - result = cp210x_read_vendor_block(serial, req_type, - CP210X_READ_LATCH, &buf, sizeof(buf)); + switch (priv->partnum) { + case CP210X_PARTNUM_CP2105: + req_type = REQTYPE_INTERFACE_TO_HOST; + len = 1; + break; + case CP210X_PARTNUM_CP2108: + req_type = REQTYPE_INTERFACE_TO_HOST; + len = 2; + break; + default: + req_type = REQTYPE_DEVICE_TO_HOST; + len = 1; + break; + } + + mask = 0; + result = cp210x_read_vendor_block(serial, req_type, CP210X_READ_LATCH, + &mask, len); + usb_autopm_put_interface(serial->interface); + if (result < 0) return result; - return !!(buf & BIT(gpio)); + le16_to_cpus(&mask); + + return !!(mask & BIT(gpio)); } static void cp210x_gpio_set(struct gpio_chip *gc, unsigned int gpio, int value) { struct usb_serial *serial = gpiochip_get_data(gc); struct cp210x_serial_private *priv = usb_get_serial_data(serial); + struct cp210x_gpio_write16 buf16; struct cp210x_gpio_write buf; + u16 mask, state; + u16 wIndex; int result; if (value == 1) - buf.state = BIT(gpio); + state = BIT(gpio); else - buf.state = 0; + state = 0; - buf.mask = BIT(gpio); + mask = BIT(gpio); result = usb_autopm_get_interface(serial->interface); if (result) goto out; - if (priv->partnum == CP210X_PARTNUM_CP2105) { + switch (priv->partnum) { + case CP210X_PARTNUM_CP2105: + buf.mask = (u8)mask; + buf.state = (u8)state; result = cp210x_write_vendor_block(serial, REQTYPE_HOST_TO_INTERFACE, CP210X_WRITE_LATCH, &buf, sizeof(buf)); - } else { - u16 wIndex = buf.state << 8 | buf.mask; - + break; + case CP210X_PARTNUM_CP2108: + buf16.mask = cpu_to_le16(mask); + buf16.state = cpu_to_le16(state); + result = cp210x_write_vendor_block(serial, + REQTYPE_HOST_TO_INTERFACE, + CP210X_WRITE_LATCH, &buf16, + sizeof(buf16)); + break; + default: + wIndex = state << 8 | mask; result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), CP210X_VENDOR_SPECIFIC, @@ -1467,6 +1553,7 @@ static void cp210x_gpio_set(struct gpio_chip *gc, unsigned int gpio, int value) CP210X_WRITE_LATCH, wIndex, NULL, 0, USB_CTRL_SET_TIMEOUT); + break; } usb_autopm_put_interface(serial->interface); @@ -1676,6 +1763,61 @@ static int cp2104_gpioconf_init(struct usb_serial *serial) return 0; } +static int cp2108_gpio_init(struct usb_serial *serial) +{ + struct cp210x_serial_private *priv = usb_get_serial_data(serial); + struct cp210x_quad_port_config config; + u16 gpio_latch; + int result; + u8 i; + + result = cp210x_read_vendor_block(serial, REQTYPE_DEVICE_TO_HOST, + CP210X_GET_PORTCONFIG, &config, + sizeof(config)); + if (result < 0) + return result; + + priv->gc.ngpio = 16; + priv->gpio_pushpull = le16_to_cpu(config.reset_state.gpio_mode_pb1); + gpio_latch = le16_to_cpu(config.reset_state.gpio_latch_pb1); + + /* + * Mark all pins which are not in GPIO mode. + * + * Refer to table 9.1 "GPIO Mode alternate Functions" in the datasheet: + * https://www.silabs.com/documents/public/data-sheets/cp2108-datasheet.pdf + * + * Alternate functions of GPIO0 to GPIO3 are determine by enhancedfxn_ifc[0] + * and the similarly for the other pins; enhancedfxn_ifc[1]: GPIO4 to GPIO7, + * enhancedfxn_ifc[2]: GPIO8 to GPIO11, enhancedfxn_ifc[3]: GPIO12 to GPIO15. + */ + for (i = 0; i < 4; i++) { + if (config.enhancedfxn_ifc[i] & CP2108_EF_IFC_GPIO_TXLED) + priv->gpio_altfunc |= BIT(i * 4); + if (config.enhancedfxn_ifc[i] & CP2108_EF_IFC_GPIO_RXLED) + priv->gpio_altfunc |= BIT((i * 4) + 1); + if (config.enhancedfxn_ifc[i] & CP2108_EF_IFC_GPIO_RS485) + priv->gpio_altfunc |= BIT((i * 4) + 2); + if (config.enhancedfxn_ifc[i] & CP2108_EF_IFC_GPIO_CLOCK) + priv->gpio_altfunc |= BIT((i * 4) + 3); + } + + /* + * Like CP2102N, CP2108 has also no strict input and output pin + * modes. Do the same input mode emulation as CP2102N. + */ + for (i = 0; i < priv->gc.ngpio; ++i) { + /* + * Set direction to "input" iff pin is open-drain and reset + * value is 1. + */ + if (!(priv->gpio_pushpull & BIT(i)) && (gpio_latch & BIT(i))) + priv->gpio_input |= BIT(i); + } + + return 0; +} + static int cp2102n_gpioconf_init(struct usb_serial *serial) { struct cp210x_serial_private *priv = usb_get_serial_data(serial); @@ -1780,6 +1922,15 @@ static int cp210x_gpio_init(struct usb_serial *serial) case CP210X_PARTNUM_CP2105: result = cp2105_gpioconf_init(serial); break; + case CP210X_PARTNUM_CP2108: + /* + * The GPIOs are not tied to any specific port so only register + * once for interface 0. + */ + if (cp210x_interface_num(serial) != 0) + return 0; + result = cp2108_gpio_init(serial); + break; case CP210X_PARTNUM_CP2102N_QFN28: case CP210X_PARTNUM_CP2102N_QFN24: case CP210X_PARTNUM_CP2102N_QFN20: -- cgit v1.2.3