From: Mathieu OTHACEHE <m.othacehe@gmail.com>
To: johan@kernel.org, gregkh@linuxfoundation.org
Cc: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org,
Mathieu OTHACEHE <m.othacehe@gmail.com>
Subject: [PATCH v2 08/22] usb: serial: ti_usb_3410_5052: Remove in_sync and out_sync functions
Date: Tue, 26 Jul 2016 19:59:48 +0200 [thread overview]
Message-ID: <20160726180002.2398-9-m.othacehe@gmail.com> (raw)
In-Reply-To: <20160726180002.2398-1-m.othacehe@gmail.com>
ti_command_in_sync and ti_command_out_sync shouldn't use userspace
datatypes (__uX), data should be void* to avoid casting and size
should be size_t.
This patch rewrite those functions with new names: ti_send_ctrl_data_urb
and ti_recv_ctrl_urb. Also add a ti_send_ctrl_urb to simplify command
sending.
Signed-off-by: Mathieu OTHACEHE <m.othacehe@gmail.com>
---
drivers/usb/serial/ti_usb_3410_5052.c | 157 +++++++++++++++++++---------------
1 file changed, 88 insertions(+), 69 deletions(-)
diff --git a/drivers/usb/serial/ti_usb_3410_5052.c b/drivers/usb/serial/ti_usb_3410_5052.c
index b5f3328..e8515eb 100644
--- a/drivers/usb/serial/ti_usb_3410_5052.c
+++ b/drivers/usb/serial/ti_usb_3410_5052.c
@@ -348,11 +348,6 @@ static void ti_handle_new_msr(struct ti_port *tport, u8 msr);
static void ti_stop_read(struct ti_port *tport, struct tty_struct *tty);
static int ti_restart_read(struct ti_port *tport, struct tty_struct *tty);
-static int ti_command_out_sync(struct ti_device *tdev, __u8 command,
- __u16 moduleid, __u16 value, __u8 *data, int size);
-static int ti_command_in_sync(struct ti_device *tdev, __u8 command,
- __u16 moduleid, __u16 value, __u8 *data, int size);
-
static int ti_write_byte(struct usb_serial_port *port, struct ti_device *tdev,
unsigned long addr, u8 mask, u8 byte);
@@ -517,6 +512,71 @@ MODULE_DEVICE_TABLE(usb, ti_id_table_combined);
module_usb_serial_driver(serial_drivers, ti_id_table_combined);
+static int ti_send_ctrl_data_urb(struct usb_serial *serial, u8 request,
+ u16 value, u16 index, void *data, size_t size)
+{
+ int status;
+
+ status = usb_control_msg(serial->dev,
+ usb_sndctrlpipe(serial->dev, 0),
+ request,
+ (USB_TYPE_VENDOR | USB_RECIP_DEVICE |
+ USB_DIR_OUT), value, index,
+ data, size,
+ USB_CTRL_SET_TIMEOUT);
+ if (status < 0) {
+ dev_err(&serial->interface->dev,
+ "%s - usb_control_msg failed: %d\n",
+ __func__, status);
+ return status;
+ }
+
+ if (status != size) {
+ dev_err(&serial->interface->dev,
+ "%s - short write (%d / %zd)\n",
+ __func__, status, size);
+ return -EIO;
+ }
+
+ return 0;
+}
+
+static int ti_send_ctrl_urb(struct usb_serial *serial,
+ u8 request, u16 value, u16 index)
+{
+ return ti_send_ctrl_data_urb(serial, request, value, index,
+ NULL, 0);
+}
+
+static int ti_recv_ctrl_data_urb(struct usb_serial *serial, u8 request,
+ u16 value, u16 index, void *data, size_t size)
+{
+ int status;
+
+ status = usb_control_msg(serial->dev,
+ usb_rcvctrlpipe(serial->dev, 0),
+ request,
+ (USB_TYPE_VENDOR | USB_RECIP_DEVICE |
+ USB_DIR_IN), value, index,
+ data, size,
+ USB_CTRL_SET_TIMEOUT);
+ if (status < 0) {
+ dev_err(&serial->interface->dev,
+ "%s - usb_control_msg failed: %d\n",
+ __func__, status);
+ return status;
+ }
+
+ if (status != size) {
+ dev_err(&serial->interface->dev,
+ "%s - short read (%d / %zd)\n",
+ __func__, status, size);
+ return -EIO;
+ }
+
+ return 0;
+}
+
static int ti_startup(struct usb_serial *serial)
{
struct ti_device *tdev;
@@ -642,6 +702,7 @@ static int ti_port_remove(struct usb_serial_port *port)
static int ti_open(struct tty_struct *tty, struct usb_serial_port *port)
{
struct ti_port *tport = usb_get_serial_port_data(port);
+ struct usb_serial *serial = port->serial;
struct ti_device *tdev;
struct usb_device *dev;
struct urb *urb;
@@ -685,31 +746,32 @@ static int ti_open(struct tty_struct *tty, struct usb_serial_port *port)
if (tty)
ti_set_termios(tty, port, &tty->termios);
- status = ti_command_out_sync(tdev, TI_OPEN_PORT,
- (__u8)(TI_UART1_PORT + port_number), open_settings, NULL, 0);
+ status = ti_send_ctrl_urb(serial, TI_OPEN_PORT, open_settings,
+ TI_UART1_PORT + port_number);
if (status) {
dev_err(&port->dev, "%s - cannot send open command, %d\n",
__func__, status);
goto unlink_int_urb;
}
- status = ti_command_out_sync(tdev, TI_START_PORT,
- (__u8)(TI_UART1_PORT + port_number), 0, NULL, 0);
+ status = ti_send_ctrl_urb(serial, TI_START_PORT, 0,
+ TI_UART1_PORT + port_number);
if (status) {
dev_err(&port->dev, "%s - cannot send start command, %d\n",
__func__, status);
goto unlink_int_urb;
}
- status = ti_command_out_sync(tdev, TI_PURGE_PORT,
- (__u8)(TI_UART1_PORT + port_number), TI_PURGE_INPUT, NULL, 0);
+ status = ti_send_ctrl_urb(serial, TI_PURGE_PORT, TI_PURGE_INPUT,
+ TI_UART1_PORT + port_number);
if (status) {
dev_err(&port->dev, "%s - cannot clear input buffers, %d\n",
__func__, status);
goto unlink_int_urb;
}
- status = ti_command_out_sync(tdev, TI_PURGE_PORT,
- (__u8)(TI_UART1_PORT + port_number), TI_PURGE_OUTPUT, NULL, 0);
+
+ status = ti_send_ctrl_urb(serial, TI_PURGE_PORT, TI_PURGE_OUTPUT,
+ TI_UART1_PORT + port_number);
if (status) {
dev_err(&port->dev, "%s - cannot clear output buffers, %d\n",
__func__, status);
@@ -724,16 +786,16 @@ static int ti_open(struct tty_struct *tty, struct usb_serial_port *port)
if (tty)
ti_set_termios(tty, port, &tty->termios);
- status = ti_command_out_sync(tdev, TI_OPEN_PORT,
- (__u8)(TI_UART1_PORT + port_number), open_settings, NULL, 0);
+ status = ti_send_ctrl_urb(serial, TI_OPEN_PORT, open_settings,
+ TI_UART1_PORT + port_number);
if (status) {
dev_err(&port->dev, "%s - cannot send open command (2), %d\n",
__func__, status);
goto unlink_int_urb;
}
- status = ti_command_out_sync(tdev, TI_START_PORT,
- (__u8)(TI_UART1_PORT + port_number), 0, NULL, 0);
+ status = ti_send_ctrl_urb(serial, TI_START_PORT, 0,
+ TI_UART1_PORT + port_number);
if (status) {
dev_err(&port->dev, "%s - cannot send start command (2), %d\n",
__func__, status);
@@ -793,8 +855,8 @@ static void ti_close(struct usb_serial_port *port)
port_number = port->port_number;
- status = ti_command_out_sync(tdev, TI_CLOSE_PORT,
- (__u8)(TI_UART1_PORT + port_number), 0, NULL, 0);
+ status = ti_send_ctrl_urb(port->serial, TI_CLOSE_PORT, 0,
+ TI_UART1_PORT + port_number);
if (status)
dev_err(&port->dev,
"%s - cannot send close port command, %d\n"
@@ -1035,9 +1097,9 @@ static void ti_set_termios(struct tty_struct *tty,
config->wBaudRate = cpu_to_be16(wbaudrate);
config->wFlags = cpu_to_be16(wflags);
- status = ti_command_out_sync(tport->tp_tdev, TI_SET_CONFIG,
- (__u8)(TI_UART1_PORT + port_number), 0, (__u8 *)config,
- sizeof(*config));
+ status = ti_send_ctrl_data_urb(port->serial, TI_SET_CONFIG, 0,
+ TI_UART1_PORT + port_number, config,
+ sizeof(*config));
if (status)
dev_err(&port->dev, "%s - cannot set config on port %d, %d\n",
__func__, port_number, status);
@@ -1401,7 +1463,6 @@ static int ti_set_mcr(struct ti_port *tport, unsigned int mcr)
static int ti_get_lsr(struct ti_port *tport, u8 *lsr)
{
int size, status;
- struct ti_device *tdev = tport->tp_tdev;
struct usb_serial_port *port = tport->tp_port;
int port_number = port->port_number;
struct ti_port_status *data;
@@ -1411,8 +1472,8 @@ static int ti_get_lsr(struct ti_port *tport, u8 *lsr)
if (!data)
return -ENOMEM;
- status = ti_command_in_sync(tdev, TI_GET_PORT_STATUS,
- (__u8)(TI_UART1_PORT+port_number), 0, (__u8 *)data, size);
+ status = ti_recv_ctrl_data_urb(port->serial, TI_GET_PORT_STATUS, 0,
+ TI_UART1_PORT + port_number, data, size);
if (status) {
dev_err(&port->dev,
"%s - get port status command failed, %d\n",
@@ -1555,47 +1616,6 @@ static int ti_restart_read(struct ti_port *tport, struct tty_struct *tty)
return status;
}
-
-static int ti_command_out_sync(struct ti_device *tdev, __u8 command,
- __u16 moduleid, __u16 value, __u8 *data, int size)
-{
- int status;
-
- status = usb_control_msg(tdev->td_serial->dev,
- usb_sndctrlpipe(tdev->td_serial->dev, 0), command,
- (USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT),
- value, moduleid, data, size, 1000);
-
- if (status == size)
- status = 0;
-
- if (status > 0)
- status = -ECOMM;
-
- return status;
-}
-
-
-static int ti_command_in_sync(struct ti_device *tdev, __u8 command,
- __u16 moduleid, __u16 value, __u8 *data, int size)
-{
- int status;
-
- status = usb_control_msg(tdev->td_serial->dev,
- usb_rcvctrlpipe(tdev->td_serial->dev, 0), command,
- (USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN),
- value, moduleid, data, size, 1000);
-
- if (status == size)
- status = 0;
-
- if (status > 0)
- status = -ECOMM;
-
- return status;
-}
-
-
static int ti_write_byte(struct usb_serial_port *port,
struct ti_device *tdev, unsigned long addr,
u8 mask, u8 byte)
@@ -1620,9 +1640,8 @@ static int ti_write_byte(struct usb_serial_port *port,
data->bData[0] = mask;
data->bData[1] = byte;
- status = ti_command_out_sync(tdev, TI_WRITE_DATA, TI_RAM_PORT, 0,
- (__u8 *)data, size);
-
+ status = ti_send_ctrl_data_urb(port->serial, TI_WRITE_DATA, 0,
+ TI_RAM_PORT, data, size);
if (status < 0)
dev_err(&port->dev, "%s - failed, %d\n", __func__, status);
--
2.9.0
next prev parent reply other threads:[~2016-07-26 18:04 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-26 17:59 [PATCH v2 00/22] usb: serial: ti_usb_3410_5052: clean driver Mathieu OTHACEHE
2016-07-26 17:59 ` [PATCH v2 01/22] usb: serial: ti_usb_3410_5052: Do not use __uX types Mathieu OTHACEHE
2016-08-23 7:44 ` Johan Hovold
2016-07-26 17:59 ` [PATCH v2 02/22] usb: serial: ti_usb_3410_5052: Remove useless dev_dbg messages Mathieu OTHACEHE
2016-08-23 7:52 ` Johan Hovold
2016-07-26 17:59 ` [PATCH v2 03/22] usb: serial: ti_usb_3410_5052: Use kzalloc instead of kmalloc Mathieu OTHACEHE
2016-07-27 8:09 ` Oliver Neukum
2016-07-27 12:46 ` Mathieu OTHACEHE
2016-08-23 7:54 ` Johan Hovold
2016-07-27 11:21 ` Sergei Shtylyov
2016-07-26 17:59 ` [PATCH v2 04/22] usb: serial: ti_usb_3410_5052: Remove useless NULL-testing Mathieu OTHACEHE
2016-08-23 8:04 ` Johan Hovold
2016-07-26 17:59 ` [PATCH v2 05/22] usb: serial: ti_usb_3410_5052: Use C_X macros instead of c_cflag manipulation Mathieu OTHACEHE
2016-07-26 17:59 ` [PATCH v2 06/22] usb: serial: ti_usb_3410_5052: Remove unused variables Mathieu OTHACEHE
2016-08-23 8:15 ` Johan Hovold
2016-07-26 17:59 ` [PATCH v2 07/22] usb: serial: ti_usb_3410_5052: Use macros instead of magic values Mathieu OTHACEHE
2016-08-23 8:19 ` Johan Hovold
2016-07-26 17:59 ` Mathieu OTHACEHE [this message]
2016-07-26 17:59 ` [PATCH v2 09/22] usb: serial: ti_usb_3410_5052: Remove useless tty_wakeup Mathieu OTHACEHE
2016-07-26 17:59 ` [PATCH v2 10/22] usb: serial: ti_usb_3410_5052: Change ti_write_byte function arguments Mathieu OTHACEHE
2016-07-27 8:13 ` Oliver Neukum
2016-07-27 16:08 ` Mathieu OTHACEHE
2016-07-27 19:10 ` Oliver Neukum
2016-07-26 17:59 ` [PATCH v2 11/22] usb: serial: ti_usb_3410_5052: Do not modify interrupt context Mathieu OTHACEHE
2016-07-26 17:59 ` [PATCH v2 12/22] usb: serial: ti_usb_3410_5052: Remove usb_serial pointer in ti_port Mathieu OTHACEHE
2016-07-26 17:59 ` [PATCH v2 13/22] usb: serial: ti_usb_3410_5052: Change ti_get/set_serial_info function arguments Mathieu OTHACEHE
2016-07-26 17:59 ` [PATCH v2 14/22] usb: serial: ti_usb_3410_5052: Do not set shadow mcr in open callback Mathieu OTHACEHE
2016-07-26 17:59 ` [PATCH v2 15/22] usb: serial: ti_usb_3410_5052: Check old_termios parameter in set_termios Mathieu OTHACEHE
2016-07-26 17:59 ` [PATCH v2 16/22] usb: serial: ti_usb_3410_5052: Raise DTR and RTS flags if speed is not null anymore Mathieu OTHACEHE
2016-07-26 17:59 ` [PATCH v2 17/22] usb: serial: ti_usb_3410_5052: Fix firmware downloading Mathieu OTHACEHE
2016-07-26 17:59 ` [PATCH v2 18/22] usb: serial: ti_usb_3410_5052: Standardize debug and error messages Mathieu OTHACEHE
2016-07-26 17:59 ` [PATCH v2 19/22] usb: serial: ti_usb_3410_5052: Use variables for vendor and product Mathieu OTHACEHE
2016-07-26 18:00 ` [PATCH v2 20/22] usb: serial: ti_usb_3410_5052: Set shadow msr before waking up waiters Mathieu OTHACEHE
2016-07-26 18:00 ` [PATCH v2 21/22] usb: serial: ti_usb_3410_5052: Add CMSPAR support Mathieu OTHACEHE
2016-07-26 18:00 ` [PATCH v2 22/22] usb: serial: ti_usb_3410_5052: Fix indentation problems Mathieu OTHACEHE
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160726180002.2398-9-m.othacehe@gmail.com \
--to=m.othacehe@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=johan@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).