Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751799AbdLMIgQ (ORCPT ); Wed, 13 Dec 2017 03:36:16 -0500 Received: from smtp43.i.mail.ru ([94.100.177.103]:51208 "EHLO smtp43.i.mail.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750785AbdLMIgM (ORCPT ); Wed, 13 Dec 2017 03:36:12 -0500 Date: Wed, 13 Dec 2017 11:29:00 +0300 From: Mikhail Zaytsev (by way of Mikhail Zaytsev ) To: Mikhail Zaytsev Message-ID: <20171213112900.60ec3e77@zaytsev.tver.pg> X-Mailer: Claws Mail 3.14.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-7FA49CB5: 0D63561A33F958A5892641D49F4D89B136E8E45B9BA2FDDBE02F2E05526AA167725E5C173C3A84C39B7AFBAF9359C3A2E37085B66532B0C2F1C9CF18C8EB2269C4224003CC836476C0CAF46E325F83A50BF2EBBBDD9D6B0F2AF38021CC9F462D574AF45C6390F7469DAA53EE0834AAEE X-Mailru-Sender: AAD8E2226B689FDAF6252034B9A76A5CC38D783AD1774CD9726CAD137D910C8039C604822A04508789FF501873465F1766FEC6BF5C9C28D91C46F632D9E29CE943722207280E957E67EA787935ED9F1B X-Mras: OK Subject: [PATCH] USB: serial: ark3116.c: Remove unused TIOCSSERIAL case from ioctl Authentication-Results: smtp43.i.mail.ru; auth=pass smtp.auth=flashed@mail.ru smtp.mailfrom=flashed@mail.ru X-7FA49CB5: 0D63561A33F958A598043ED8B514396A5A678318BEBDF17EC0731C76F60764D3725E5C173C3A84C3D5C20573A3B95D97707BB65C825966BC26B9191E2D567F0EC4224003CC836476C0CAF46E325F83A50BF2EBBBDD9D6B0F2AF38021CC9F462D574AF45C6390F7469DAA53EE0834AAEE X-Mailru-Sender: AAD8E2226B689FDAF6252034B9A76A5C5762A8AA50F78E4EC34BF7158BF88256AA7D504100BA821089FF501873465F1766FEC6BF5C9C28D91C46F632D9E29CE943722207280E957E67EA787935ED9F1B X-Mras: OK Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2984 Lines: 102 The patch removes unused TIOCSSERIAL case from ioctl. TIOCGSERIAL case moves to the get_serial_info() function. Any magic numbers moves to #define directives. Signed-off-by: Mikhail Zaytsev --- drivers/usb/serial/ark3116.c | 54 ++++++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/drivers/usb/serial/ark3116.c b/drivers/usb/serial/ark3116.c index 23d46ef87..f45f69e18 100644 --- a/drivers/usb/serial/ark3116.c +++ b/drivers/usb/serial/ark3116.c @@ -36,13 +36,19 @@ #define DRIVER_DESC "USB ARK3116 serial/IrDA driver" #define DRIVER_DEV_DESC "ARK3116 RS232/IrDA" #define DRIVER_NAME "ark3116" +#define ARK3116_BAUDRATE 460800 + +#define RS232_VENDOR 0x6547 +#define RS232_PRODUCT 0x0232 +#define IRDA_VENDOR 0x18ec +#define IRDA_PRODUCT 0x3118 /* usb timeout of 1 second */ #define ARK_TIMEOUT 1000 static const struct usb_device_id id_table[] = { - { USB_DEVICE(0x6547, 0x0232) }, - { USB_DEVICE(0x18ec, 0x3118) }, /* USB to IrDA adapter */ + { USB_DEVICE(RS232_VENDOR, RS232_PRODUCT) }, + { USB_DEVICE(IRDA_VENDOR, IRDA_PRODUCT) }, /* USB to IrDA adapter */ { }, }; MODULE_DEVICE_TABLE(usb, id_table); @@ -50,8 +56,8 @@ MODULE_DEVICE_TABLE(usb, id_table); static int is_irda(struct usb_serial *serial) { struct usb_device *dev = serial->dev; - if (le16_to_cpu(dev->descriptor.idVendor) == 0x18ec && - le16_to_cpu(dev->descriptor.idProduct) == 0x3118) + if (le16_to_cpu(dev->descriptor.idVendor) == IRDA_VENDOR && + le16_to_cpu(dev->descriptor.idProduct) == IRDA_PRODUCT) return 1; return 0; } @@ -397,31 +403,35 @@ static int ark3116_open(struct tty_struct *tty, struct usb_serial_port *port) return result; } +static int ark3116_get_serial_info(struct usb_serial_port *port, + unsigned long arg) +{ + struct serial_struct ser; + + memset(&ser, 0, sizeof(ser)); + + ser.type = PORT_16654; + ser.line = port->minor; + ser.port = port->port_number; + ser.custom_divisor = 0; + ser.baud_base = ARK3116_BAUDRATE; + + if (copy_to_user((void __user *)arg, &ser, sizeof(ser))) + return -EFAULT; + + return 0; +} + static int ark3116_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg) { struct usb_serial_port *port = tty->driver_data; - struct serial_struct serstruct; - void __user *user_arg = (void __user *)arg; switch (cmd) { case TIOCGSERIAL: - /* XXX: Some of these values are probably wrong. */ - memset(&serstruct, 0, sizeof(serstruct)); - serstruct.type = PORT_16654; - serstruct.line = port->minor; - serstruct.port = port->port_number; - serstruct.custom_divisor = 0; - serstruct.baud_base = 460800; - - if (copy_to_user(user_arg, &serstruct, sizeof(serstruct))) - return -EFAULT; - - return 0; - case TIOCSSERIAL: - if (copy_from_user(&serstruct, user_arg, sizeof(serstruct))) - return -EFAULT; - return 0; + return ark3116_get_serial_info(port, arg); + default: + break; } return -ENOIOCTLCMD; -- 2.11.0