From patchwork Thu Nov 7 13:28:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 11232787 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CAA9F1850 for ; Thu, 7 Nov 2019 13:29:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A0622218AE for ; Thu, 7 Nov 2019 13:29:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573133371; bh=M0mtW1QfgoABj4u03nO+wZVlgdnnbc530WEBoHkksR0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=m9XzFhn0rbupD7lKTuc3ZVhj+tfEOS8jETUlAfUdgKDnPJbmGkRvjwgTd4+yR9D0H 7QInyI8hi7ChkomORHfEINWEwvJMvaQHzPVFp1CCZEcIjTnSZdC5Viwj1ndaz+IA/J DZ51ZG2crYP6HS5ef/dRPRM78zIoOynWGKXex71c= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387763AbfKGN3a (ORCPT ); Thu, 7 Nov 2019 08:29:30 -0500 Received: from mail-lj1-f195.google.com ([209.85.208.195]:44331 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728687AbfKGN3a (ORCPT ); Thu, 7 Nov 2019 08:29:30 -0500 Received: by mail-lj1-f195.google.com with SMTP id g3so2255950ljl.11 for ; Thu, 07 Nov 2019 05:29:27 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9ltBNcSELxQBDJPS5fhj1KWRfvpuYAgMykIAsgA01P4=; b=REWlDSxGoUKFYetTc06RChd44c812ifjsu/bmdDo+pFJx1BfuHnr6eYZz0fD1yyss9 ns0hTcvy2WTkUwURoCWv6Ls9Dm4KSGJLOw95pM1uUCUAKEo1cySO8iEFbpxc0WVe/WtU Ni0f/I8HOLmjcv6KIcXONqK7aJFtcITZEvlqq+m0kfejeu68hSQ1So+UzKH/G1TQ5saB yICxKZjnPlzX4gnhJz2dfMBegcbj5Ri2MgmO8257ba52wCm54LK0JjzFsAzG4htVW1Tl a9BtkoxroO5ro1MyMc3266XfO25qTXFfVJoqskt+LswjYzfLBCBjjxE8sLoCq5B78L8F OqFA== X-Gm-Message-State: APjAAAV0MHj1z8Ism5754aFkNu9rQPbiIsiQNPMoV2BWDlKiT2YGMjid q5vpV6OCFHNw15QOpCaZmYw= X-Google-Smtp-Source: APXvYqzi6DzZLj7sg5h1w4f/LUA6Iny4S/tgr8PnJl+lLuYJzBGINBW4GWd9pHbKfDMfDjjjJLJU2w== X-Received: by 2002:a05:651c:119b:: with SMTP id w27mr2283597ljo.221.1573133366324; Thu, 07 Nov 2019 05:29:26 -0800 (PST) Received: from xi.terra (c-51f1e055.07-184-6d6c6d4.bbcust.telenor.se. [85.224.241.81]) by smtp.gmail.com with ESMTPSA id x187sm1143374lfa.64.2019.11.07.05.29.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Nov 2019 05:29:23 -0800 (PST) Received: from johan by xi.terra with local (Exim 4.92.3) (envelope-from ) id 1iShqn-0000dO-8u; Thu, 07 Nov 2019 14:29:25 +0100 From: Johan Hovold To: Johan Hovold Cc: linux-usb@vger.kernel.org Subject: [PATCH 01/11] USB: serial: mos7840: clean up device-type handling Date: Thu, 7 Nov 2019 14:28:54 +0100 Message-Id: <20191107132904.2379-2-johan@kernel.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191107132904.2379-1-johan@kernel.org> References: <20191107132904.2379-1-johan@kernel.org> MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The current device-type detection is fragile and can't really be relied upon. Instead of sprinkling device-id conditionals throughout the driver, let's use the device-id table to encode the number of ports and whether the device has a driver-controlled activity LED (MCS7810). Signed-off-by: Johan Hovold --- drivers/usb/serial/mos7840.c | 121 +++++++++++++---------------------- 1 file changed, 44 insertions(+), 77 deletions(-) diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c index ab4bf8d6d7df..f13cf723fa6c 100644 --- a/drivers/usb/serial/mos7840.c +++ b/drivers/usb/serial/mos7840.c @@ -89,17 +89,10 @@ /* For higher baud Rates use TIOCEXBAUD */ #define TIOCEXBAUD 0x5462 -/* vendor id and device id defines */ - -/* The native mos7840/7820 component */ -#define USB_VENDOR_ID_MOSCHIP 0x9710 -#define MOSCHIP_DEVICE_ID_7840 0x7840 -#define MOSCHIP_DEVICE_ID_7843 0x7843 -#define MOSCHIP_DEVICE_ID_7820 0x7820 -#define MOSCHIP_DEVICE_ID_7810 0x7810 -/* The native component can have its vendor/device id's overridden - * in vendor-specific implementations. Such devices can be handled - * by making a change here, in id_table. +/* + * Vendor id and device id defines + * + * NOTE: Do not add new defines, add entries directly to the id_table instead. */ #define USB_VENDOR_ID_BANDB 0x0856 #define BANDB_DEVICE_ID_USO9ML2_2 0xAC22 @@ -116,18 +109,6 @@ #define BANDB_DEVICE_ID_USOPTL4_4P 0xBC03 #define BANDB_DEVICE_ID_USOPTL2_4 0xAC24 -/* This driver also supports - * ATEN UC2324 device using Moschip MCS7840 - * ATEN UC2322 device using Moschip MCS7820 - * MOXA UPort 2210 device using Moschip MCS7820 - */ -#define USB_VENDOR_ID_ATENINTL 0x0557 -#define ATENINTL_DEVICE_ID_UC2324 0x2011 -#define ATENINTL_DEVICE_ID_UC2322 0x7820 - -#define USB_VENDOR_ID_MOXA 0x110a -#define MOXA_DEVICE_ID_2210 0x2210 - /* Interrupt Routine Defines */ #define SERIAL_IIR_RLS 0x06 @@ -179,27 +160,34 @@ enum mos7840_flag { MOS7840_FLAG_LED_BUSY, }; +#define MCS_PORT_MASK GENMASK(2, 0) +#define MCS_PORTS(nr) ((nr) & MCS_PORT_MASK) +#define MCS_LED BIT(3) + +#define MCS_DEVICE(vid, pid, flags) \ + USB_DEVICE((vid), (pid)), .driver_info = (flags) + static const struct usb_device_id id_table[] = { - {USB_DEVICE(USB_VENDOR_ID_MOSCHIP, MOSCHIP_DEVICE_ID_7840)}, - {USB_DEVICE(USB_VENDOR_ID_MOSCHIP, MOSCHIP_DEVICE_ID_7843)}, - {USB_DEVICE(USB_VENDOR_ID_MOSCHIP, MOSCHIP_DEVICE_ID_7820)}, - {USB_DEVICE(USB_VENDOR_ID_MOSCHIP, MOSCHIP_DEVICE_ID_7810)}, - {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USO9ML2_2)}, - {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USO9ML2_2P)}, - {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USO9ML2_4)}, - {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USO9ML2_4P)}, - {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_US9ML2_2)}, - {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_US9ML2_4)}, - {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USPTL4_2)}, - {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USPTL4_4)}, - {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL4_2)}, - {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL4_2P)}, - {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL4_4)}, - {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL4_4P)}, - {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL2_4)}, - {USB_DEVICE(USB_VENDOR_ID_ATENINTL, ATENINTL_DEVICE_ID_UC2324)}, - {USB_DEVICE(USB_VENDOR_ID_ATENINTL, ATENINTL_DEVICE_ID_UC2322)}, - {USB_DEVICE(USB_VENDOR_ID_MOXA, MOXA_DEVICE_ID_2210)}, + { MCS_DEVICE(0x0557, 0x2011, MCS_PORTS(4)) }, /* ATEN UC2324 */ + { MCS_DEVICE(0x0557, 0x7820, MCS_PORTS(2)) }, /* ATEN UC2322 */ + { MCS_DEVICE(0x110a, 0x2210, MCS_PORTS(2)) }, /* Moxa UPort 2210 */ + { MCS_DEVICE(0x9710, 0x7810, MCS_PORTS(1) | MCS_LED) }, /* ASIX MCS7810 */ + { MCS_DEVICE(0x9710, 0x7820, MCS_PORTS(2)) }, /* MosChip MCS7820 */ + { MCS_DEVICE(0x9710, 0x7840, MCS_PORTS(4)) }, /* MosChip MCS7840 */ + { MCS_DEVICE(0x9710, 0x7843, MCS_PORTS(3)) }, /* ASIX MCS7840 3 port */ + { USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USO9ML2_2) }, + { USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USO9ML2_2P) }, + { USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USO9ML2_4) }, + { USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USO9ML2_4P) }, + { USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_US9ML2_2) }, + { USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_US9ML2_4) }, + { USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USPTL4_2) }, + { USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USPTL4_4) }, + { USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL4_2) }, + { USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL4_2P) }, + { USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL4_4) }, + { USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL4_4P) }, + { USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL2_4) }, {} /* terminating entry */ }; MODULE_DEVICE_TABLE(usb, id_table); @@ -2024,22 +2012,12 @@ static int mos7810_check(struct usb_serial *serial) static int mos7840_probe(struct usb_serial *serial, const struct usb_device_id *id) { - u16 product = le16_to_cpu(serial->dev->descriptor.idProduct); - u16 vid = le16_to_cpu(serial->dev->descriptor.idVendor); + unsigned long device_flags = id->driver_info; u8 *buf; - int device_type; - if (product == MOSCHIP_DEVICE_ID_7810 || - product == MOSCHIP_DEVICE_ID_7820 || - product == MOSCHIP_DEVICE_ID_7843) { - device_type = product; + /* Skip device-type detection if we already have device flags. */ + if (device_flags) goto out; - } - - if (vid == USB_VENDOR_ID_MOXA && product == MOXA_DEVICE_ID_2210) { - device_type = MOSCHIP_DEVICE_ID_7820; - goto out; - } buf = kzalloc(VENDOR_READ_LENGTH, GFP_KERNEL); if (!buf) @@ -2051,15 +2029,15 @@ static int mos7840_probe(struct usb_serial *serial, /* For a MCS7840 device GPIO0 must be set to 1 */ if (buf[0] & 0x01) - device_type = MOSCHIP_DEVICE_ID_7840; + device_flags = MCS_PORTS(4); else if (mos7810_check(serial)) - device_type = MOSCHIP_DEVICE_ID_7810; + device_flags = MCS_PORTS(1) | MCS_LED; else - device_type = MOSCHIP_DEVICE_ID_7820; + device_flags = MCS_PORTS(2); kfree(buf); out: - usb_set_serial_data(serial, (void *)(unsigned long)device_type); + usb_set_serial_data(serial, (void *)device_flags); return 0; } @@ -2067,19 +2045,10 @@ static int mos7840_probe(struct usb_serial *serial, static int mos7840_calc_num_ports(struct usb_serial *serial, struct usb_serial_endpoints *epds) { - int device_type = (unsigned long)usb_get_serial_data(serial); - int num_ports; + unsigned long device_flags = (unsigned long)usb_get_serial_data(serial); + int num_ports = MCS_PORTS(device_flags); - if (device_type == MOSCHIP_DEVICE_ID_7843) - num_ports = 3; - else - num_ports = (device_type >> 4) & 0x000F; - - /* - * num_ports is currently never zero as device_type is one of - * MOSCHIP_DEVICE_ID_78{1,2,4}0. - */ - if (num_ports == 0) + if (num_ports == 0 || num_ports > 4) return -ENODEV; if (epds->num_bulk_in < num_ports || epds->num_bulk_out < num_ports) { @@ -2093,7 +2062,7 @@ static int mos7840_calc_num_ports(struct usb_serial *serial, static int mos7840_port_probe(struct usb_serial_port *port) { struct usb_serial *serial = port->serial; - int device_type = (unsigned long)usb_get_serial_data(serial); + unsigned long device_flags = (unsigned long)usb_get_serial_data(serial); struct moschip_port *mos7840_port; int status; int pnum; @@ -2255,12 +2224,10 @@ static int mos7840_port_probe(struct usb_serial_port *port) goto error; } - mos7840_port->has_led = false; + mos7840_port->has_led = device_flags & MCS_LED; /* Initialize LED timers */ - if (device_type == MOSCHIP_DEVICE_ID_7810) { - mos7840_port->has_led = true; - + if (mos7840_port->has_led) { mos7840_port->led_urb = usb_alloc_urb(0, GFP_KERNEL); mos7840_port->led_dr = kmalloc(sizeof(*mos7840_port->led_dr), GFP_KERNEL); From patchwork Thu Nov 7 13:28:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 11232785 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7459C1747 for ; Thu, 7 Nov 2019 13:29:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4AA882187F for ; Thu, 7 Nov 2019 13:29:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573133371; bh=yXhhLZSrr7EuryNuFTVjyYdqRDKgG73USAgKsCe6bL8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=czYZnFqS5Du0RhAmAJTNToWoQ236NZiQWnI22tHk7FQnDJnDBy7A2c00wc6wozr3p S58KDxuyJ4ZdHOiO1yxV38113yW44m/OJ9Ugf9sW0ZVA160p161Lv8s+/oiFClt9cb lHbzFtPq+c8hMBqwdEEcpqUohnokjDc1p1hxYd5k= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387675AbfKGN3a (ORCPT ); Thu, 7 Nov 2019 08:29:30 -0500 Received: from mail-lj1-f193.google.com ([209.85.208.193]:46808 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729070AbfKGN3a (ORCPT ); Thu, 7 Nov 2019 08:29:30 -0500 Received: by mail-lj1-f193.google.com with SMTP id e9so2235963ljp.13 for ; Thu, 07 Nov 2019 05:29:29 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4r/F/ivoK5xSMfm2eKEdB73WmR9Rd+NwLR476BvBd0I=; b=TBXJfcHvrALZJ4J5O3o2cYaB56lopKe8MJX6myMMaCHFv+TdwNs0sVnBAEzhVZFqkf uFPcjN+tJInVdZbYSdJBrhSn3nW7zuKey0z4j5iP9Mp+ZqiJ/G4lv8huA4x3GOVinodm C0uHXeSWfy7QAaZnKkNB1icbzdb2eR7aHc5vB9kf2Pn84nYQ8+d44DKmI49kMWlGwB/N fLisKfkGjSuxe/65zoyvFn0A8n7+76PWsmGhBhNOdVCOWRD7YeyY2EDfWL/KFCzOBaUu 4PsHZMWL0+pIrWZOA4OGu0mh4LQkH8r2fJtTEmakZtWhTv5fQ5r9Wgu+G2dX86NQtwoc vrHA== X-Gm-Message-State: APjAAAXlxdTm+kk0SGJctl0fKK+UVE9pBbGH1D5bjGC96AJ5q0+2iR8Z 97ye9lLK87oA2Nu6j+vKiMA= X-Google-Smtp-Source: APXvYqyXmqRzwEmDcodMrwAkoADtdV7DZgLjf7FJEOrdlJ2xw6dejHGCNxBLBq31IekOezeiqX4/kg== X-Received: by 2002:a2e:b4c1:: with SMTP id r1mr2540310ljm.203.1573133368314; Thu, 07 Nov 2019 05:29:28 -0800 (PST) Received: from xi.terra (c-51f1e055.07-184-6d6c6d4.bbcust.telenor.se. [85.224.241.81]) by smtp.gmail.com with ESMTPSA id p8sm1210257ljn.0.2019.11.07.05.29.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Nov 2019 05:29:23 -0800 (PST) Received: from johan by xi.terra with local (Exim 4.92.3) (envelope-from ) id 1iShqn-0000dS-BI; Thu, 07 Nov 2019 14:29:25 +0100 From: Johan Hovold To: Johan Hovold Cc: linux-usb@vger.kernel.org Subject: [PATCH 02/11] USB: serial: mos7840: document MCS7810 detection hack Date: Thu, 7 Nov 2019 14:28:55 +0100 Message-Id: <20191107132904.2379-3-johan@kernel.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191107132904.2379-1-johan@kernel.org> References: <20191107132904.2379-1-johan@kernel.org> MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Document the MCS7810 detection hack which relies on having the GPO and GPI pins connected as recommended by ASIX. Note that GPO (pin 42) is really RTS of the third port which will be toggled for the corresponding physical port on two- and four-port devices. Signed-off-by: Johan Hovold --- drivers/usb/serial/mos7840.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c index f13cf723fa6c..6de41a3c2dab 100644 --- a/drivers/usb/serial/mos7840.c +++ b/drivers/usb/serial/mos7840.c @@ -1955,6 +1955,13 @@ static int mos7840_ioctl(struct tty_struct *tty, return -ENOIOCTLCMD; } +/* + * Check if GPO (pin 42) is connected to GPI (pin 33) as recommended by ASIX + * for MCS7810 by bit-banging a 16-bit word. + * + * Note that GPO is really RTS of the third port so this will toggle RTS of + * port two or three on two- and four-port devices. + */ static int mos7810_check(struct usb_serial *serial) { int i, pass_count = 0; From patchwork Thu Nov 7 13:28:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 11232789 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DC1E213BD for ; Thu, 7 Nov 2019 13:29:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B23B02178F for ; Thu, 7 Nov 2019 13:29:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573133372; bh=MeM6MddWrmTwIwuEDKyO5VXVH8tXSEUPURpqWUwWqf4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=qm8RBBDwtz6P4GiMwy6ikFG8hJktra5KdhFC5LuX81s8EtMx0hRKYLKwacHr9Jsg4 AtqyDctksD3WKO+LXQMWlFuO9ic+0+OIPIAjd8SwYyLsri8uLGIzNKhEfKvvy3h3Cu XLgbxIIY2XeVuFZn374AIbOzOhilv/X7stLWnWSs= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388310AbfKGN3c (ORCPT ); Thu, 7 Nov 2019 08:29:32 -0500 Received: from mail-lj1-f195.google.com ([209.85.208.195]:45163 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728568AbfKGN3b (ORCPT ); Thu, 7 Nov 2019 08:29:31 -0500 Received: by mail-lj1-f195.google.com with SMTP id n21so2252440ljg.12 for ; Thu, 07 Nov 2019 05:29:29 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=KV6FgkZT3tBNc1qg/Lz1AkNLOCRRjfwbev+8vDOiJp4=; b=YHTcXjmVeGroMDLq2uQQJ/C/sbJsO7wcdUpx6uFDs3yTw4RW9+PxZI+WHDgOMnhxwD uPv49JsenNSsCyiqN63Cj2D34liFmZ90um2Hw5QzEwcvGDgbuEPjGwhJ04YHWsV7jZad xBSX509GeIRgAs0JJgU82tyYaZR+QqoO5B7/VvkJwWV8jGZtucL48OiaVAwgORx3kWNO Q96WhPrV+L7S4j8DV/cxAB3D8WWrNxTreW3bhecWAOWMLfH1hluPTaOaoSrHlISVjYF6 0js88Y08m/fIakV33273WS6WSFQX4iiDuSy3Oyb1yyjNnBMW6chrjVi8u6hv0bRGFSve cM2g== X-Gm-Message-State: APjAAAUxJklA7T9CPZBtuUB+1kffEvuAA6HaLs+Sm+qO8u0wgCHATUnp w88XQcPLmQo+8hbFrvRi+4w= X-Google-Smtp-Source: APXvYqxpFCshqccB/E/oEqKT+p5364/UGH9bR/GLB6mpvxJJzao9wP7mlQlFqO1jKC+9bIgw+RaBjg== X-Received: by 2002:a2e:9b89:: with SMTP id z9mr2573775lji.185.1573133368792; Thu, 07 Nov 2019 05:29:28 -0800 (PST) Received: from xi.terra (c-51f1e055.07-184-6d6c6d4.bbcust.telenor.se. [85.224.241.81]) by smtp.gmail.com with ESMTPSA id y18sm1249830lja.12.2019.11.07.05.29.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Nov 2019 05:29:25 -0800 (PST) Received: from johan by xi.terra with local (Exim 4.92.3) (envelope-from ) id 1iShqn-0000da-Dw; Thu, 07 Nov 2019 14:29:25 +0100 From: Johan Hovold To: Johan Hovold Cc: linux-usb@vger.kernel.org Subject: [PATCH 03/11] USB: serial: mos7840: fix probe error handling Date: Thu, 7 Nov 2019 14:28:56 +0100 Message-Id: <20191107132904.2379-4-johan@kernel.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191107132904.2379-1-johan@kernel.org> References: <20191107132904.2379-1-johan@kernel.org> MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The driver would return success and leave the port structures half-initialised if any of the register accesses during probe fails. This would specifically leave the port control urb unallocated, something which could trigger a NULL pointer dereference on interrupt events. Fortunately the interrupt implementation is completely broken and has never even been enabled... Note that the zero-length-enable register write used to set the zle-flag for all ports is moved to attach. Signed-off-by: Johan Hovold --- drivers/usb/serial/mos7840.c | 48 +++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c index 6de41a3c2dab..ddd8db3be110 100644 --- a/drivers/usb/serial/mos7840.c +++ b/drivers/usb/serial/mos7840.c @@ -2066,6 +2066,23 @@ static int mos7840_calc_num_ports(struct usb_serial *serial, return num_ports; } +static int mos7840_attach(struct usb_serial *serial) +{ + struct device *dev = &serial->interface->dev; + int status; + u16 val; + + /* Zero Length flag enable */ + val = 0x0f; + status = mos7840_set_reg_sync(serial->port[0], ZLP_REG5, val); + if (status < 0) + dev_dbg(dev, "Writing ZLP_REG5 failed status-0x%x\n", status); + else + dev_dbg(dev, "ZLP_REG5 Writing success status%d\n", status); + + return status; +} + static int mos7840_port_probe(struct usb_serial_port *port) { struct usb_serial *serial = port->serial; @@ -2123,7 +2140,7 @@ static int mos7840_port_probe(struct usb_serial_port *port) mos7840_port->ControlRegOffset, &Data); if (status < 0) { dev_dbg(&port->dev, "Reading ControlReg failed status-0x%x\n", status); - goto out; + goto error; } else dev_dbg(&port->dev, "ControlReg Reading success val is %x, status%d\n", Data, status); Data |= 0x08; /* setting driver done bit */ @@ -2135,7 +2152,7 @@ static int mos7840_port_probe(struct usb_serial_port *port) mos7840_port->ControlRegOffset, Data); if (status < 0) { dev_dbg(&port->dev, "Writing ControlReg failed(rx_disable) status-0x%x\n", status); - goto out; + goto error; } else dev_dbg(&port->dev, "ControlReg Writing success(rx_disable) status%d\n", status); @@ -2146,7 +2163,7 @@ static int mos7840_port_probe(struct usb_serial_port *port) (__u16) (mos7840_port->DcrRegOffset + 0), Data); if (status < 0) { dev_dbg(&port->dev, "Writing DCR0 failed status-0x%x\n", status); - goto out; + goto error; } else dev_dbg(&port->dev, "DCR0 Writing success status%d\n", status); @@ -2155,7 +2172,7 @@ static int mos7840_port_probe(struct usb_serial_port *port) (__u16) (mos7840_port->DcrRegOffset + 1), Data); if (status < 0) { dev_dbg(&port->dev, "Writing DCR1 failed status-0x%x\n", status); - goto out; + goto error; } else dev_dbg(&port->dev, "DCR1 Writing success status%d\n", status); @@ -2164,7 +2181,7 @@ static int mos7840_port_probe(struct usb_serial_port *port) (__u16) (mos7840_port->DcrRegOffset + 2), Data); if (status < 0) { dev_dbg(&port->dev, "Writing DCR2 failed status-0x%x\n", status); - goto out; + goto error; } else dev_dbg(&port->dev, "DCR2 Writing success status%d\n", status); @@ -2173,7 +2190,7 @@ static int mos7840_port_probe(struct usb_serial_port *port) status = mos7840_set_reg_sync(port, CLK_START_VALUE_REGISTER, Data); if (status < 0) { dev_dbg(&port->dev, "Writing CLK_START_VALUE_REGISTER failed status-0x%x\n", status); - goto out; + goto error; } else dev_dbg(&port->dev, "CLK_START_VALUE_REGISTER Writing success status%d\n", status); @@ -2190,7 +2207,7 @@ static int mos7840_port_probe(struct usb_serial_port *port) status = mos7840_set_uart_reg(port, SCRATCH_PAD_REGISTER, Data); if (status < 0) { dev_dbg(&port->dev, "Writing SCRATCH_PAD_REGISTER failed status-0x%x\n", status); - goto out; + goto error; } else dev_dbg(&port->dev, "SCRATCH_PAD_REGISTER Writing success status%d\n", status); @@ -2204,7 +2221,7 @@ static int mos7840_port_probe(struct usb_serial_port *port) (__u16)(ZLP_REG1 + ((__u16) mos7840_port->port_num))); if (status < 0) { dev_dbg(&port->dev, "Writing ZLP_REG%d failed status-0x%x\n", pnum + 2, status); - goto out; + goto error; } else dev_dbg(&port->dev, "ZLP_REG%d Writing success status%d\n", pnum + 2, status); } else { @@ -2216,7 +2233,7 @@ static int mos7840_port_probe(struct usb_serial_port *port) (__u16)(ZLP_REG1 + ((__u16) mos7840_port->port_num) - 0x1)); if (status < 0) { dev_dbg(&port->dev, "Writing ZLP_REG%d failed status-0x%x\n", pnum + 1, status); - goto out; + goto error; } else dev_dbg(&port->dev, "ZLP_REG%d Writing success status%d\n", pnum + 1, status); @@ -2254,17 +2271,7 @@ static int mos7840_port_probe(struct usb_serial_port *port) /* Turn off LED */ mos7840_set_led_sync(port, MODEM_CONTROL_REGISTER, 0x0300); } -out: - if (pnum == serial->num_ports - 1) { - /* Zero Length flag enable */ - Data = 0x0f; - status = mos7840_set_reg_sync(serial->port[0], ZLP_REG5, Data); - if (status < 0) { - dev_dbg(&port->dev, "Writing ZLP_REG5 failed status-0x%x\n", status); - goto error; - } else - dev_dbg(&port->dev, "ZLP_REG5 Writing success status%d\n", status); - } + return 0; error: kfree(mos7840_port->led_dr); @@ -2320,6 +2327,7 @@ static struct usb_serial_driver moschip7840_4port_device = { .unthrottle = mos7840_unthrottle, .calc_num_ports = mos7840_calc_num_ports, .probe = mos7840_probe, + .attach = mos7840_attach, .ioctl = mos7840_ioctl, .get_serial = mos7840_get_serial_info, .set_termios = mos7840_set_termios, From patchwork Thu Nov 7 13:28:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 11232791 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6D3C71747 for ; Thu, 7 Nov 2019 13:29:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3A03B21D79 for ; Thu, 7 Nov 2019 13:29:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573133374; bh=jvIEeFCw0ex+S9FClrELuB7B76/YYNGvzGeDMMBprlc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=MXLwqR2QRY2jmscjQJ7TldjWltSUENON7Nbgsto6uOE0VZLkkI8Efk2Zy82kVY/8C 6FC2jylxL2iFYt5g5PxMTmwsRgkHQwsIZHyMPJ2970Eus3T/v/EgZMCQ6z6LmvhWFg vwoCD6y7AJYN/ZWGSZVxyf93hTB1H/4e2SGSZOqE= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388446AbfKGN3d (ORCPT ); Thu, 7 Nov 2019 08:29:33 -0500 Received: from mail-lj1-f195.google.com ([209.85.208.195]:40432 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728687AbfKGN3d (ORCPT ); Thu, 7 Nov 2019 08:29:33 -0500 Received: by mail-lj1-f195.google.com with SMTP id q2so2269072ljg.7 for ; Thu, 07 Nov 2019 05:29:31 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gPkHGr+kZtYXp1ld78eLFZejzjsMmO71ZxEl+Do5Yd4=; b=dFCflJapnQVJVSMqfYRIySaHtcMF0GNQVQmcK5mq+BP9iB9gIOj1i1BBpGMFMOq2t4 MZj0ljcBC6Y7hbF66tXviDjofukmlL/NOpDbSTrsz+Ig7hy45ZrU9TpC3/c5BGl8qRPg dI1UlawSnvkxaBDhJ+B09awz4q0peav7Pj9ZkdJD741212okz1eqGlM7oATlatWOS7yD dx52rj1cKeaPJlRCXUCWrl+GQY+oojzE53HW1x1tS1wezmj+R/CvZNtagESG08WJ+1nv fqWQcB4YPhLPL+JPXKdMdRGaHRDpaOjZ2Wp3QDEzTjBYt/1ok69/+f1hRXKG66fPtukj K1ug== X-Gm-Message-State: APjAAAUG7r3NSNHi0TTY/mYPsydtlt4biI3ug/+4JrlrHHynj8elJfiu lk27NE12TgsFM9G+HCez7LI= X-Google-Smtp-Source: APXvYqyqk/S1bNpX84B28/h5BXtuB4SfT5og740EeFH0NJ5Xifj0Wz+sG2QJcEk3A28DqmDb8A7umA== X-Received: by 2002:a2e:9083:: with SMTP id l3mr2534109ljg.127.1573133370445; Thu, 07 Nov 2019 05:29:30 -0800 (PST) Received: from xi.terra (c-51f1e055.07-184-6d6c6d4.bbcust.telenor.se. [85.224.241.81]) by smtp.gmail.com with ESMTPSA id v203sm1093487lfa.25.2019.11.07.05.29.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Nov 2019 05:29:26 -0800 (PST) Received: from johan by xi.terra with local (Exim 4.92.3) (envelope-from ) id 1iShqn-0000df-HB; Thu, 07 Nov 2019 14:29:25 +0100 From: Johan Hovold To: Johan Hovold Cc: linux-usb@vger.kernel.org Subject: [PATCH 04/11] USB: serial: mos7840: rip out broken interrupt handling Date: Thu, 7 Nov 2019 14:28:57 +0100 Message-Id: <20191107132904.2379-5-johan@kernel.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191107132904.2379-1-johan@kernel.org> References: <20191107132904.2379-1-johan@kernel.org> MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The interrupt handling is completely broken and has in fact never been been enabled due to an inverted test for an interrupt endpoint in open() that prevented the interrupt URB from being submitted. Other highlights include missing interrupt URB resubmission (had it ever been submitted), missing locking when managing the open-port count, and NULL-pointer dereferences that could have been triggered by a malicious device. Rip out this broken crap which is beyond repair instead of pretending we support this feature. Signed-off-by: Johan Hovold --- drivers/usb/serial/mos7840.c | 294 +---------------------------------- 1 file changed, 3 insertions(+), 291 deletions(-) diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c index ddd8db3be110..9c5956fbd600 100644 --- a/drivers/usb/serial/mos7840.c +++ b/drivers/usb/serial/mos7840.c @@ -156,7 +156,6 @@ #define LED_OFF_MS 500 enum mos7840_flag { - MOS7840_FLAG_CTRL_BUSY, MOS7840_FLAG_LED_BUSY, }; @@ -200,18 +199,12 @@ struct moschip_port { __u8 shadowLCR; /* last LCR value received */ __u8 shadowMCR; /* last MCR value received */ char open; - char open_ports; struct usb_serial_port *port; /* loop back to the owner of this object */ /* Offsets */ __u8 SpRegOffset; __u8 ControlRegOffset; __u8 DcrRegOffset; - /* for processing control URBS in interrupt context */ - struct urb *control_urb; - struct usb_ctrlrequest *dr; - char *ctrl_buf; - int MsrLsr; spinlock_t pool_lock; struct urb *write_urb_pool[NUM_URBS]; @@ -371,55 +364,6 @@ static inline struct moschip_port *mos7840_get_port_private(struct return (struct moschip_port *)usb_get_serial_port_data(port); } -static void mos7840_handle_new_msr(struct moschip_port *port, __u8 new_msr) -{ - struct moschip_port *mos7840_port; - struct async_icount *icount; - mos7840_port = port; - if (new_msr & - (MOS_MSR_DELTA_CTS | MOS_MSR_DELTA_DSR | MOS_MSR_DELTA_RI | - MOS_MSR_DELTA_CD)) { - icount = &mos7840_port->port->icount; - - /* update input line counters */ - if (new_msr & MOS_MSR_DELTA_CTS) - icount->cts++; - if (new_msr & MOS_MSR_DELTA_DSR) - icount->dsr++; - if (new_msr & MOS_MSR_DELTA_CD) - icount->dcd++; - if (new_msr & MOS_MSR_DELTA_RI) - icount->rng++; - - wake_up_interruptible(&port->port->port.delta_msr_wait); - } -} - -static void mos7840_handle_new_lsr(struct moschip_port *port, __u8 new_lsr) -{ - struct async_icount *icount; - - if (new_lsr & SERIAL_LSR_BI) { - /* - * Parity and Framing errors only count if they - * occur exclusive of a break being - * received. - */ - new_lsr &= (__u8) (SERIAL_LSR_OE | SERIAL_LSR_BI); - } - - /* update input line counters */ - icount = &port->port->icount; - if (new_lsr & SERIAL_LSR_BI) - icount->brk++; - if (new_lsr & SERIAL_LSR_OE) - icount->overrun++; - if (new_lsr & SERIAL_LSR_PE) - icount->parity++; - if (new_lsr & SERIAL_LSR_FE) - icount->frame++; -} - /************************************************************************/ /************************************************************************/ /* U S B C A L L B A C K F U N C T I O N S */ @@ -427,76 +371,6 @@ static void mos7840_handle_new_lsr(struct moschip_port *port, __u8 new_lsr) /************************************************************************/ /************************************************************************/ -static void mos7840_control_callback(struct urb *urb) -{ - unsigned char *data; - struct moschip_port *mos7840_port; - struct device *dev = &urb->dev->dev; - __u8 regval = 0x0; - int status = urb->status; - - mos7840_port = urb->context; - - switch (status) { - case 0: - /* success */ - break; - case -ECONNRESET: - case -ENOENT: - case -ESHUTDOWN: - /* this urb is terminated, clean up */ - dev_dbg(dev, "%s - urb shutting down with status: %d\n", __func__, status); - goto out; - default: - dev_dbg(dev, "%s - nonzero urb status received: %d\n", __func__, status); - goto out; - } - - dev_dbg(dev, "%s urb buffer size is %d\n", __func__, urb->actual_length); - if (urb->actual_length < 1) - goto out; - - dev_dbg(dev, "%s mos7840_port->MsrLsr is %d port %d\n", __func__, - mos7840_port->MsrLsr, mos7840_port->port_num); - data = urb->transfer_buffer; - regval = (__u8) data[0]; - dev_dbg(dev, "%s data is %x\n", __func__, regval); - if (mos7840_port->MsrLsr == 0) - mos7840_handle_new_msr(mos7840_port, regval); - else if (mos7840_port->MsrLsr == 1) - mos7840_handle_new_lsr(mos7840_port, regval); -out: - clear_bit_unlock(MOS7840_FLAG_CTRL_BUSY, &mos7840_port->flags); -} - -static int mos7840_get_reg(struct moschip_port *mcs, __u16 Wval, __u16 reg, - __u16 *val) -{ - struct usb_device *dev = mcs->port->serial->dev; - struct usb_ctrlrequest *dr = mcs->dr; - unsigned char *buffer = mcs->ctrl_buf; - int ret; - - if (test_and_set_bit_lock(MOS7840_FLAG_CTRL_BUSY, &mcs->flags)) - return -EBUSY; - - dr->bRequestType = MCS_RD_RTYPE; - dr->bRequest = MCS_RDREQ; - dr->wValue = cpu_to_le16(Wval); /* 0 */ - dr->wIndex = cpu_to_le16(reg); - dr->wLength = cpu_to_le16(2); - - usb_fill_control_urb(mcs->control_urb, dev, usb_rcvctrlpipe(dev, 0), - (unsigned char *)dr, buffer, 2, - mos7840_control_callback, mcs); - mcs->control_urb->transfer_buffer_length = 2; - ret = usb_submit_urb(mcs->control_urb, GFP_ATOMIC); - if (ret) - clear_bit_unlock(MOS7840_FLAG_CTRL_BUSY, &mcs->flags); - - return ret; -} - static void mos7840_set_led_callback(struct urb *urb) { switch (urb->status) { @@ -572,100 +446,6 @@ static void mos7840_led_activity(struct usb_serial_port *port) jiffies + msecs_to_jiffies(LED_ON_MS)); } -/***************************************************************************** - * mos7840_interrupt_callback - * this is the callback function for when we have received data on the - * interrupt endpoint. - *****************************************************************************/ - -static void mos7840_interrupt_callback(struct urb *urb) -{ - int result; - int length; - struct moschip_port *mos7840_port; - struct usb_serial *serial; - __u16 Data; - unsigned char *data; - __u8 sp[5]; - int i, rv = 0; - __u16 wval, wreg = 0; - int status = urb->status; - - switch (status) { - case 0: - /* success */ - break; - case -ECONNRESET: - case -ENOENT: - case -ESHUTDOWN: - /* this urb is terminated, clean up */ - dev_dbg(&urb->dev->dev, "%s - urb shutting down with status: %d\n", - __func__, status); - return; - default: - dev_dbg(&urb->dev->dev, "%s - nonzero urb status received: %d\n", - __func__, status); - goto exit; - } - - length = urb->actual_length; - data = urb->transfer_buffer; - - serial = urb->context; - - /* Moschip get 5 bytes - * Byte 1 IIR Port 1 (port.number is 0) - * Byte 2 IIR Port 2 (port.number is 1) - * Byte 3 IIR Port 3 (port.number is 2) - * Byte 4 IIR Port 4 (port.number is 3) - * Byte 5 FIFO status for both */ - - if (length > 5) { - dev_dbg(&urb->dev->dev, "%s", "Wrong data !!!\n"); - return; - } - - sp[0] = (__u8) data[0]; - sp[1] = (__u8) data[1]; - sp[2] = (__u8) data[2]; - sp[3] = (__u8) data[3]; - - for (i = 0; i < serial->num_ports; i++) { - mos7840_port = mos7840_get_port_private(serial->port[i]); - wval = ((__u16)serial->port[i]->port_number + 1) << 8; - if (mos7840_port->open) { - if (sp[i] & 0x01) { - dev_dbg(&urb->dev->dev, "SP%d No Interrupt !!!\n", i); - } else { - switch (sp[i] & 0x0f) { - case SERIAL_IIR_RLS: - dev_dbg(&urb->dev->dev, "Serial Port %d: Receiver status error or \n", i); - dev_dbg(&urb->dev->dev, "address bit detected in 9-bit mode\n"); - mos7840_port->MsrLsr = 1; - wreg = LINE_STATUS_REGISTER; - break; - case SERIAL_IIR_MS: - dev_dbg(&urb->dev->dev, "Serial Port %d: Modem status change\n", i); - mos7840_port->MsrLsr = 0; - wreg = MODEM_STATUS_REGISTER; - break; - } - rv = mos7840_get_reg(mos7840_port, wval, wreg, &Data); - } - } - } - if (!(rv < 0)) - /* the completion handler for the control urb will resubmit */ - return; -exit: - result = usb_submit_urb(urb, GFP_ATOMIC); - if (result) { - dev_err(&urb->dev->dev, - "%s - Error %d submitting interrupt urb\n", - __func__, result); - } -} - static int mos7840_port_paranoia_check(struct usb_serial_port *port, const char *function) { @@ -836,7 +616,6 @@ static int mos7840_open(struct tty_struct *tty, struct usb_serial_port *port) __u16 Data; int status; struct moschip_port *mos7840_port; - struct moschip_port *port0; if (mos7840_port_paranoia_check(port, __func__)) return -ENODEV; @@ -847,14 +626,11 @@ static int mos7840_open(struct tty_struct *tty, struct usb_serial_port *port) return -ENODEV; mos7840_port = mos7840_get_port_private(port); - port0 = mos7840_get_port_private(serial->port[0]); - - if (mos7840_port == NULL || port0 == NULL) + if (mos7840_port == NULL) return -ENODEV; usb_clear_halt(serial->dev, port->write_urb->pipe); usb_clear_halt(serial->dev, port->read_urb->pipe); - port0->open_ports++; /* Initialising the write urb pool */ for (j = 0; j < NUM_URBS; ++j) { @@ -1005,41 +781,6 @@ static int mos7840_open(struct tty_struct *tty, struct usb_serial_port *port) status = mos7840_set_reg_sync(port, mos7840_port->ControlRegOffset, Data); - /* Check to see if we've set up our endpoint info yet * - * (can't set it up in mos7840_startup as the structures * - * were not set up at that time.) */ - if (port0->open_ports == 1) { - /* FIXME: Buffer never NULL, so URB is not submitted. */ - if (serial->port[0]->interrupt_in_buffer == NULL) { - /* set up interrupt urb */ - usb_fill_int_urb(serial->port[0]->interrupt_in_urb, - serial->dev, - usb_rcvintpipe(serial->dev, - serial->port[0]->interrupt_in_endpointAddress), - serial->port[0]->interrupt_in_buffer, - serial->port[0]->interrupt_in_urb-> - transfer_buffer_length, - mos7840_interrupt_callback, - serial, - serial->port[0]->interrupt_in_urb->interval); - - /* start interrupt read for mos7840 */ - response = - usb_submit_urb(serial->port[0]->interrupt_in_urb, - GFP_KERNEL); - if (response) { - dev_err(&port->dev, "%s - Error %d submitting " - "interrupt urb\n", __func__, response); - } - - } - - } - - /* see if we've set up our endpoint info yet * - * (can't set it up in mos7840_startup as the * - * structures were not set up at that time.) */ - dev_dbg(&port->dev, "port number is %d\n", port->port_number); dev_dbg(&port->dev, "minor number is %d\n", port->minor); dev_dbg(&port->dev, "Bulkin endpoint is %d\n", port->bulk_in_endpointAddress); @@ -1142,7 +883,6 @@ static void mos7840_close(struct usb_serial_port *port) { struct usb_serial *serial; struct moschip_port *mos7840_port; - struct moschip_port *port0; int j; __u16 Data; @@ -1154,9 +894,7 @@ static void mos7840_close(struct usb_serial_port *port) return; mos7840_port = mos7840_get_port_private(port); - port0 = mos7840_get_port_private(serial->port[0]); - - if (mos7840_port == NULL || port0 == NULL) + if (mos7840_port == NULL) return; for (j = 0; j < NUM_URBS; ++j) @@ -1173,15 +911,6 @@ static void mos7840_close(struct usb_serial_port *port) usb_kill_urb(mos7840_port->read_urb); mos7840_port->read_urb_busy = false; - port0->open_ports--; - dev_dbg(&port->dev, "%s in close%d\n", __func__, port0->open_ports); - if (port0->open_ports == 0) { - if (serial->port[0]->interrupt_in_urb) { - dev_dbg(&port->dev, "Shutdown interrupt_in_urb\n"); - usb_kill_urb(serial->port[0]->interrupt_in_urb); - } - } - Data = 0x0; mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data); @@ -2238,15 +1967,6 @@ static int mos7840_port_probe(struct usb_serial_port *port) dev_dbg(&port->dev, "ZLP_REG%d Writing success status%d\n", pnum + 1, status); } - mos7840_port->control_urb = usb_alloc_urb(0, GFP_KERNEL); - mos7840_port->ctrl_buf = kmalloc(16, GFP_KERNEL); - mos7840_port->dr = kmalloc(sizeof(struct usb_ctrlrequest), - GFP_KERNEL); - if (!mos7840_port->control_urb || !mos7840_port->ctrl_buf || - !mos7840_port->dr) { - status = -ENOMEM; - goto error; - } mos7840_port->has_led = device_flags & MCS_LED; @@ -2276,9 +1996,6 @@ static int mos7840_port_probe(struct usb_serial_port *port) error: kfree(mos7840_port->led_dr); usb_free_urb(mos7840_port->led_urb); - kfree(mos7840_port->dr); - kfree(mos7840_port->ctrl_buf); - usb_free_urb(mos7840_port->control_urb); kfree(mos7840_port); return status; @@ -2301,10 +2018,7 @@ static int mos7840_port_remove(struct usb_serial_port *port) usb_free_urb(mos7840_port->led_urb); kfree(mos7840_port->led_dr); } - usb_kill_urb(mos7840_port->control_urb); - usb_free_urb(mos7840_port->control_urb); - kfree(mos7840_port->ctrl_buf); - kfree(mos7840_port->dr); + kfree(mos7840_port); return 0; @@ -2334,12 +2048,10 @@ static struct usb_serial_driver moschip7840_4port_device = { .break_ctl = mos7840_break, .tiocmget = mos7840_tiocmget, .tiocmset = mos7840_tiocmset, - .tiocmiwait = usb_serial_generic_tiocmiwait, .get_icount = usb_serial_generic_get_icount, .port_probe = mos7840_port_probe, .port_remove = mos7840_port_remove, .read_bulk_callback = mos7840_bulk_in_callback, - .read_int_callback = mos7840_interrupt_callback, }; static struct usb_serial_driver * const serial_drivers[] = { From patchwork Thu Nov 7 13:28:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 11232805 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AE43C1850 for ; Thu, 7 Nov 2019 13:29:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 832A12178F for ; Thu, 7 Nov 2019 13:29:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573133379; bh=sHJERiPacoO9v0qnCHHBFA2Cul5DpFAVXgHrfyueH/c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=o3EOmpN5DADhvmcvRLWkhoWNTNppktUqWtaEPGPxGmE15Lf5Qm1BwvK4bCdUfzYDJ /MM+7GUG8AnqU0f/bCgRTrCbaqegaOhEBjnOXeStjnEy0VLSzol7EucbiYDdV/IQ8y fM21SPJLQoSSBd453Loj5OXf7q53ZiS8QGFk4NPk= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388750AbfKGN3i (ORCPT ); Thu, 7 Nov 2019 08:29:38 -0500 Received: from mail-lj1-f193.google.com ([209.85.208.193]:45169 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388525AbfKGN3i (ORCPT ); Thu, 7 Nov 2019 08:29:38 -0500 Received: by mail-lj1-f193.google.com with SMTP id n21so2252811ljg.12 for ; Thu, 07 Nov 2019 05:29:35 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=KMldmjZNEDlQPHZw4y7grynkhWU7xoAmhFJtHHyHyMY=; b=LYv0aB7gmqJji3Fhyik4Ash8n7tnWt1pgM56hQyVGIj8IbrLLDvVdFyUerwQXskuLZ WwAl6ZlKxkzfrTwgEGiAB+a5HvuyWJeRctXkyBGnoegIp5WaCQUJIvjqpQmDZMXJFsL8 SjW3oqcHe8i9sDWihv5WLHzHCEV8V2Q/A1TAwrZOJUaST7dJtncZnASPBbhobaNKZuVX /g+ODFt9aa6b3tiBB2m6WVqfCis2GY3kYBuiPBLb7hVRpsa5U5Qi4C7qsRJMx2uVseGq gvJEupAceaxrJjmH85umG1FessKKtLRF5Cc+3nXd1rgrAmpKR3DizcliwulLfwK1wsqM khXA== X-Gm-Message-State: APjAAAWKOk9eu1kWtWJdVa6LrUF1ikhVlfiyRuj4Gg5JExOAWEzcJrta kxgKPzD38FeEpsRGbaaobZ8= X-Google-Smtp-Source: APXvYqwctiqQiqO9QZbEe2PJEZjZciyTHtcInuxQbhDSypJGYVZ13fhV9R21JY9C5D3RfQNPC0iDrQ== X-Received: by 2002:a2e:9112:: with SMTP id m18mr2565052ljg.75.1573133374533; Thu, 07 Nov 2019 05:29:34 -0800 (PST) Received: from xi.terra (c-51f1e055.07-184-6d6c6d4.bbcust.telenor.se. [85.224.241.81]) by smtp.gmail.com with ESMTPSA id y17sm918053lfy.58.2019.11.07.05.29.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Nov 2019 05:29:28 -0800 (PST) Received: from johan by xi.terra with local (Exim 4.92.3) (envelope-from ) id 1iShqn-0000dj-KQ; Thu, 07 Nov 2019 14:29:25 +0100 From: Johan Hovold To: Johan Hovold Cc: linux-usb@vger.kernel.org Subject: [PATCH 05/11] USB: serial: mos7840: drop redundant urb context check Date: Thu, 7 Nov 2019 14:28:58 +0100 Message-Id: <20191107132904.2379-6-johan@kernel.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191107132904.2379-1-johan@kernel.org> References: <20191107132904.2379-1-johan@kernel.org> MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The bulk-in URB context is set to the driver-data struct at open and is never cleared so drop the redundant check in the completion callback. Signed-off-by: Johan Hovold --- drivers/usb/serial/mos7840.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c index 9c5956fbd600..92180687097f 100644 --- a/drivers/usb/serial/mos7840.c +++ b/drivers/usb/serial/mos7840.c @@ -500,17 +500,13 @@ static struct usb_serial *mos7840_get_usb_serial(struct usb_serial_port *port, static void mos7840_bulk_in_callback(struct urb *urb) { + struct moschip_port *mos7840_port = urb->context; int retval; unsigned char *data; struct usb_serial *serial; struct usb_serial_port *port; - struct moschip_port *mos7840_port; int status = urb->status; - mos7840_port = urb->context; - if (!mos7840_port) - return; - if (status) { dev_dbg(&urb->dev->dev, "nonzero read bulk status received: %d\n", status); mos7840_port->read_urb_busy = false; From patchwork Thu Nov 7 13:28:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 11232797 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E63231986 for ; Thu, 7 Nov 2019 13:29:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C422F21D79 for ; Thu, 7 Nov 2019 13:29:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573133375; bh=cHyqyoSmeRvFLH4fxgjOJdXlw8bxGP24DP/ugNsCqJs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=Qkpvf/yGR422j/dOfPTyh5RiWfrqFqkHHZMwcyxsJBstqpPK8j4sGZk/32NpsX633 HlsxAjeOfitlm0xPyP6DBpwkvUmIdwc/k2lcIxsGbeBg/Hiz8JDrk1Z9u2TmMm/zMl Y5ZGSEwKxMwnMfney6avjtAoUcrKI9W3ODP6PPKU= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388668AbfKGN3f (ORCPT ); Thu, 7 Nov 2019 08:29:35 -0500 Received: from mail-lj1-f195.google.com ([209.85.208.195]:42633 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388008AbfKGN3e (ORCPT ); Thu, 7 Nov 2019 08:29:34 -0500 Received: by mail-lj1-f195.google.com with SMTP id n5so2261302ljc.9 for ; Thu, 07 Nov 2019 05:29:31 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jfFfffzVTcOgudBE4JWMItypAKlcFqsOjrXitM3DElM=; b=fbZ5rglsr/BStOFRhzpVL8HdFNtGwqQHiEeW4wqHapRKCEFE59vaVxlQDL+uj+DKS9 FS55oWL6FskImSe5lBbLIzMGDPix5EGzRnrcJ+WIEbcf6HQAgQeBpzDqvP/QdRokpjJP C0bIEx/B21MpSIUPIPlt/uE39xxGBGiHktBTmIeUSgNjZphIwdwzD7DdmeriJc9XHe51 pDCcpp86JEMQkeOpEn0+yvCgW5DT4wSuAflzMlm1qdutI0I3wfmXBrl5HaWhxhBf9arP KSF2vfhhc/wPpHv4ES61sNaIsrOiZw1hOEJjxy251CVx1V7+zMROldiiM6Ir/Q+EqWDg Tabg== X-Gm-Message-State: APjAAAXMncrr06Sy+tV/I4dQ8Y0RG2ijUoSxsPfsK8/HZajRDxxD/FSi MANJJNL2bzVIxrJvyBu+NJo= X-Google-Smtp-Source: APXvYqzTOvv6eD9J6GtQBHPyYrWAdQLjP/f6B1JbkDgOtI22oKoRrD53JZIqNTlHorBnGskksnmqAg== X-Received: by 2002:a2e:a304:: with SMTP id l4mr2436754lje.178.1573133371058; Thu, 07 Nov 2019 05:29:31 -0800 (PST) Received: from xi.terra (c-51f1e055.07-184-6d6c6d4.bbcust.telenor.se. [85.224.241.81]) by smtp.gmail.com with ESMTPSA id e14sm1652147ljb.75.2019.11.07.05.29.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Nov 2019 05:29:28 -0800 (PST) Received: from johan by xi.terra with local (Exim 4.92.3) (envelope-from ) id 1iShqn-0000dp-Nl; Thu, 07 Nov 2019 14:29:25 +0100 From: Johan Hovold To: Johan Hovold Cc: linux-usb@vger.kernel.org Subject: [PATCH 06/11] USB: serial: mos7840: drop paranoid port checks Date: Thu, 7 Nov 2019 14:28:59 +0100 Message-Id: <20191107132904.2379-7-johan@kernel.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191107132904.2379-1-johan@kernel.org> References: <20191107132904.2379-1-johan@kernel.org> MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Drop the paranoid port structure sanity checks which are confusing at best. The driver data port pointer is set at port probe and never cleared, while USB serial core sets the tty driver data at install and won't call any driver functions with a NULL port pointer. Signed-off-by: Johan Hovold --- drivers/usb/serial/mos7840.c | 92 ++++-------------------------------- 1 file changed, 8 insertions(+), 84 deletions(-) diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c index 92180687097f..dcb1e04a0514 100644 --- a/drivers/usb/serial/mos7840.c +++ b/drivers/usb/serial/mos7840.c @@ -446,21 +446,6 @@ static void mos7840_led_activity(struct usb_serial_port *port) jiffies + msecs_to_jiffies(LED_ON_MS)); } -static int mos7840_port_paranoia_check(struct usb_serial_port *port, - const char *function) -{ - if (!port) { - pr_debug("%s - port == NULL\n", function); - return -1; - } - if (!port->serial) { - pr_debug("%s - port->serial == NULL\n", function); - return -1; - } - - return 0; -} - /* Inline functions to check the sanity of a pointer that is passed to us */ static int mos7840_serial_paranoia_check(struct usb_serial *serial, const char *function) @@ -482,7 +467,6 @@ static struct usb_serial *mos7840_get_usb_serial(struct usb_serial_port *port, { /* if no port was specified, or it fails a paranoia check */ if (!port || - mos7840_port_paranoia_check(port, function) || mos7840_serial_paranoia_check(port->serial, function)) { /* then say that we don't have a valid usb_serial thing, * which will end up genrating -ENODEV return values */ @@ -501,10 +485,10 @@ static struct usb_serial *mos7840_get_usb_serial(struct usb_serial_port *port, static void mos7840_bulk_in_callback(struct urb *urb) { struct moschip_port *mos7840_port = urb->context; + struct usb_serial_port *port = mos7840_port->port; int retval; unsigned char *data; struct usb_serial *serial; - struct usb_serial_port *port; int status = urb->status; if (status) { @@ -513,12 +497,6 @@ static void mos7840_bulk_in_callback(struct urb *urb) return; } - port = mos7840_port->port; - if (mos7840_port_paranoia_check(port, __func__)) { - mos7840_port->read_urb_busy = false; - return; - } - serial = mos7840_get_usb_serial(port, __func__); if (!serial) { mos7840_port->read_urb_busy = false; @@ -562,14 +540,12 @@ static void mos7840_bulk_in_callback(struct urb *urb) static void mos7840_bulk_out_data_callback(struct urb *urb) { - struct moschip_port *mos7840_port; - struct usb_serial_port *port; + struct moschip_port *mos7840_port = urb->context; + struct usb_serial_port *port = mos7840_port->port; int status = urb->status; unsigned long flags; int i; - mos7840_port = urb->context; - port = mos7840_port->port; spin_lock_irqsave(&mos7840_port->pool_lock, flags); for (i = 0; i < NUM_URBS; i++) { if (urb == mos7840_port->write_urb_pool[i]) { @@ -584,9 +560,6 @@ static void mos7840_bulk_out_data_callback(struct urb *urb) return; } - if (mos7840_port_paranoia_check(port, __func__)) - return; - if (mos7840_port->open) tty_port_tty_wakeup(&port->port); @@ -605,19 +578,14 @@ static void mos7840_bulk_out_data_callback(struct urb *urb) static int mos7840_open(struct tty_struct *tty, struct usb_serial_port *port) { + struct usb_serial *serial = port->serial; int response; int j; - struct usb_serial *serial; struct urb *urb; __u16 Data; int status; struct moschip_port *mos7840_port; - if (mos7840_port_paranoia_check(port, __func__)) - return -ENODEV; - - serial = port->serial; - if (mos7840_serial_paranoia_check(serial, __func__)) return -ENODEV; @@ -850,9 +818,6 @@ static int mos7840_chars_in_buffer(struct tty_struct *tty) unsigned long flags; struct moschip_port *mos7840_port; - if (mos7840_port_paranoia_check(port, __func__)) - return 0; - mos7840_port = mos7840_get_port_private(port); if (mos7840_port == NULL) return 0; @@ -882,9 +847,6 @@ static void mos7840_close(struct usb_serial_port *port) int j; __u16 Data; - if (mos7840_port_paranoia_check(port, __func__)) - return; - serial = mos7840_get_usb_serial(port, __func__); if (!serial) return; @@ -927,9 +889,6 @@ static void mos7840_break(struct tty_struct *tty, int break_state) struct usb_serial *serial; struct moschip_port *mos7840_port; - if (mos7840_port_paranoia_check(port, __func__)) - return; - serial = mos7840_get_usb_serial(port, __func__); if (!serial) return; @@ -967,9 +926,6 @@ static int mos7840_write_room(struct tty_struct *tty) unsigned long flags; struct moschip_port *mos7840_port; - if (mos7840_port_paranoia_check(port, __func__)) - return -1; - mos7840_port = mos7840_get_port_private(port); if (mos7840_port == NULL) return -1; @@ -998,6 +954,7 @@ static int mos7840_write_room(struct tty_struct *tty) static int mos7840_write(struct tty_struct *tty, struct usb_serial_port *port, const unsigned char *data, int count) { + struct usb_serial *serial = port->serial; int status; int i; int bytes_sent = 0; @@ -1005,15 +962,10 @@ static int mos7840_write(struct tty_struct *tty, struct usb_serial_port *port, unsigned long flags; struct moschip_port *mos7840_port; - struct usb_serial *serial; struct urb *urb; /* __u16 Data; */ const unsigned char *current_position = data; - if (mos7840_port_paranoia_check(port, __func__)) - return -1; - - serial = port->serial; if (mos7840_serial_paranoia_check(serial, __func__)) return -1; @@ -1104,9 +1056,6 @@ static void mos7840_throttle(struct tty_struct *tty) struct moschip_port *mos7840_port; int status; - if (mos7840_port_paranoia_check(port, __func__)) - return; - mos7840_port = mos7840_get_port_private(port); if (mos7840_port == NULL) @@ -1146,9 +1095,6 @@ static void mos7840_unthrottle(struct tty_struct *tty) int status; struct moschip_port *mos7840_port = mos7840_get_port_private(port); - if (mos7840_port_paranoia_check(port, __func__)) - return; - if (mos7840_port == NULL) return; @@ -1296,18 +1242,11 @@ static int mos7840_calc_baud_rate_divisor(struct usb_serial_port *port, static int mos7840_send_cmd_write_baud_rate(struct moschip_port *mos7840_port, int baudRate) { + struct usb_serial_port *port = mos7840_port->port; int divisor = 0; int status; __u16 Data; __u16 clk_sel_val; - struct usb_serial_port *port; - - if (mos7840_port == NULL) - return -1; - - port = mos7840_port->port; - if (mos7840_port_paranoia_check(port, __func__)) - return -1; if (mos7840_serial_paranoia_check(port->serial, __func__)) return -1; @@ -1399,6 +1338,7 @@ static int mos7840_send_cmd_write_baud_rate(struct moschip_port *mos7840_port, static void mos7840_change_port_settings(struct tty_struct *tty, struct moschip_port *mos7840_port, struct ktermios *old_termios) { + struct usb_serial_port *port = mos7840_port->port; int baud; unsigned cflag; __u8 lData; @@ -1406,15 +1346,6 @@ static void mos7840_change_port_settings(struct tty_struct *tty, __u8 lStop; int status; __u16 Data; - struct usb_serial_port *port; - - if (mos7840_port == NULL) - return; - - port = mos7840_port->port; - - if (mos7840_port_paranoia_check(port, __func__)) - return; if (mos7840_serial_paranoia_check(port->serial, __func__)) return; @@ -1557,14 +1488,10 @@ static void mos7840_set_termios(struct tty_struct *tty, struct usb_serial_port *port, struct ktermios *old_termios) { + struct usb_serial *serial = port->serial; int status; - struct usb_serial *serial; struct moschip_port *mos7840_port; - if (mos7840_port_paranoia_check(port, __func__)) - return; - - serial = port->serial; if (mos7840_serial_paranoia_check(serial, __func__)) return; @@ -1659,9 +1586,6 @@ static int mos7840_ioctl(struct tty_struct *tty, void __user *argp = (void __user *)arg; struct moschip_port *mos7840_port; - if (mos7840_port_paranoia_check(port, __func__)) - return -1; - mos7840_port = mos7840_get_port_private(port); if (mos7840_port == NULL) From patchwork Thu Nov 7 13:29:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 11232793 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 73B581747 for ; Thu, 7 Nov 2019 13:29:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 534AD218AE for ; Thu, 7 Nov 2019 13:29:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573133375; bh=EE/mcYDD2FNZ/eEMB6mcmSYW1yegntxOs4ongApJqtY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=PaOUWlc69ZvQtlEkJX2i81zhAzsBGHzmfhXoKu0onpNBZreawkSen6BB3wmbrrM6t 9DEddaSs3dlAljpjBhQQyyx/ZtcG2qy8dVE8J/0+QdOeXfxDeOOjVXpFuNB/34tw8r PdR26m9tZlHZyGZcv7wL3Sq+7qroFaPU4FZr89cg= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388504AbfKGN3e (ORCPT ); Thu, 7 Nov 2019 08:29:34 -0500 Received: from mail-lf1-f68.google.com ([209.85.167.68]:41120 "EHLO mail-lf1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728568AbfKGN3e (ORCPT ); Thu, 7 Nov 2019 08:29:34 -0500 Received: by mail-lf1-f68.google.com with SMTP id j14so1591568lfb.8 for ; Thu, 07 Nov 2019 05:29:33 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gVxCcGkHQM/3+rGEIzFNU8KiSHclyzKNkWX8dKWpChQ=; b=EMwKD72OVaduri0JCeJ84dTjLlulaHU7pojL0suXT0hHvuurd9vgVbXde8/Nmteyw3 LXACvTQQFuVLEF63RjO3VDM4Itdb27H5JKKdEM1fXZK73NixVoiMZarHnnupuYT9rKRD 5/lJdOFz+HDiIEsMGu87fP8+UUOylcCjZYoG7vAxZ+jv2iisnwOSVpgwa7v1svC/4ZCK BXxygFhxaYOZIIxEMKz0hpwUQAxhvzPHfbhVa0O0xyZfU5fzC3NscsCIkJncykO+Ac+V pOezJqM4vKs+bDH/Lktjqp8SPw+wA43Mqbd+ZLfg9lLv6uo03g3raiWmIJJmYZWwKkeO 2CCg== X-Gm-Message-State: APjAAAXjlDJ+7k/BlbFMdIe/upfDM8ZinUTjCQa6GQeqSV3wz936BchA qSJGhPvoWRDs9R+6We7du+4= X-Google-Smtp-Source: APXvYqxHK4hts7imHkGOM+6ubdtYS4G8/k5AjBnrFwMWJYDr5JX4epiRMtkSzxhZ+QedytY9yHuXWg== X-Received: by 2002:a19:820e:: with SMTP id e14mr2449169lfd.29.1573133372409; Thu, 07 Nov 2019 05:29:32 -0800 (PST) Received: from xi.terra (c-51f1e055.07-184-6d6c6d4.bbcust.telenor.se. [85.224.241.81]) by smtp.gmail.com with ESMTPSA id a22sm977434ljn.58.2019.11.07.05.29.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Nov 2019 05:29:28 -0800 (PST) Received: from johan by xi.terra with local (Exim 4.92.3) (envelope-from ) id 1iShqn-0000dt-Qa; Thu, 07 Nov 2019 14:29:25 +0100 From: Johan Hovold To: Johan Hovold Cc: linux-usb@vger.kernel.org Subject: [PATCH 07/11] USB: serial: mos7840: drop paranoid serial checks Date: Thu, 7 Nov 2019 14:29:00 +0100 Message-Id: <20191107132904.2379-8-johan@kernel.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191107132904.2379-1-johan@kernel.org> References: <20191107132904.2379-1-johan@kernel.org> MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Drop the likewise paranoid serial structure sanity checks. USB serial core sets the serial pointer in the port structures at initialisation and it is never cleared, and similar for the serial structure type. Signed-off-by: Johan Hovold --- drivers/usb/serial/mos7840.c | 38 ++---------------------------------- 1 file changed, 2 insertions(+), 36 deletions(-) diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c index dcb1e04a0514..207b88d948a9 100644 --- a/drivers/usb/serial/mos7840.c +++ b/drivers/usb/serial/mos7840.c @@ -446,28 +446,11 @@ static void mos7840_led_activity(struct usb_serial_port *port) jiffies + msecs_to_jiffies(LED_ON_MS)); } -/* Inline functions to check the sanity of a pointer that is passed to us */ -static int mos7840_serial_paranoia_check(struct usb_serial *serial, - const char *function) -{ - if (!serial) { - pr_debug("%s - serial == NULL\n", function); - return -1; - } - if (!serial->type) { - pr_debug("%s - serial->type == NULL!\n", function); - return -1; - } - - return 0; -} - static struct usb_serial *mos7840_get_usb_serial(struct usb_serial_port *port, const char *function) { - /* if no port was specified, or it fails a paranoia check */ - if (!port || - mos7840_serial_paranoia_check(port->serial, function)) { + /* if no port was specified */ + if (!port) { /* then say that we don't have a valid usb_serial thing, * which will end up genrating -ENODEV return values */ return NULL; @@ -586,9 +569,6 @@ static int mos7840_open(struct tty_struct *tty, struct usb_serial_port *port) int status; struct moschip_port *mos7840_port; - if (mos7840_serial_paranoia_check(serial, __func__)) - return -ENODEV; - mos7840_port = mos7840_get_port_private(port); if (mos7840_port == NULL) return -ENODEV; @@ -966,9 +946,6 @@ static int mos7840_write(struct tty_struct *tty, struct usb_serial_port *port, /* __u16 Data; */ const unsigned char *current_position = data; - if (mos7840_serial_paranoia_check(serial, __func__)) - return -1; - mos7840_port = mos7840_get_port_private(port); if (mos7840_port == NULL) return -1; @@ -1248,9 +1225,6 @@ static int mos7840_send_cmd_write_baud_rate(struct moschip_port *mos7840_port, __u16 Data; __u16 clk_sel_val; - if (mos7840_serial_paranoia_check(port->serial, __func__)) - return -1; - dev_dbg(&port->dev, "%s - baud = %d\n", __func__, baudRate); /* reset clk_uart_sel in spregOffset */ if (baudRate > 115200) { @@ -1347,9 +1321,6 @@ static void mos7840_change_port_settings(struct tty_struct *tty, int status; __u16 Data; - if (mos7840_serial_paranoia_check(port->serial, __func__)) - return; - if (!mos7840_port->open) { dev_dbg(&port->dev, "%s - port not opened\n", __func__); return; @@ -1488,14 +1459,9 @@ static void mos7840_set_termios(struct tty_struct *tty, struct usb_serial_port *port, struct ktermios *old_termios) { - struct usb_serial *serial = port->serial; int status; struct moschip_port *mos7840_port; - - if (mos7840_serial_paranoia_check(serial, __func__)) - return; - mos7840_port = mos7840_get_port_private(port); if (mos7840_port == NULL) From patchwork Thu Nov 7 13:29:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 11232803 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3288B1747 for ; Thu, 7 Nov 2019 13:29:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 115642178F for ; Thu, 7 Nov 2019 13:29:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573133378; bh=1kb4+8WHIR+ybyNn10No8OEo5iO0AfwJLJ21v8QZFEo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=RYB7zUIxXC6/KPq/QMDyaNcHxeJqnVcaK41CdL+/xKOZ0QfgaGuHGE+LLZ6PGIjny JNXADnufGDaAzwOOwjsRfjjv0WwlYpeiQ3f4FSkUyHqVbceZ+G9mXLWRBHNcnIErVa OBy3cmPd6C7CcMhgfOayvZuBp8XWw+p1KkpArMAQ= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388708AbfKGN3h (ORCPT ); Thu, 7 Nov 2019 08:29:37 -0500 Received: from mail-lj1-f195.google.com ([209.85.208.195]:37246 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388008AbfKGN3g (ORCPT ); Thu, 7 Nov 2019 08:29:36 -0500 Received: by mail-lj1-f195.google.com with SMTP id l20so2281514lje.4 for ; Thu, 07 Nov 2019 05:29:35 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QHlkzVPGYoZV2+CMcfwNeUR5UtQIb8x4XIcb1f9JufI=; b=ozK6YCPl4PBkEhxS8ZMTAv4RH0bEXYBJSi+SOGTcEtyRZkNSwOoTX6L5tDNqNrvx5M OVLndalqIIyY0dCfGxoEYFLNkY7KV1c8F13zS9pi8fYlx+rXxvuJdBLKbryA8dfSE1DP mCdO0wyZ8AsYIqVETLkk1aYeXoNpOy2ufTDKBBx70+FbZmTj1rMfcjVhY7oK7i/h6RBL yIxaftAvknuy/s7cxap0Wflxy9s+HVW8k0Jw2ayb7MQmhqg7AmcdfVsjmJyeDGMUZ6Uw ruv7GoOKTi3CiPM8KoqmDlmPmWY+ZjzQtsxe2Zn3Ye6UUCIutA/hFCbxwrnVJNqbi9Qc T4vw== X-Gm-Message-State: APjAAAV5lbowWV9FNVcuC/6MFgAUBJD1AGOy8bF4F9j9isxYIhJEO3+M ks2M9XClYrJKUdlijqXDOd2nDaxX X-Google-Smtp-Source: APXvYqwm4FRA0fgAB9yLBQDqx5SS0jU2ep2o2q3pu+wRr4MB59+K/yj8sWFlAaBew6ZxybF+SYxw+A== X-Received: by 2002:a2e:9784:: with SMTP id y4mr2530990lji.77.1573133375015; Thu, 07 Nov 2019 05:29:35 -0800 (PST) Received: from xi.terra (c-51f1e055.07-184-6d6c6d4.bbcust.telenor.se. [85.224.241.81]) by smtp.gmail.com with ESMTPSA id 4sm1006649lfa.95.2019.11.07.05.29.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Nov 2019 05:29:28 -0800 (PST) Received: from johan by xi.terra with local (Exim 4.92.3) (envelope-from ) id 1iShqn-0000dy-T0; Thu, 07 Nov 2019 14:29:25 +0100 From: Johan Hovold To: Johan Hovold Cc: linux-usb@vger.kernel.org Subject: [PATCH 08/11] USB: serial: mos7840: drop serial struct accessor Date: Thu, 7 Nov 2019 14:29:01 +0100 Message-Id: <20191107132904.2379-9-johan@kernel.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191107132904.2379-1-johan@kernel.org> References: <20191107132904.2379-1-johan@kernel.org> MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Drop the helper used to retrieve the serial struct pointer from the port structure. Note that this helper was only used when the serial structure was actually not needed. Signed-off-by: Johan Hovold --- drivers/usb/serial/mos7840.c | 30 ------------------------------ 1 file changed, 30 deletions(-) diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c index 207b88d948a9..01787685a4ee 100644 --- a/drivers/usb/serial/mos7840.c +++ b/drivers/usb/serial/mos7840.c @@ -446,19 +446,6 @@ static void mos7840_led_activity(struct usb_serial_port *port) jiffies + msecs_to_jiffies(LED_ON_MS)); } -static struct usb_serial *mos7840_get_usb_serial(struct usb_serial_port *port, - const char *function) -{ - /* if no port was specified */ - if (!port) { - /* then say that we don't have a valid usb_serial thing, - * which will end up genrating -ENODEV return values */ - return NULL; - } - - return port->serial; -} - /***************************************************************************** * mos7840_bulk_in_callback * this is the callback function for when we have received data on the @@ -471,7 +458,6 @@ static void mos7840_bulk_in_callback(struct urb *urb) struct usb_serial_port *port = mos7840_port->port; int retval; unsigned char *data; - struct usb_serial *serial; int status = urb->status; if (status) { @@ -480,12 +466,6 @@ static void mos7840_bulk_in_callback(struct urb *urb) return; } - serial = mos7840_get_usb_serial(port, __func__); - if (!serial) { - mos7840_port->read_urb_busy = false; - return; - } - data = urb->transfer_buffer; usb_serial_debug_data(&port->dev, __func__, urb->actual_length, data); @@ -822,15 +802,10 @@ static int mos7840_chars_in_buffer(struct tty_struct *tty) static void mos7840_close(struct usb_serial_port *port) { - struct usb_serial *serial; struct moschip_port *mos7840_port; int j; __u16 Data; - serial = mos7840_get_usb_serial(port, __func__); - if (!serial) - return; - mos7840_port = mos7840_get_port_private(port); if (mos7840_port == NULL) return; @@ -866,13 +841,8 @@ static void mos7840_break(struct tty_struct *tty, int break_state) { struct usb_serial_port *port = tty->driver_data; unsigned char data; - struct usb_serial *serial; struct moschip_port *mos7840_port; - serial = mos7840_get_usb_serial(port, __func__); - if (!serial) - return; - mos7840_port = mos7840_get_port_private(port); if (mos7840_port == NULL) From patchwork Thu Nov 7 13:29:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 11232795 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B9AF913BD for ; Thu, 7 Nov 2019 13:29:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 99FAF21D7F for ; Thu, 7 Nov 2019 13:29:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573133375; bh=QN2x/z8uh1G5nryZM9q9ujui9QUVwlfJXfaIORG8K9Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=Hyzm545PM7vGmLvG2DaUQ6rl26MjjT2TdnL7JUHyCcHD/6f9i9J40eYTckS7UIwfv lhaq1X9hzZaR03hM+dtCpmz5nW01HK7oejbvz+KqUXh1q2YdHK5iSqvwtoS3ZP3zhn IRub0k16zBr6De+GSPxLJdad1loyHRBeYis49GZ0= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388613AbfKGN3f (ORCPT ); Thu, 7 Nov 2019 08:29:35 -0500 Received: from mail-lj1-f193.google.com ([209.85.208.193]:41856 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727738AbfKGN3e (ORCPT ); Thu, 7 Nov 2019 08:29:34 -0500 Received: by mail-lj1-f193.google.com with SMTP id m9so2261705ljh.8 for ; Thu, 07 Nov 2019 05:29:32 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=IWNc6gKaHd0LRi/YjZbjj6jKzYZ1Fwyj1A+ny0FdUCA=; b=pWDk4nFfMVCPBj8c6OWWuswNa9ZuRHubF6V/A7Fvhdon2bGtCeFZwYXJ8T2ETnDDJH kiaIEa5FN9efY4L/bDUruOsaFG+YIvjlri/zUh28k/PkgumPcQTdmCgALq0YuTQWU+lQ 8RuGr+vGExFX0d2Qa71GV9LjM36qTVY6BvIPJ3cIpb6HKl6aODhEVO7nBNPmGX8jCLr9 6I5+/JYnsGijJ5vZPaFNMMdvaaNE/h91YdfdyHKTj7Iw8/iJ/UydXTRgTbCZPi08LANd WW7rcPzHFfdYqOS8dVXDBQauJ0sYFNhmW75F9ss7rr3/eFhdsn3QPZkukWGOn1/pv4Fo M4IA== X-Gm-Message-State: APjAAAUSyyIWjsM+BLN9TOUcShh3CHWQCMLPjHzxdGIfonnhyry7akt5 7y517rgyODNKhld2uHJCgiNZcyfb X-Google-Smtp-Source: APXvYqwV0cNNFUcA/zqPsf2Uht0SM/QHVV09iqlWJRAJ34OI9CZgtZpvMb8cEoTI4DLe0yXoKK+TOg== X-Received: by 2002:a2e:3a09:: with SMTP id h9mr2546792lja.33.1573133371965; Thu, 07 Nov 2019 05:29:31 -0800 (PST) Received: from xi.terra (c-51f1e055.07-184-6d6c6d4.bbcust.telenor.se. [85.224.241.81]) by smtp.gmail.com with ESMTPSA id r12sm2065336lfp.63.2019.11.07.05.29.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Nov 2019 05:29:28 -0800 (PST) Received: from johan by xi.terra with local (Exim 4.92.3) (envelope-from ) id 1iShqn-0000e4-Vb; Thu, 07 Nov 2019 14:29:26 +0100 From: Johan Hovold To: Johan Hovold Cc: linux-usb@vger.kernel.org Subject: [PATCH 09/11] USB: serial: mos7840: drop port driver data accessors Date: Thu, 7 Nov 2019 14:29:02 +0100 Message-Id: <20191107132904.2379-10-johan@kernel.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191107132904.2379-1-johan@kernel.org> References: <20191107132904.2379-1-johan@kernel.org> MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Drop the custom port driver data accessors and paranoid sanity checks. The driver data is not cleared until the driver is unbound. Signed-off-by: Johan Hovold --- drivers/usb/serial/mos7840.c | 104 +++++------------------------------ 1 file changed, 13 insertions(+), 91 deletions(-) diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c index 01787685a4ee..11706f2d4145 100644 --- a/drivers/usb/serial/mos7840.c +++ b/drivers/usb/serial/mos7840.c @@ -344,26 +344,6 @@ static void mos7840_dump_serial_port(struct usb_serial_port *port, } -/************************************************************************/ -/************************************************************************/ -/* I N T E R F A C E F U N C T I O N S */ -/* I N T E R F A C E F U N C T I O N S */ -/************************************************************************/ -/************************************************************************/ - -static inline void mos7840_set_port_private(struct usb_serial_port *port, - struct moschip_port *data) -{ - usb_set_serial_port_data(port, (void *)data); -} - -static inline struct moschip_port *mos7840_get_port_private(struct - usb_serial_port - *port) -{ - return (struct moschip_port *)usb_get_serial_port_data(port); -} - /************************************************************************/ /************************************************************************/ /* U S B C A L L B A C K F U N C T I O N S */ @@ -541,17 +521,13 @@ static void mos7840_bulk_out_data_callback(struct urb *urb) static int mos7840_open(struct tty_struct *tty, struct usb_serial_port *port) { + struct moschip_port *mos7840_port = usb_get_serial_port_data(port); struct usb_serial *serial = port->serial; int response; int j; struct urb *urb; __u16 Data; int status; - struct moschip_port *mos7840_port; - - mos7840_port = mos7840_get_port_private(port); - if (mos7840_port == NULL) - return -ENODEV; usb_clear_halt(serial->dev, port->write_urb->pipe); usb_clear_halt(serial->dev, port->read_urb->pipe); @@ -773,14 +749,10 @@ static int mos7840_open(struct tty_struct *tty, struct usb_serial_port *port) static int mos7840_chars_in_buffer(struct tty_struct *tty) { struct usb_serial_port *port = tty->driver_data; + struct moschip_port *mos7840_port = usb_get_serial_port_data(port); int i; int chars = 0; unsigned long flags; - struct moschip_port *mos7840_port; - - mos7840_port = mos7840_get_port_private(port); - if (mos7840_port == NULL) - return 0; spin_lock_irqsave(&mos7840_port->pool_lock, flags); for (i = 0; i < NUM_URBS; ++i) { @@ -802,14 +774,10 @@ static int mos7840_chars_in_buffer(struct tty_struct *tty) static void mos7840_close(struct usb_serial_port *port) { - struct moschip_port *mos7840_port; + struct moschip_port *mos7840_port = usb_get_serial_port_data(port); int j; __u16 Data; - mos7840_port = mos7840_get_port_private(port); - if (mos7840_port == NULL) - return; - for (j = 0; j < NUM_URBS; ++j) usb_kill_urb(mos7840_port->write_urb_pool[j]); @@ -840,13 +808,8 @@ static void mos7840_close(struct usb_serial_port *port) static void mos7840_break(struct tty_struct *tty, int break_state) { struct usb_serial_port *port = tty->driver_data; + struct moschip_port *mos7840_port = usb_get_serial_port_data(port); unsigned char data; - struct moschip_port *mos7840_port; - - mos7840_port = mos7840_get_port_private(port); - - if (mos7840_port == NULL) - return; if (break_state == -1) data = mos7840_port->shadowLCR | LCR_SET_BREAK; @@ -871,14 +834,10 @@ static void mos7840_break(struct tty_struct *tty, int break_state) static int mos7840_write_room(struct tty_struct *tty) { struct usb_serial_port *port = tty->driver_data; + struct moschip_port *mos7840_port = usb_get_serial_port_data(port); int i; int room = 0; unsigned long flags; - struct moschip_port *mos7840_port; - - mos7840_port = mos7840_get_port_private(port); - if (mos7840_port == NULL) - return -1; spin_lock_irqsave(&mos7840_port->pool_lock, flags); for (i = 0; i < NUM_URBS; ++i) { @@ -904,22 +863,17 @@ static int mos7840_write_room(struct tty_struct *tty) static int mos7840_write(struct tty_struct *tty, struct usb_serial_port *port, const unsigned char *data, int count) { + struct moschip_port *mos7840_port = usb_get_serial_port_data(port); struct usb_serial *serial = port->serial; int status; int i; int bytes_sent = 0; int transfer_size; unsigned long flags; - - struct moschip_port *mos7840_port; struct urb *urb; /* __u16 Data; */ const unsigned char *current_position = data; - mos7840_port = mos7840_get_port_private(port); - if (mos7840_port == NULL) - return -1; - /* try to find a free urb in the list */ urb = NULL; @@ -1000,14 +954,9 @@ static int mos7840_write(struct tty_struct *tty, struct usb_serial_port *port, static void mos7840_throttle(struct tty_struct *tty) { struct usb_serial_port *port = tty->driver_data; - struct moschip_port *mos7840_port; + struct moschip_port *mos7840_port = usb_get_serial_port_data(port); int status; - mos7840_port = mos7840_get_port_private(port); - - if (mos7840_port == NULL) - return; - if (!mos7840_port->open) { dev_dbg(&port->dev, "%s", "port not opened\n"); return; @@ -1039,11 +988,8 @@ static void mos7840_throttle(struct tty_struct *tty) static void mos7840_unthrottle(struct tty_struct *tty) { struct usb_serial_port *port = tty->driver_data; + struct moschip_port *mos7840_port = usb_get_serial_port_data(port); int status; - struct moschip_port *mos7840_port = mos7840_get_port_private(port); - - if (mos7840_port == NULL) - return; if (!mos7840_port->open) { dev_dbg(&port->dev, "%s - port not opened\n", __func__); @@ -1071,15 +1017,10 @@ static void mos7840_unthrottle(struct tty_struct *tty) static int mos7840_tiocmget(struct tty_struct *tty) { struct usb_serial_port *port = tty->driver_data; - struct moschip_port *mos7840_port; unsigned int result; __u16 msr; __u16 mcr; int status; - mos7840_port = mos7840_get_port_private(port); - - if (mos7840_port == NULL) - return -ENODEV; status = mos7840_get_uart_reg(port, MODEM_STATUS_REGISTER, &msr); if (status < 0) @@ -1104,15 +1045,10 @@ static int mos7840_tiocmset(struct tty_struct *tty, unsigned int set, unsigned int clear) { struct usb_serial_port *port = tty->driver_data; - struct moschip_port *mos7840_port; + struct moschip_port *mos7840_port = usb_get_serial_port_data(port); unsigned int mcr; int status; - mos7840_port = mos7840_get_port_private(port); - - if (mos7840_port == NULL) - return -ENODEV; - /* FIXME: What locks the port registers ? */ mcr = mos7840_port->shadowMCR; if (clear & TIOCM_RTS) @@ -1429,13 +1365,8 @@ static void mos7840_set_termios(struct tty_struct *tty, struct usb_serial_port *port, struct ktermios *old_termios) { + struct moschip_port *mos7840_port = usb_get_serial_port_data(port); int status; - struct moschip_port *mos7840_port; - - mos7840_port = mos7840_get_port_private(port); - - if (mos7840_port == NULL) - return; if (!mos7840_port->open) { dev_dbg(&port->dev, "%s - port not opened\n", __func__); @@ -1497,7 +1428,7 @@ static int mos7840_get_serial_info(struct tty_struct *tty, struct serial_struct *ss) { struct usb_serial_port *port = tty->driver_data; - struct moschip_port *mos7840_port = mos7840_get_port_private(port); + struct moschip_port *mos7840_port = usb_get_serial_port_data(port); ss->type = PORT_16550A; ss->line = mos7840_port->port->minor; @@ -1520,12 +1451,6 @@ static int mos7840_ioctl(struct tty_struct *tty, { struct usb_serial_port *port = tty->driver_data; void __user *argp = (void __user *)arg; - struct moschip_port *mos7840_port; - - mos7840_port = mos7840_get_port_private(port); - - if (mos7840_port == NULL) - return -1; switch (cmd) { /* return number of bytes available */ @@ -1692,7 +1617,6 @@ static int mos7840_port_probe(struct usb_serial_port *port) * common to all port */ mos7840_port->port = port; - mos7840_set_port_private(port, mos7840_port); spin_lock_init(&mos7840_port->pool_lock); /* minor is not initialised until later by @@ -1718,7 +1642,7 @@ static int mos7840_port_probe(struct usb_serial_port *port) mos7840_port->DcrRegOffset = 0x16 + 3 * (phy_num - 2); } mos7840_dump_serial_port(port, mos7840_port); - mos7840_set_port_private(port, mos7840_port); + usb_set_serial_port_data(port, mos7840_port); /* enable rx_disable bit in control register */ status = mos7840_get_reg_sync(port, @@ -1859,9 +1783,7 @@ static int mos7840_port_probe(struct usb_serial_port *port) static int mos7840_port_remove(struct usb_serial_port *port) { - struct moschip_port *mos7840_port; - - mos7840_port = mos7840_get_port_private(port); + struct moschip_port *mos7840_port = usb_get_serial_port_data(port); if (mos7840_port->has_led) { /* Turn off LED */ From patchwork Thu Nov 7 13:29:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 11232799 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D0EB113BD for ; Thu, 7 Nov 2019 13:29:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A560921D79 for ; Thu, 7 Nov 2019 13:29:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573133376; bh=zbGOXK6Ej4J79e/5/pnwtezoahnhJbKLL0mCNoU0jiY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=lWP5o/wtUpbFgWmGQl9m734pkYe/F+ufqHARIm3H/7ldpPSCqYwEQLwz1zM2hYeBv ZlhidRZg8+NiuB3XtISL7tv2O9Aolc9bUjUkrQtS+1BKHhHcTX6jxMQkpBzF/VERS4 DNIOkrsP7NTpZd4GiARJQjSZUmHxDnvEJJwwMdC0= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388679AbfKGN3g (ORCPT ); Thu, 7 Nov 2019 08:29:36 -0500 Received: from mail-lf1-f67.google.com ([209.85.167.67]:35055 "EHLO mail-lf1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728687AbfKGN3f (ORCPT ); Thu, 7 Nov 2019 08:29:35 -0500 Received: by mail-lf1-f67.google.com with SMTP id y6so1616785lfj.2 for ; Thu, 07 Nov 2019 05:29:34 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Q5VZueLPa3LMWvRMgC3rV4Ys93H9McfqwkDOVYWZf8Q=; b=qNDqMYDoEZ3pSwNiV4Vf/Ov4U/lUi98terMsiIWGQmdfyNCkY90ywFY0XA51vROuW8 DgMiYQ9jzKgGgL4ldPN8Q9FNR0O/YtqFdNBzlIPuKQxFfjvwO4p+aWRkC8l15xB+2i64 uernuWsNdw0+8CN0Q+tlm3EdF4dmiLQpTNFKs+wjoyknN0M3YpoLftGyyC14nE0/6v8+ elhPyzAU9zzWiBEcwi7PB7UY9wVPlDCfRp9G5jApabdI+d8wvdF5MMlfPFwzKadROQG+ erzYzVV9saJwOr+psKLVfo19VC4IQHkOwZ3OBHGNyDdT2ZNevXTnU5Setv4h4J1egVPI 0tmg== X-Gm-Message-State: APjAAAXwuZXQ88GDHgVYxIYZN6n/n6zqKfXwMAMyqYnSoAcI1T9Z4oOg 76RQLKktyYFNn+xdVj+fjGiB3XX3 X-Google-Smtp-Source: APXvYqyHCmQ9ifJTYr42CyTSds7atb78GpT4w8poKnzJKLyRmsHL4D5sZD94VXJUt2mR6eIPYDcYuQ== X-Received: by 2002:a19:6d19:: with SMTP id i25mr2460871lfc.178.1573133373414; Thu, 07 Nov 2019 05:29:33 -0800 (PST) Received: from xi.terra (c-51f1e055.07-184-6d6c6d4.bbcust.telenor.se. [85.224.241.81]) by smtp.gmail.com with ESMTPSA id h26sm981414lfc.69.2019.11.07.05.29.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Nov 2019 05:29:28 -0800 (PST) Received: from johan by xi.terra with local (Exim 4.92.3) (envelope-from ) id 1iShqo-0000e8-2a; Thu, 07 Nov 2019 14:29:26 +0100 From: Johan Hovold To: Johan Hovold Cc: linux-usb@vger.kernel.org Subject: [PATCH 10/11] USB: serial: mos7840: drop read-urb check Date: Thu, 7 Nov 2019 14:29:03 +0100 Message-Id: <20191107132904.2379-11-johan@kernel.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191107132904.2379-1-johan@kernel.org> References: <20191107132904.2379-1-johan@kernel.org> MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Drop read-urb check which is always false from completion the callback. The driver read-urb pointer is set at every open and is never cleared. Signed-off-by: Johan Hovold --- drivers/usb/serial/mos7840.c | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c index 11706f2d4145..f5c08effa3ab 100644 --- a/drivers/usb/serial/mos7840.c +++ b/drivers/usb/serial/mos7840.c @@ -457,12 +457,6 @@ static void mos7840_bulk_in_callback(struct urb *urb) dev_dbg(&port->dev, "icount.rx is %d:\n", port->icount.rx); } - if (!mos7840_port->read_urb) { - dev_dbg(&port->dev, "%s", "URB KILLED !!!\n"); - mos7840_port->read_urb_busy = false; - return; - } - if (mos7840_port->has_led) mos7840_led_activity(port); @@ -1377,11 +1371,6 @@ static void mos7840_set_termios(struct tty_struct *tty, mos7840_change_port_settings(tty, mos7840_port, old_termios); - if (!mos7840_port->read_urb) { - dev_dbg(&port->dev, "%s", "URB KILLED !!!!!\n"); - return; - } - if (!mos7840_port->read_urb_busy) { mos7840_port->read_urb_busy = true; status = usb_submit_urb(mos7840_port->read_urb, GFP_KERNEL); From patchwork Thu Nov 7 13:29:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 11232801 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 53FFD1850 for ; Thu, 7 Nov 2019 13:29:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 33D3121D7B for ; Thu, 7 Nov 2019 13:29:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573133377; bh=uApviLhRIDMd2TVFsRkuiiEfu8OnuBvbKnm1xr7n8ms=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=JoosOOoxPeqVaAXoQyEQK4LYmbBuqdia2lnV9KP3KB5s7Mn8bR5Py8c+dtD9OSiUh uvSmwyC71HPbahFrJe74GrO8FQGKkODpq3YUEVdvjKr8KGi4EpzsGoz/jo32s2a9FO 6gkwEF43Tvbf0gGsGyVbxH9cG/FL68PpoBRLvjCI= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388683AbfKGN3g (ORCPT ); Thu, 7 Nov 2019 08:29:36 -0500 Received: from mail-lj1-f193.google.com ([209.85.208.193]:43581 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388525AbfKGN3g (ORCPT ); Thu, 7 Nov 2019 08:29:36 -0500 Received: by mail-lj1-f193.google.com with SMTP id y23so2258606ljh.10 for ; Thu, 07 Nov 2019 05:29:34 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SwpaxTxNJWgIEUxyPB9fMbXiAXc6MAAqO3URuJG+Mhs=; b=kH6VmNdtIVKLbkCm5Oy+VzrZP0VCvkzEaEEcGFpnj2j+Vq/dZLcIN6d0jopEAc3e3r w9gNaeW30ujf7PX6zrJvmweMbVxnKzumzyP2aVjQD4lltEzjpRzQv58W5KT/lUPBS3kB kgoH7LbIxFEMue8ZnzacXwp/XALJLA8L95kRTveB7gvhzX3Royz7UN8JC9YygPSR2Nsg 9lR20FL+wAfdFHn/wxA86evKx114HKVfNFoh2TvZiVIpB1Pil8nvQ82S/6n596g3JeUY BBf+tytupi9l/cTKecNcRHRO/LPuGDbZrCERQmyXqW4X4DgZC4nc/nAAXebEnjfPiZ8/ k61g== X-Gm-Message-State: APjAAAVC8qH0mfvWbXXuWvV4QIUngAoHcpWXBnW/SeWpzMRctMcpCq4Z BB38wu6FTdV5KPzZNhev8cQYMP4r X-Google-Smtp-Source: APXvYqzsZghg0fLak90MCL47dHkSfRKVbImbgdRtPKJOnFQxbOn4blxDbaPKOH5Z+pRjQdDtkq8FJQ== X-Received: by 2002:a2e:8784:: with SMTP id n4mr2569290lji.230.1573133373882; Thu, 07 Nov 2019 05:29:33 -0800 (PST) Received: from xi.terra (c-51f1e055.07-184-6d6c6d4.bbcust.telenor.se. [85.224.241.81]) by smtp.gmail.com with ESMTPSA id e10sm980560ljp.23.2019.11.07.05.29.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Nov 2019 05:29:28 -0800 (PST) Received: from johan by xi.terra with local (Exim 4.92.3) (envelope-from ) id 1iShqo-0000eD-5s; Thu, 07 Nov 2019 14:29:26 +0100 From: Johan Hovold To: Johan Hovold Cc: linux-usb@vger.kernel.org Subject: [PATCH 11/11] USB: serial: mos7840: drop port open flag Date: Thu, 7 Nov 2019 14:29:04 +0100 Message-Id: <20191107132904.2379-12-johan@kernel.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191107132904.2379-1-johan@kernel.org> References: <20191107132904.2379-1-johan@kernel.org> MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Drop the redundant port open flag and corresponding checks. USB serial core will not call any of these driver callbacks for a closed port, and the write URBs are stopped at close(). Signed-off-by: Johan Hovold --- drivers/usb/serial/mos7840.c | 29 +---------------------------- 1 file changed, 1 insertion(+), 28 deletions(-) diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c index f5c08effa3ab..23f91d658cb4 100644 --- a/drivers/usb/serial/mos7840.c +++ b/drivers/usb/serial/mos7840.c @@ -198,7 +198,6 @@ struct moschip_port { struct urb *read_urb; /* read URB for this port */ __u8 shadowLCR; /* last LCR value received */ __u8 shadowMCR; /* last MCR value received */ - char open; struct usb_serial_port *port; /* loop back to the owner of this object */ /* Offsets */ @@ -497,8 +496,7 @@ static void mos7840_bulk_out_data_callback(struct urb *urb) return; } - if (mos7840_port->open) - tty_port_tty_wakeup(&port->port); + tty_port_tty_wakeup(&port->port); } @@ -714,9 +712,6 @@ static int mos7840_open(struct tty_struct *tty, struct usb_serial_port *port) /* initialize our port settings */ /* Must set to enable ints! */ mos7840_port->shadowMCR = MCR_MASTER_IE; - /* send a open port command */ - mos7840_port->open = 1; - /* mos7840_change_port_settings(mos7840_port,old_termios); */ return 0; err: @@ -791,8 +786,6 @@ static void mos7840_close(struct usb_serial_port *port) Data = 0x00; mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data); - - mos7840_port->open = 0; } /***************************************************************************** @@ -951,11 +944,6 @@ static void mos7840_throttle(struct tty_struct *tty) struct moschip_port *mos7840_port = usb_get_serial_port_data(port); int status; - if (!mos7840_port->open) { - dev_dbg(&port->dev, "%s", "port not opened\n"); - return; - } - /* if we are implementing XON/XOFF, send the stop character */ if (I_IXOFF(tty)) { unsigned char stop_char = STOP_CHAR(tty); @@ -985,11 +973,6 @@ static void mos7840_unthrottle(struct tty_struct *tty) struct moschip_port *mos7840_port = usb_get_serial_port_data(port); int status; - if (!mos7840_port->open) { - dev_dbg(&port->dev, "%s - port not opened\n", __func__); - return; - } - /* if we are implementing XON/XOFF, send the start character */ if (I_IXOFF(tty)) { unsigned char start_char = START_CHAR(tty); @@ -1221,11 +1204,6 @@ static void mos7840_change_port_settings(struct tty_struct *tty, int status; __u16 Data; - if (!mos7840_port->open) { - dev_dbg(&port->dev, "%s - port not opened\n", __func__); - return; - } - lData = LCR_BITS_8; lStop = LCR_STOP_1; lParity = LCR_PAR_NONE; @@ -1362,11 +1340,6 @@ static void mos7840_set_termios(struct tty_struct *tty, struct moschip_port *mos7840_port = usb_get_serial_port_data(port); int status; - if (!mos7840_port->open) { - dev_dbg(&port->dev, "%s - port not opened\n", __func__); - return; - } - /* change the port settings to the new ones specified */ mos7840_change_port_settings(tty, mos7840_port, old_termios);