提交 af2ac1a0 编写于 作者: P Pete Zaitcev 提交者: Greg Kroah-Hartman

USB: serial mct_usb232: move DMA buffers to heap

My distro kernel (Fedora Rawhide) started throwing warnings from DMA API
checker, so I have no choice but band-aid it quick. There's no attempt
to reuse DMA buffers. Control messages are only sent rarely anyway.
Signed-off-by: NPete Zaitcev <zaitcev@redhat.com>
Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
上级 4fdb31d9
...@@ -75,6 +75,7 @@ ...@@ -75,6 +75,7 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/spinlock.h> #include <linux/spinlock.h>
#include <linux/uaccess.h> #include <linux/uaccess.h>
#include <asm/unaligned.h>
#include <linux/usb.h> #include <linux/usb.h>
#include <linux/usb/serial.h> #include <linux/usb/serial.h>
#include "mct_u232.h" #include "mct_u232.h"
...@@ -231,19 +232,22 @@ static int mct_u232_calculate_baud_rate(struct usb_serial *serial, ...@@ -231,19 +232,22 @@ static int mct_u232_calculate_baud_rate(struct usb_serial *serial,
static int mct_u232_set_baud_rate(struct tty_struct *tty, static int mct_u232_set_baud_rate(struct tty_struct *tty,
struct usb_serial *serial, struct usb_serial_port *port, speed_t value) struct usb_serial *serial, struct usb_serial_port *port, speed_t value)
{ {
__le32 divisor; unsigned int divisor;
int rc; int rc;
unsigned char zero_byte = 0; unsigned char *buf;
unsigned char cts_enable_byte = 0; unsigned char cts_enable_byte = 0;
speed_t speed; speed_t speed;
divisor = cpu_to_le32(mct_u232_calculate_baud_rate(serial, value, buf = kmalloc(MCT_U232_MAX_SIZE, GFP_KERNEL);
&speed)); if (buf == NULL)
return -ENOMEM;
divisor = mct_u232_calculate_baud_rate(serial, value, &speed);
put_unaligned_le32(cpu_to_le32(divisor), buf);
rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
MCT_U232_SET_BAUD_RATE_REQUEST, MCT_U232_SET_BAUD_RATE_REQUEST,
MCT_U232_SET_REQUEST_TYPE, MCT_U232_SET_REQUEST_TYPE,
0, 0, &divisor, MCT_U232_SET_BAUD_RATE_SIZE, 0, 0, buf, MCT_U232_SET_BAUD_RATE_SIZE,
WDR_TIMEOUT); WDR_TIMEOUT);
if (rc < 0) /*FIXME: What value speed results */ if (rc < 0) /*FIXME: What value speed results */
dev_err(&port->dev, "Set BAUD RATE %d failed (error = %d)\n", dev_err(&port->dev, "Set BAUD RATE %d failed (error = %d)\n",
...@@ -269,10 +273,11 @@ static int mct_u232_set_baud_rate(struct tty_struct *tty, ...@@ -269,10 +273,11 @@ static int mct_u232_set_baud_rate(struct tty_struct *tty,
a device which is not asserting 'CTS'. a device which is not asserting 'CTS'.
*/ */
buf[0] = 0;
rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
MCT_U232_SET_UNKNOWN1_REQUEST, MCT_U232_SET_UNKNOWN1_REQUEST,
MCT_U232_SET_REQUEST_TYPE, MCT_U232_SET_REQUEST_TYPE,
0, 0, &zero_byte, MCT_U232_SET_UNKNOWN1_SIZE, 0, 0, buf, MCT_U232_SET_UNKNOWN1_SIZE,
WDR_TIMEOUT); WDR_TIMEOUT);
if (rc < 0) if (rc < 0)
dev_err(&port->dev, "Sending USB device request code %d " dev_err(&port->dev, "Sending USB device request code %d "
...@@ -284,30 +289,40 @@ static int mct_u232_set_baud_rate(struct tty_struct *tty, ...@@ -284,30 +289,40 @@ static int mct_u232_set_baud_rate(struct tty_struct *tty,
dbg("set_baud_rate: send second control message, data = %02X", dbg("set_baud_rate: send second control message, data = %02X",
cts_enable_byte); cts_enable_byte);
buf[0] = cts_enable_byte;
rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
MCT_U232_SET_CTS_REQUEST, MCT_U232_SET_CTS_REQUEST,
MCT_U232_SET_REQUEST_TYPE, MCT_U232_SET_REQUEST_TYPE,
0, 0, &cts_enable_byte, MCT_U232_SET_CTS_SIZE, 0, 0, buf, MCT_U232_SET_CTS_SIZE,
WDR_TIMEOUT); WDR_TIMEOUT);
if (rc < 0) if (rc < 0)
dev_err(&port->dev, "Sending USB device request code %d " dev_err(&port->dev, "Sending USB device request code %d "
"failed (error = %d)\n", MCT_U232_SET_CTS_REQUEST, rc); "failed (error = %d)\n", MCT_U232_SET_CTS_REQUEST, rc);
kfree(buf);
return rc; return rc;
} /* mct_u232_set_baud_rate */ } /* mct_u232_set_baud_rate */
static int mct_u232_set_line_ctrl(struct usb_serial *serial, unsigned char lcr) static int mct_u232_set_line_ctrl(struct usb_serial *serial, unsigned char lcr)
{ {
int rc; int rc;
unsigned char *buf;
buf = kmalloc(MCT_U232_MAX_SIZE, GFP_KERNEL);
if (buf == NULL)
return -ENOMEM;
buf[0] = lcr;
rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
MCT_U232_SET_LINE_CTRL_REQUEST, MCT_U232_SET_LINE_CTRL_REQUEST,
MCT_U232_SET_REQUEST_TYPE, MCT_U232_SET_REQUEST_TYPE,
0, 0, &lcr, MCT_U232_SET_LINE_CTRL_SIZE, 0, 0, buf, MCT_U232_SET_LINE_CTRL_SIZE,
WDR_TIMEOUT); WDR_TIMEOUT);
if (rc < 0) if (rc < 0)
dev_err(&serial->dev->dev, dev_err(&serial->dev->dev,
"Set LINE CTRL 0x%x failed (error = %d)\n", lcr, rc); "Set LINE CTRL 0x%x failed (error = %d)\n", lcr, rc);
dbg("set_line_ctrl: 0x%x", lcr); dbg("set_line_ctrl: 0x%x", lcr);
kfree(buf);
return rc; return rc;
} /* mct_u232_set_line_ctrl */ } /* mct_u232_set_line_ctrl */
...@@ -315,23 +330,31 @@ static int mct_u232_set_modem_ctrl(struct usb_serial *serial, ...@@ -315,23 +330,31 @@ static int mct_u232_set_modem_ctrl(struct usb_serial *serial,
unsigned int control_state) unsigned int control_state)
{ {
int rc; int rc;
unsigned char mcr = MCT_U232_MCR_NONE; unsigned char mcr;
unsigned char *buf;
buf = kmalloc(MCT_U232_MAX_SIZE, GFP_KERNEL);
if (buf == NULL)
return -ENOMEM;
mcr = MCT_U232_MCR_NONE;
if (control_state & TIOCM_DTR) if (control_state & TIOCM_DTR)
mcr |= MCT_U232_MCR_DTR; mcr |= MCT_U232_MCR_DTR;
if (control_state & TIOCM_RTS) if (control_state & TIOCM_RTS)
mcr |= MCT_U232_MCR_RTS; mcr |= MCT_U232_MCR_RTS;
buf[0] = mcr;
rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
MCT_U232_SET_MODEM_CTRL_REQUEST, MCT_U232_SET_MODEM_CTRL_REQUEST,
MCT_U232_SET_REQUEST_TYPE, MCT_U232_SET_REQUEST_TYPE,
0, 0, &mcr, MCT_U232_SET_MODEM_CTRL_SIZE, 0, 0, buf, MCT_U232_SET_MODEM_CTRL_SIZE,
WDR_TIMEOUT); WDR_TIMEOUT);
if (rc < 0) if (rc < 0)
dev_err(&serial->dev->dev, dev_err(&serial->dev->dev,
"Set MODEM CTRL 0x%x failed (error = %d)\n", mcr, rc); "Set MODEM CTRL 0x%x failed (error = %d)\n", mcr, rc);
dbg("set_modem_ctrl: state=0x%x ==> mcr=0x%x", control_state, mcr); dbg("set_modem_ctrl: state=0x%x ==> mcr=0x%x", control_state, mcr);
kfree(buf);
return rc; return rc;
} /* mct_u232_set_modem_ctrl */ } /* mct_u232_set_modem_ctrl */
...@@ -339,17 +362,27 @@ static int mct_u232_get_modem_stat(struct usb_serial *serial, ...@@ -339,17 +362,27 @@ static int mct_u232_get_modem_stat(struct usb_serial *serial,
unsigned char *msr) unsigned char *msr)
{ {
int rc; int rc;
unsigned char *buf;
buf = kmalloc(MCT_U232_MAX_SIZE, GFP_KERNEL);
if (buf == NULL) {
*msr = 0;
return -ENOMEM;
}
rc = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), rc = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
MCT_U232_GET_MODEM_STAT_REQUEST, MCT_U232_GET_MODEM_STAT_REQUEST,
MCT_U232_GET_REQUEST_TYPE, MCT_U232_GET_REQUEST_TYPE,
0, 0, msr, MCT_U232_GET_MODEM_STAT_SIZE, 0, 0, buf, MCT_U232_GET_MODEM_STAT_SIZE,
WDR_TIMEOUT); WDR_TIMEOUT);
if (rc < 0) { if (rc < 0) {
dev_err(&serial->dev->dev, dev_err(&serial->dev->dev,
"Get MODEM STATus failed (error = %d)\n", rc); "Get MODEM STATus failed (error = %d)\n", rc);
*msr = 0; *msr = 0;
} else {
*msr = buf[0];
} }
dbg("get_modem_stat: 0x%x", *msr); dbg("get_modem_stat: 0x%x", *msr);
kfree(buf);
return rc; return rc;
} /* mct_u232_get_modem_stat */ } /* mct_u232_get_modem_stat */
......
...@@ -73,6 +73,8 @@ ...@@ -73,6 +73,8 @@
#define MCT_U232_SET_CTS_REQUEST 12 #define MCT_U232_SET_CTS_REQUEST 12
#define MCT_U232_SET_CTS_SIZE 1 #define MCT_U232_SET_CTS_SIZE 1
#define MCT_U232_MAX_SIZE 4 /* of MCT_XXX_SIZE */
/* /*
* Baud rate (divisor) * Baud rate (divisor)
* Actually, there are two of them, MCT website calls them "Philips solution" * Actually, there are two of them, MCT website calls them "Philips solution"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册