Skip to content

Commit 4082772

Browse files
jan-kiszkajhovold
authored andcommitted
USB: serial: pl2303: account for deficits of clones
There are apparently incomplete clones of the HXD type chip in use. Those return -EPIPE on GET_LINE_REQUEST and BREAK_REQUEST. Avoid flooding the kernel log with those errors. Detect them during startup and then use the line_settings cache instead of GET_LINE_REQUEST. Signal missing break support via -ENOTTY. Signed-off-by: Jan Kiszka <[email protected]> [ johan: fix macro prefix, drop oom error message ] Signed-off-by: Johan Hovold <[email protected]>
1 parent 59b723c commit 4082772

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

drivers/usb/serial/pl2303.c

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#define PL2303_QUIRK_UART_STATE_IDX0 BIT(0)
3232
#define PL2303_QUIRK_LEGACY BIT(1)
3333
#define PL2303_QUIRK_ENDPOINT_HACK BIT(2)
34+
#define PL2303_QUIRK_NO_BREAK_GETLINE BIT(3)
3435

3536
static const struct usb_device_id id_table[] = {
3637
{ USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID),
@@ -467,6 +468,25 @@ static int pl2303_detect_type(struct usb_serial *serial)
467468
return -ENODEV;
468469
}
469470

471+
static bool pl2303_is_hxd_clone(struct usb_serial *serial)
472+
{
473+
struct usb_device *udev = serial->dev;
474+
unsigned char *buf;
475+
int ret;
476+
477+
buf = kmalloc(7, GFP_KERNEL);
478+
if (!buf)
479+
return false;
480+
481+
ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
482+
GET_LINE_REQUEST, GET_LINE_REQUEST_TYPE,
483+
0, 0, buf, 7, 100);
484+
485+
kfree(buf);
486+
487+
return ret == -EPIPE;
488+
}
489+
470490
static int pl2303_startup(struct usb_serial *serial)
471491
{
472492
struct pl2303_serial_private *spriv;
@@ -489,6 +509,9 @@ static int pl2303_startup(struct usb_serial *serial)
489509
spriv->quirks = (unsigned long)usb_get_serial_data(serial);
490510
spriv->quirks |= spriv->type->quirks;
491511

512+
if (type == TYPE_HXD && pl2303_is_hxd_clone(serial))
513+
spriv->quirks |= PL2303_QUIRK_NO_BREAK_GETLINE;
514+
492515
usb_set_serial_data(serial, spriv);
493516

494517
if (type != TYPE_HXN) {
@@ -725,9 +748,18 @@ static void pl2303_encode_baud_rate(struct tty_struct *tty,
725748
static int pl2303_get_line_request(struct usb_serial_port *port,
726749
unsigned char buf[7])
727750
{
728-
struct usb_device *udev = port->serial->dev;
751+
struct usb_serial *serial = port->serial;
752+
struct pl2303_serial_private *spriv = usb_get_serial_data(serial);
753+
struct usb_device *udev = serial->dev;
729754
int ret;
730755

756+
if (spriv->quirks & PL2303_QUIRK_NO_BREAK_GETLINE) {
757+
struct pl2303_private *priv = usb_get_serial_port_data(port);
758+
759+
memcpy(buf, priv->line_settings, 7);
760+
return 0;
761+
}
762+
731763
ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
732764
GET_LINE_REQUEST, GET_LINE_REQUEST_TYPE,
733765
0, 0, buf, 7, 100);
@@ -1064,9 +1096,13 @@ static int pl2303_carrier_raised(struct usb_serial_port *port)
10641096
static int pl2303_set_break(struct usb_serial_port *port, bool enable)
10651097
{
10661098
struct usb_serial *serial = port->serial;
1099+
struct pl2303_serial_private *spriv = usb_get_serial_data(serial);
10671100
u16 state;
10681101
int result;
10691102

1103+
if (spriv->quirks & PL2303_QUIRK_NO_BREAK_GETLINE)
1104+
return -ENOTTY;
1105+
10701106
if (enable)
10711107
state = BREAK_ON;
10721108
else

0 commit comments

Comments
 (0)