mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-12-15 15:04:27 +08:00
USB: serial: kl5kusb105: use usb_control_msg_recv() and usb_control_msg_send()
The wrappers usb_control_msg_send/recv eliminate the need of manually allocating DMA buffers for USB messages. They also treat short reads as an error. Hence use the wrappers and remove DMA allocations. Note that short reads are now logged as -EREMOTEIO instead of the amount of data read. Signed-off-by: Himadri Pandya <himadrispandya@gmail.com> Link: https://lore.kernel.org/r/20210801203122.3515-7-himadrispandya@gmail.com [ johan: amend commit message ] Signed-off-by: Johan Hovold <johan@kernel.org>
This commit is contained in:
parent
c9129371cb
commit
71b20b34af
@ -124,16 +124,18 @@ static int klsi_105_chg_port_settings(struct usb_serial_port *port,
|
||||
{
|
||||
int rc;
|
||||
|
||||
rc = usb_control_msg(port->serial->dev,
|
||||
usb_sndctrlpipe(port->serial->dev, 0),
|
||||
KL5KUSB105A_SIO_SET_DATA,
|
||||
USB_TYPE_VENDOR | USB_DIR_OUT | USB_RECIP_INTERFACE,
|
||||
0, /* value */
|
||||
0, /* index */
|
||||
settings,
|
||||
sizeof(struct klsi_105_port_settings),
|
||||
KLSI_TIMEOUT);
|
||||
if (rc < 0)
|
||||
rc = usb_control_msg_send(port->serial->dev,
|
||||
0,
|
||||
KL5KUSB105A_SIO_SET_DATA,
|
||||
USB_TYPE_VENDOR | USB_DIR_OUT |
|
||||
USB_RECIP_INTERFACE,
|
||||
0, /* value */
|
||||
0, /* index */
|
||||
settings,
|
||||
sizeof(struct klsi_105_port_settings),
|
||||
KLSI_TIMEOUT,
|
||||
GFP_KERNEL);
|
||||
if (rc)
|
||||
dev_err(&port->dev,
|
||||
"Change port settings failed (error = %d)\n", rc);
|
||||
|
||||
@ -167,28 +169,21 @@ static int klsi_105_get_line_state(struct usb_serial_port *port,
|
||||
unsigned long *line_state_p)
|
||||
{
|
||||
int rc;
|
||||
u8 *status_buf;
|
||||
u8 status_buf[KLSI_STATUSBUF_LEN];
|
||||
__u16 status;
|
||||
|
||||
status_buf = kmalloc(KLSI_STATUSBUF_LEN, GFP_KERNEL);
|
||||
if (!status_buf)
|
||||
return -ENOMEM;
|
||||
|
||||
status_buf[0] = 0xff;
|
||||
status_buf[1] = 0xff;
|
||||
rc = usb_control_msg(port->serial->dev,
|
||||
usb_rcvctrlpipe(port->serial->dev, 0),
|
||||
KL5KUSB105A_SIO_POLL,
|
||||
USB_TYPE_VENDOR | USB_DIR_IN,
|
||||
0, /* value */
|
||||
0, /* index */
|
||||
status_buf, KLSI_STATUSBUF_LEN,
|
||||
10000
|
||||
);
|
||||
if (rc != KLSI_STATUSBUF_LEN) {
|
||||
rc = usb_control_msg_recv(port->serial->dev, 0,
|
||||
KL5KUSB105A_SIO_POLL,
|
||||
USB_TYPE_VENDOR | USB_DIR_IN,
|
||||
0, /* value */
|
||||
0, /* index */
|
||||
status_buf, KLSI_STATUSBUF_LEN,
|
||||
10000,
|
||||
GFP_KERNEL);
|
||||
if (rc) {
|
||||
dev_err(&port->dev, "reading line status failed: %d\n", rc);
|
||||
if (rc >= 0)
|
||||
rc = -EIO;
|
||||
} else {
|
||||
status = get_unaligned_le16(status_buf);
|
||||
|
||||
@ -198,7 +193,6 @@ static int klsi_105_get_line_state(struct usb_serial_port *port,
|
||||
*line_state_p = klsi_105_status2linestate(status);
|
||||
}
|
||||
|
||||
kfree(status_buf);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@ -245,7 +239,7 @@ static int klsi_105_open(struct tty_struct *tty, struct usb_serial_port *port)
|
||||
int retval = 0;
|
||||
int rc;
|
||||
unsigned long line_state;
|
||||
struct klsi_105_port_settings *cfg;
|
||||
struct klsi_105_port_settings cfg;
|
||||
unsigned long flags;
|
||||
|
||||
/* Do a defined restart:
|
||||
@ -255,27 +249,22 @@ static int klsi_105_open(struct tty_struct *tty, struct usb_serial_port *port)
|
||||
* Then read the modem line control and store values in
|
||||
* priv->line_state.
|
||||
*/
|
||||
cfg = kmalloc(sizeof(*cfg), GFP_KERNEL);
|
||||
if (!cfg)
|
||||
return -ENOMEM;
|
||||
|
||||
cfg->pktlen = 5;
|
||||
cfg->baudrate = kl5kusb105a_sio_b9600;
|
||||
cfg->databits = kl5kusb105a_dtb_8;
|
||||
cfg->unknown1 = 0;
|
||||
cfg->unknown2 = 1;
|
||||
klsi_105_chg_port_settings(port, cfg);
|
||||
cfg.pktlen = 5;
|
||||
cfg.baudrate = kl5kusb105a_sio_b9600;
|
||||
cfg.databits = kl5kusb105a_dtb_8;
|
||||
cfg.unknown1 = 0;
|
||||
cfg.unknown2 = 1;
|
||||
klsi_105_chg_port_settings(port, &cfg);
|
||||
|
||||
spin_lock_irqsave(&priv->lock, flags);
|
||||
priv->cfg.pktlen = cfg->pktlen;
|
||||
priv->cfg.baudrate = cfg->baudrate;
|
||||
priv->cfg.databits = cfg->databits;
|
||||
priv->cfg.unknown1 = cfg->unknown1;
|
||||
priv->cfg.unknown2 = cfg->unknown2;
|
||||
priv->cfg.pktlen = cfg.pktlen;
|
||||
priv->cfg.baudrate = cfg.baudrate;
|
||||
priv->cfg.databits = cfg.databits;
|
||||
priv->cfg.unknown1 = cfg.unknown1;
|
||||
priv->cfg.unknown2 = cfg.unknown2;
|
||||
spin_unlock_irqrestore(&priv->lock, flags);
|
||||
|
||||
kfree(cfg);
|
||||
|
||||
/* READ_ON and urb submission */
|
||||
rc = usb_serial_generic_open(tty, port);
|
||||
if (rc)
|
||||
|
Loading…
Reference in New Issue
Block a user