Skip to content

Commit cde1e61

Browse files
committed
Merge tag 'usb-serial-6.14-rc1' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/johan/usb-serial into usb-next
Merge usb-serial updates from Johan: USB-serial updates for 6.14-rc1 Here are the USB-serial updates for 6.14-rc1, including: - fix a long-standing NULL-deref issue in quatech2 - add support for hardware flow control to ch341 Included is also a related clean up. All have been in linux-next with no reported issues. * tag 'usb-serial-6.14-rc1' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/johan/usb-serial: USB: serial: quatech2: fix null-ptr-deref in qt2_process_read_urb() USB: serial: ch341: use fix-width types consistently USB: serial: ch341: add hardware flow control RTS/CTS
2 parents ba39e42 + 575a5ad commit cde1e61

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

drivers/usb/serial/ch341.c

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
#define CH341_REG_DIVISOR 0x13
6464
#define CH341_REG_LCR 0x18
6565
#define CH341_REG_LCR2 0x25
66+
#define CH341_REG_FLOW_CTL 0x27
6667

6768
#define CH341_NBREAK_BITS 0x01
6869

@@ -77,6 +78,9 @@
7778
#define CH341_LCR_CS6 0x01
7879
#define CH341_LCR_CS5 0x00
7980

81+
#define CH341_FLOW_CTL_NONE 0x00
82+
#define CH341_FLOW_CTL_RTSCTS 0x01
83+
8084
#define CH341_QUIRK_LIMITED_PRESCALER BIT(0)
8185
#define CH341_QUIRK_SIMULATE_BREAK BIT(1)
8286

@@ -478,6 +482,28 @@ static int ch341_open(struct tty_struct *tty, struct usb_serial_port *port)
478482
return r;
479483
}
480484

485+
static void ch341_set_flow_control(struct tty_struct *tty,
486+
struct usb_serial_port *port,
487+
const struct ktermios *old_termios)
488+
{
489+
u16 flow_ctl;
490+
int r;
491+
492+
if (C_CRTSCTS(tty))
493+
flow_ctl = CH341_FLOW_CTL_RTSCTS;
494+
else
495+
flow_ctl = CH341_FLOW_CTL_NONE;
496+
497+
r = ch341_control_out(port->serial->dev,
498+
CH341_REQ_WRITE_REG,
499+
(CH341_REG_FLOW_CTL << 8) | CH341_REG_FLOW_CTL,
500+
(flow_ctl << 8) | flow_ctl);
501+
if (r < 0 && old_termios) {
502+
tty->termios.c_cflag &= ~CRTSCTS;
503+
tty->termios.c_cflag |= (old_termios->c_cflag & CRTSCTS);
504+
}
505+
}
506+
481507
/* Old_termios contains the original termios settings and
482508
* tty->termios contains the new setting to be used.
483509
*/
@@ -546,6 +572,8 @@ static void ch341_set_termios(struct tty_struct *tty,
546572
spin_unlock_irqrestore(&priv->lock, flags);
547573

548574
ch341_set_handshake(port->serial->dev, priv->mcr);
575+
576+
ch341_set_flow_control(tty, port, old_termios);
549577
}
550578

551579
/*
@@ -632,13 +660,12 @@ static int ch341_simulate_break(struct tty_struct *tty, int break_state)
632660

633661
static int ch341_break_ctl(struct tty_struct *tty, int break_state)
634662
{
635-
const uint16_t ch341_break_reg =
636-
((uint16_t) CH341_REG_LCR << 8) | CH341_REG_BREAK;
663+
const u16 ch341_break_reg = (CH341_REG_LCR << 8) | CH341_REG_BREAK;
637664
struct usb_serial_port *port = tty->driver_data;
638665
struct ch341_private *priv = usb_get_serial_port_data(port);
666+
u16 reg_contents;
667+
u8 break_reg[2];
639668
int r;
640-
uint16_t reg_contents;
641-
uint8_t break_reg[2];
642669

643670
if (priv->quirks & CH341_QUIRK_SIMULATE_BREAK)
644671
return ch341_simulate_break(tty, break_state);

drivers/usb/serial/quatech2.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ static void qt2_process_read_urb(struct urb *urb)
503503

504504
newport = *(ch + 3);
505505

506-
if (newport > serial->num_ports) {
506+
if (newport >= serial->num_ports) {
507507
dev_err(&port->dev,
508508
"%s - port change to invalid port: %i\n",
509509
__func__, newport);

0 commit comments

Comments
 (0)