Skip to content

Commit c47055e

Browse files
committed
Merge tag 'usb-serial-5.16-rc1' of https://git.kernel.org/pub/scm/linux/kernel/git/johan/usb-serial into usb-next
Johan writes: USB-serial updates for 5.16-rc1 Here are the USB-serial updates for 5.16-rc1, including: - conversions of usb_control_msg() calls to use the new wrappers where appropriate - fix of the keyspan probe error handling after a low-order allocation failure (e.g. due to fault injection) - allow hung up ports to be runtime suspended Included are also some related clean ups. All have been in linux-next with no reported issues. * tag 'usb-serial-5.16-rc1' of https://git.kernel.org/pub/scm/linux/kernel/git/johan/usb-serial: USB: serial: keyspan: fix memleak on probe errors USB: serial: cp210x: use usb_control_msg_recv() and usb_control_msg_send() USB: serial: ch314: use usb_control_msg_recv() USB: serial: kl5kusb105: drop line-status helper USB: serial: kl5kusb105: simplify line-status handling USB: serial: kl5kusb105: clean up line-status handling USB: serial: kl5kusb105: use usb_control_msg_recv() and usb_control_msg_send() USB: serial: keyspan_pda: use usb_control_msg_recv() USB: serial: ftdi_sio: use usb_control_msg_recv() USB: serial: f81232: use usb_control_msg_recv() and usb_control_msg_send() USB: serial: allow hung up ports to be suspended USB: serial: clean up core error labels
2 parents 79a4479 + 910c996 commit c47055e

File tree

8 files changed

+215
-384
lines changed

8 files changed

+215
-384
lines changed

drivers/usb/serial/ch341.c

Lines changed: 26 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -131,17 +131,11 @@ static int ch341_control_in(struct usb_device *dev,
131131
dev_dbg(&dev->dev, "%s - (%02x,%04x,%04x,%u)\n", __func__,
132132
request, value, index, bufsize);
133133

134-
r = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), request,
135-
USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
136-
value, index, buf, bufsize, DEFAULT_TIMEOUT);
137-
if (r < (int)bufsize) {
138-
if (r >= 0) {
139-
dev_err(&dev->dev,
140-
"short control message received (%d < %u)\n",
141-
r, bufsize);
142-
r = -EIO;
143-
}
144-
134+
r = usb_control_msg_recv(dev, 0, request,
135+
USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
136+
value, index, buf, bufsize, DEFAULT_TIMEOUT,
137+
GFP_KERNEL);
138+
if (r) {
145139
dev_err(&dev->dev, "failed to receive control message: %d\n",
146140
r);
147141
return r;
@@ -287,56 +281,48 @@ static int ch341_set_handshake(struct usb_device *dev, u8 control)
287281
static int ch341_get_status(struct usb_device *dev, struct ch341_private *priv)
288282
{
289283
const unsigned int size = 2;
290-
char *buffer;
284+
u8 buffer[2];
291285
int r;
292286
unsigned long flags;
293287

294-
buffer = kmalloc(size, GFP_KERNEL);
295-
if (!buffer)
296-
return -ENOMEM;
297-
298288
r = ch341_control_in(dev, CH341_REQ_READ_REG, 0x0706, 0, buffer, size);
299-
if (r < 0)
300-
goto out;
289+
if (r)
290+
return r;
301291

302292
spin_lock_irqsave(&priv->lock, flags);
303293
priv->msr = (~(*buffer)) & CH341_BITS_MODEM_STAT;
304294
spin_unlock_irqrestore(&priv->lock, flags);
305295

306-
out: kfree(buffer);
307-
return r;
296+
return 0;
308297
}
309298

310299
/* -------------------------------------------------------------------------- */
311300

312301
static int ch341_configure(struct usb_device *dev, struct ch341_private *priv)
313302
{
314303
const unsigned int size = 2;
315-
char *buffer;
304+
u8 buffer[2];
316305
int r;
317306

318-
buffer = kmalloc(size, GFP_KERNEL);
319-
if (!buffer)
320-
return -ENOMEM;
321-
322307
/* expect two bytes 0x27 0x00 */
323308
r = ch341_control_in(dev, CH341_REQ_READ_VERSION, 0, 0, buffer, size);
324-
if (r < 0)
325-
goto out;
309+
if (r)
310+
return r;
326311
dev_dbg(&dev->dev, "Chip version: 0x%02x\n", buffer[0]);
327312

328313
r = ch341_control_out(dev, CH341_REQ_SERIAL_INIT, 0, 0);
329314
if (r < 0)
330-
goto out;
315+
return r;
331316

332317
r = ch341_set_baudrate_lcr(dev, priv, priv->baud_rate, priv->lcr);
333318
if (r < 0)
334-
goto out;
319+
return r;
335320

336321
r = ch341_set_handshake(dev, priv->mcr);
322+
if (r < 0)
323+
return r;
337324

338-
out: kfree(buffer);
339-
return r;
325+
return 0;
340326
}
341327

342328
static int ch341_detect_quirks(struct usb_serial_port *port)
@@ -345,40 +331,27 @@ static int ch341_detect_quirks(struct usb_serial_port *port)
345331
struct usb_device *udev = port->serial->dev;
346332
const unsigned int size = 2;
347333
unsigned long quirks = 0;
348-
char *buffer;
334+
u8 buffer[2];
349335
int r;
350336

351-
buffer = kmalloc(size, GFP_KERNEL);
352-
if (!buffer)
353-
return -ENOMEM;
354-
355337
/*
356338
* A subset of CH34x devices does not support all features. The
357339
* prescaler is limited and there is no support for sending a RS232
358340
* break condition. A read failure when trying to set up the latter is
359341
* used to detect these devices.
360342
*/
361-
r = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), CH341_REQ_READ_REG,
362-
USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
363-
CH341_REG_BREAK, 0, buffer, size, DEFAULT_TIMEOUT);
343+
r = usb_control_msg_recv(udev, 0, CH341_REQ_READ_REG,
344+
USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
345+
CH341_REG_BREAK, 0, &buffer, size,
346+
DEFAULT_TIMEOUT, GFP_KERNEL);
364347
if (r == -EPIPE) {
365348
dev_info(&port->dev, "break control not supported, using simulated break\n");
366349
quirks = CH341_QUIRK_LIMITED_PRESCALER | CH341_QUIRK_SIMULATE_BREAK;
367350
r = 0;
368-
goto out;
369-
}
370-
371-
if (r != size) {
372-
if (r >= 0)
373-
r = -EIO;
351+
} else if (r) {
374352
dev_err(&port->dev, "failed to read break control: %d\n", r);
375-
goto out;
376353
}
377354

378-
r = 0;
379-
out:
380-
kfree(buffer);
381-
382355
if (quirks) {
383356
dev_dbg(&port->dev, "enabling quirk flags: 0x%02lx\n", quirks);
384357
priv->quirks |= quirks;
@@ -647,23 +620,19 @@ static void ch341_break_ctl(struct tty_struct *tty, int break_state)
647620
struct ch341_private *priv = usb_get_serial_port_data(port);
648621
int r;
649622
uint16_t reg_contents;
650-
uint8_t *break_reg;
623+
uint8_t break_reg[2];
651624

652625
if (priv->quirks & CH341_QUIRK_SIMULATE_BREAK) {
653626
ch341_simulate_break(tty, break_state);
654627
return;
655628
}
656629

657-
break_reg = kmalloc(2, GFP_KERNEL);
658-
if (!break_reg)
659-
return;
660-
661630
r = ch341_control_in(port->serial->dev, CH341_REQ_READ_REG,
662631
ch341_break_reg, 0, break_reg, 2);
663-
if (r < 0) {
632+
if (r) {
664633
dev_err(&port->dev, "%s - USB control read error (%d)\n",
665634
__func__, r);
666-
goto out;
635+
return;
667636
}
668637
dev_dbg(&port->dev, "%s - initial ch341 break register contents - reg1: %x, reg2: %x\n",
669638
__func__, break_reg[0], break_reg[1]);
@@ -684,8 +653,6 @@ static void ch341_break_ctl(struct tty_struct *tty, int break_state)
684653
if (r < 0)
685654
dev_err(&port->dev, "%s - USB control write error (%d)\n",
686655
__func__, r);
687-
out:
688-
kfree(break_reg);
689656
}
690657

691658
static int ch341_tiocmset(struct tty_struct *tty,

drivers/usb/serial/cp210x.c

Lines changed: 31 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -631,30 +631,20 @@ static int cp210x_read_reg_block(struct usb_serial_port *port, u8 req,
631631
{
632632
struct usb_serial *serial = port->serial;
633633
struct cp210x_port_private *port_priv = usb_get_serial_port_data(port);
634-
void *dmabuf;
635634
int result;
636635

637-
dmabuf = kmalloc(bufsize, GFP_KERNEL);
638-
if (!dmabuf)
639-
return -ENOMEM;
640636

641-
result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
642-
req, REQTYPE_INTERFACE_TO_HOST, 0,
643-
port_priv->bInterfaceNumber, dmabuf, bufsize,
644-
USB_CTRL_GET_TIMEOUT);
645-
if (result == bufsize) {
646-
memcpy(buf, dmabuf, bufsize);
647-
result = 0;
648-
} else {
637+
result = usb_control_msg_recv(serial->dev, 0, req,
638+
REQTYPE_INTERFACE_TO_HOST, 0,
639+
port_priv->bInterfaceNumber, buf, bufsize,
640+
USB_CTRL_SET_TIMEOUT, GFP_KERNEL);
641+
if (result) {
649642
dev_err(&port->dev, "failed get req 0x%x size %d status: %d\n",
650643
req, bufsize, result);
651-
if (result >= 0)
652-
result = -EIO;
644+
return result;
653645
}
654646

655-
kfree(dmabuf);
656-
657-
return result;
647+
return 0;
658648
}
659649

660650
/*
@@ -672,31 +662,19 @@ static int cp210x_read_u8_reg(struct usb_serial_port *port, u8 req, u8 *val)
672662
static int cp210x_read_vendor_block(struct usb_serial *serial, u8 type, u16 val,
673663
void *buf, int bufsize)
674664
{
675-
void *dmabuf;
676665
int result;
677666

678-
dmabuf = kmalloc(bufsize, GFP_KERNEL);
679-
if (!dmabuf)
680-
return -ENOMEM;
681-
682-
result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
683-
CP210X_VENDOR_SPECIFIC, type, val,
684-
cp210x_interface_num(serial), dmabuf, bufsize,
685-
USB_CTRL_GET_TIMEOUT);
686-
if (result == bufsize) {
687-
memcpy(buf, dmabuf, bufsize);
688-
result = 0;
689-
} else {
667+
result = usb_control_msg_recv(serial->dev, 0, CP210X_VENDOR_SPECIFIC,
668+
type, val, cp210x_interface_num(serial), buf, bufsize,
669+
USB_CTRL_GET_TIMEOUT, GFP_KERNEL);
670+
if (result) {
690671
dev_err(&serial->interface->dev,
691672
"failed to get vendor val 0x%04x size %d: %d\n", val,
692673
bufsize, result);
693-
if (result >= 0)
694-
result = -EIO;
674+
return result;
695675
}
696676

697-
kfree(dmabuf);
698-
699-
return result;
677+
return 0;
700678
}
701679

702680
/*
@@ -730,21 +708,13 @@ static int cp210x_write_reg_block(struct usb_serial_port *port, u8 req,
730708
{
731709
struct usb_serial *serial = port->serial;
732710
struct cp210x_port_private *port_priv = usb_get_serial_port_data(port);
733-
void *dmabuf;
734711
int result;
735712

736-
dmabuf = kmemdup(buf, bufsize, GFP_KERNEL);
737-
if (!dmabuf)
738-
return -ENOMEM;
739-
740-
result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
741-
req, REQTYPE_HOST_TO_INTERFACE, 0,
742-
port_priv->bInterfaceNumber, dmabuf, bufsize,
743-
USB_CTRL_SET_TIMEOUT);
744-
745-
kfree(dmabuf);
746-
747-
if (result < 0) {
713+
result = usb_control_msg_send(serial->dev, 0, req,
714+
REQTYPE_HOST_TO_INTERFACE, 0,
715+
port_priv->bInterfaceNumber, buf, bufsize,
716+
USB_CTRL_SET_TIMEOUT, GFP_KERNEL);
717+
if (result) {
748718
dev_err(&port->dev, "failed set req 0x%x size %d status: %d\n",
749719
req, bufsize, result);
750720
return result;
@@ -773,21 +743,12 @@ static int cp210x_write_u32_reg(struct usb_serial_port *port, u8 req, u32 val)
773743
static int cp210x_write_vendor_block(struct usb_serial *serial, u8 type,
774744
u16 val, void *buf, int bufsize)
775745
{
776-
void *dmabuf;
777746
int result;
778747

779-
dmabuf = kmemdup(buf, bufsize, GFP_KERNEL);
780-
if (!dmabuf)
781-
return -ENOMEM;
782-
783-
result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
784-
CP210X_VENDOR_SPECIFIC, type, val,
785-
cp210x_interface_num(serial), dmabuf, bufsize,
786-
USB_CTRL_SET_TIMEOUT);
787-
788-
kfree(dmabuf);
789-
790-
if (result < 0) {
748+
result = usb_control_msg_send(serial->dev, 0, CP210X_VENDOR_SPECIFIC,
749+
type, val, cp210x_interface_num(serial), buf, bufsize,
750+
USB_CTRL_SET_TIMEOUT, GFP_KERNEL);
751+
if (result) {
791752
dev_err(&serial->interface->dev,
792753
"failed to set vendor val 0x%04x size %d: %d\n", val,
793754
bufsize, result);
@@ -952,29 +913,21 @@ static int cp210x_get_tx_queue_byte_count(struct usb_serial_port *port,
952913
{
953914
struct usb_serial *serial = port->serial;
954915
struct cp210x_port_private *port_priv = usb_get_serial_port_data(port);
955-
struct cp210x_comm_status *sts;
916+
struct cp210x_comm_status sts;
956917
int result;
957918

958-
sts = kmalloc(sizeof(*sts), GFP_KERNEL);
959-
if (!sts)
960-
return -ENOMEM;
961-
962-
result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
963-
CP210X_GET_COMM_STATUS, REQTYPE_INTERFACE_TO_HOST,
964-
0, port_priv->bInterfaceNumber, sts, sizeof(*sts),
965-
USB_CTRL_GET_TIMEOUT);
966-
if (result == sizeof(*sts)) {
967-
*count = le32_to_cpu(sts->ulAmountInOutQueue);
968-
result = 0;
969-
} else {
919+
result = usb_control_msg_recv(serial->dev, 0, CP210X_GET_COMM_STATUS,
920+
REQTYPE_INTERFACE_TO_HOST, 0,
921+
port_priv->bInterfaceNumber, &sts, sizeof(sts),
922+
USB_CTRL_GET_TIMEOUT, GFP_KERNEL);
923+
if (result) {
970924
dev_err(&port->dev, "failed to get comm status: %d\n", result);
971-
if (result >= 0)
972-
result = -EIO;
925+
return result;
973926
}
974927

975-
kfree(sts);
928+
*count = le32_to_cpu(sts.ulAmountInOutQueue);
976929

977-
return result;
930+
return 0;
978931
}
979932

980933
static bool cp210x_tx_empty(struct usb_serial_port *port)

0 commit comments

Comments
 (0)