From patchwork Wed Jan 22 10:15:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 11345449 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 AFCAC6C1 for ; Wed, 22 Jan 2020 10:15:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8456624689 for ; Wed, 22 Jan 2020 10:15:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579688154; bh=bZys1UjnBjiUy5msrYP893NTWbpflJf7vyLAnBEC5UQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=IC8Jt1yxypo+nef0uRa09mk8AmVEEPpnwgYeD3irmOsWpqnuo5uKvvbK/TeT+ROjk PV28teNi4fKT+1jshk7fY54KbPOx/nWittyRX5ijXsqgmkwks3qsSJTrmKkJYnzl83 PReH6uMMtyA0Z2UubrN7/YW8dYZDcA7H0k4RAJZM= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729526AbgAVKPx (ORCPT ); Wed, 22 Jan 2020 05:15:53 -0500 Received: from mail-lf1-f66.google.com ([209.85.167.66]:45410 "EHLO mail-lf1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729281AbgAVKPx (ORCPT ); Wed, 22 Jan 2020 05:15:53 -0500 Received: by mail-lf1-f66.google.com with SMTP id 203so4850219lfa.12; Wed, 22 Jan 2020 02:15:51 -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=nAGmP7/E0+dkjElTkN6jQ2jIYPfA3j8DC+gRpJkqbEM=; b=RR9APJA9q+P+rvlxm+E9R/AvatjJnDSjytvr7OMpj5tKI2MvPxuQETkiPOIYU22kUt f4ehalsXkf/+oHBO/LEW0Ce8r+wZR1I8/BIS47LX94L5xR0bxL5DGhVsI0SkehCCTrKz QxC1F1TwriIvWOobk58q+CuEaNtEyugimLkFiyYvuDjLANlv34QiZAxcpl7tv3GEeK0g pqI2tI7xh/p7iem9MCsPgBNeGmndqMp2n7NN0/cUYmbIuagN0l9WhGKQSQbzaup0OQZ3 5u5iKuvN32cOpin9A2loRwgoT6JoTPf54ja5rm0cMfNV79vvLSBT4XVLff4wEk+Brfow kTfw== X-Gm-Message-State: APjAAAVgKqmJpXfYW/ujtcO+yJ84IoJ8CxZs2QlRAXgjadFfnNcKkiTu 28NGomJxaNn/CZsGgZ/Nx+w= X-Google-Smtp-Source: APXvYqx1ZBBPf872QGty4fVC30qLUgko5wXFyT5uPwtOwckYEcWVbOSAkTvlTWqQkroYybLE+tCUfQ== X-Received: by 2002:ac2:5e2e:: with SMTP id o14mr1399159lfg.198.1579688151084; Wed, 22 Jan 2020 02:15:51 -0800 (PST) Received: from xi.terra (c-14b8e655.07-184-6d6c6d4.bbcust.telenor.se. [85.230.184.20]) by smtp.gmail.com with ESMTPSA id r15sm19988772ljh.11.2020.01.22.02.15.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jan 2020 02:15:50 -0800 (PST) Received: from johan by xi.terra with local (Exim 4.92.3) (envelope-from ) id 1iuD34-0007bU-71; Wed, 22 Jan 2020 11:15:46 +0100 From: Johan Hovold To: Johan Hovold Cc: linux-usb@vger.kernel.org, stable Subject: [PATCH 1/5] USB: serial: ir-usb: add missing endpoint sanity check Date: Wed, 22 Jan 2020 11:15:26 +0100 Message-Id: <20200122101530.29176-2-johan@kernel.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200122101530.29176-1-johan@kernel.org> References: <20200122101530.29176-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 Add missing endpoint sanity check to avoid dereferencing a NULL-pointer on open() in case a device lacks a bulk-out endpoint. Note that prior to commit f4a4cbb2047e ("USB: ir-usb: reimplement using generic framework") the oops would instead happen on open() if the device lacked a bulk-in endpoint and on write() if it lacked a bulk-out endpoint. Fixes: f4a4cbb2047e ("USB: ir-usb: reimplement using generic framework") Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Cc: stable Signed-off-by: Johan Hovold Reviewed-by: Greg Kroah-Hartman --- drivers/usb/serial/ir-usb.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/usb/serial/ir-usb.c b/drivers/usb/serial/ir-usb.c index 302eb9530859..c3b06fc5a7f0 100644 --- a/drivers/usb/serial/ir-usb.c +++ b/drivers/usb/serial/ir-usb.c @@ -195,6 +195,9 @@ static int ir_startup(struct usb_serial *serial) struct usb_irda_cs_descriptor *irda_desc; int rates; + if (serial->num_bulk_in < 1 || serial->num_bulk_out < 1) + return -ENODEV; + irda_desc = irda_usb_find_class_desc(serial, 0); if (!irda_desc) { dev_err(&serial->dev->dev, From patchwork Wed Jan 22 10:15:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 11345453 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 E1C031398 for ; Wed, 22 Jan 2020 10:15:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C2AEF24688 for ; Wed, 22 Jan 2020 10:15:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579688156; bh=g9vXJsbcCQKHObHImPwrBfICIp9aPRemPXneWkBflAw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=uyR8RYs2eLwH6DW8z/Kwu7t5fk+GShRhm3jLWmFMbXBtCDWwsqQPjHdR+4KJ2t256 cTxE2/gFeYT7dDfHrW1tpAij/xzlRyctZNKjMRFCBAUZm49GTnKIH3oubj71RT8JaZ oIv1zzMc9VqcbFSS7CB5KqNqCLx+P7tMq9zkFLIE= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729543AbgAVKPz (ORCPT ); Wed, 22 Jan 2020 05:15:55 -0500 Received: from mail-lf1-f65.google.com ([209.85.167.65]:37408 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729308AbgAVKPx (ORCPT ); Wed, 22 Jan 2020 05:15:53 -0500 Received: by mail-lf1-f65.google.com with SMTP id b15so4887733lfc.4; Wed, 22 Jan 2020 02:15:52 -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=gaD1PJgTIue46yFrsImoNhaoR4zNTqSz3mLICXSlQz0=; b=U8K971BtgMbnQVUBoPZcv5LmnS6MTRYTioHFO81mpxhbaT6guapoQRoAKZRatcOVGp pV0leffqLjAhtgirtMCeliIrl8+bh2tfHCE+9JASWMR3Zs6dVtLK2/d1lDP/mpeH8V1a DVN/wuioScOsMJnXiyGd4GVTQXn47vS/0KG9837hAKUf41Xj6DpArRsOYmQysu6Iaei0 9dgvKKGlhzR0LacAkEE2K/wZg+ncVFM1oBCCDwVS2dOg8W48z6OYVmX32MdY5TQe94xD CjW1uKFBjpGv8ilEh91gnvPR5nNrWbBRr6wmVf03Jtfe4GbSfSka5yeHRqcZlrw62V4p nyzA== X-Gm-Message-State: APjAAAVE4Fj7L9PWCBPshnFPfVNnz+u0mznfipWkl9GLVpY9H2Y7j3zz Q0VoFG4j9RMZuQ3IyxKhnBzvuC5r X-Google-Smtp-Source: APXvYqyS6C8uDI8D+1BXprQMSyZVf4xfMwLPeBPqWEn8cIqZ3HfMWXQxisL/OUlbwliE5H/rN6oByQ== X-Received: by 2002:ac2:54b5:: with SMTP id w21mr1382203lfk.175.1579688151438; Wed, 22 Jan 2020 02:15:51 -0800 (PST) Received: from xi.terra (c-14b8e655.07-184-6d6c6d4.bbcust.telenor.se. [85.230.184.20]) by smtp.gmail.com with ESMTPSA id 14sm6592612lfz.47.2020.01.22.02.15.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jan 2020 02:15:50 -0800 (PST) Received: from johan by xi.terra with local (Exim 4.92.3) (envelope-from ) id 1iuD34-0007bZ-A0; Wed, 22 Jan 2020 11:15:46 +0100 From: Johan Hovold To: Johan Hovold Cc: linux-usb@vger.kernel.org, stable , Felipe Balbi Subject: [PATCH 2/5] USB: serial: ir-usb: fix link-speed handling Date: Wed, 22 Jan 2020 11:15:27 +0100 Message-Id: <20200122101530.29176-3-johan@kernel.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200122101530.29176-1-johan@kernel.org> References: <20200122101530.29176-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 Commit e0d795e4f36c ("usb: irda: cleanup on ir-usb module") added a USB IrDA header with common defines, but mistakingly switched to using the class-descriptor baud-rate bitmask values for the outbound header. This broke link-speed handling for rates above 9600 baud, but a device would also be able to operate at the default 9600 baud until a link-speed request was issued (e.g. using the TCGETS ioctl). Fixes: e0d795e4f36c ("usb: irda: cleanup on ir-usb module") Cc: stable # 2.6.27 Cc: Felipe Balbi Signed-off-by: Johan Hovold Reviewed-by: Greg Kroah-Hartman --- drivers/usb/serial/ir-usb.c | 20 ++++++++++---------- include/linux/usb/irda.h | 13 ++++++++++++- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/drivers/usb/serial/ir-usb.c b/drivers/usb/serial/ir-usb.c index c3b06fc5a7f0..26eab1307165 100644 --- a/drivers/usb/serial/ir-usb.c +++ b/drivers/usb/serial/ir-usb.c @@ -335,34 +335,34 @@ static void ir_set_termios(struct tty_struct *tty, switch (baud) { case 2400: - ir_baud = USB_IRDA_BR_2400; + ir_baud = USB_IRDA_LS_2400; break; case 9600: - ir_baud = USB_IRDA_BR_9600; + ir_baud = USB_IRDA_LS_9600; break; case 19200: - ir_baud = USB_IRDA_BR_19200; + ir_baud = USB_IRDA_LS_19200; break; case 38400: - ir_baud = USB_IRDA_BR_38400; + ir_baud = USB_IRDA_LS_38400; break; case 57600: - ir_baud = USB_IRDA_BR_57600; + ir_baud = USB_IRDA_LS_57600; break; case 115200: - ir_baud = USB_IRDA_BR_115200; + ir_baud = USB_IRDA_LS_115200; break; case 576000: - ir_baud = USB_IRDA_BR_576000; + ir_baud = USB_IRDA_LS_576000; break; case 1152000: - ir_baud = USB_IRDA_BR_1152000; + ir_baud = USB_IRDA_LS_1152000; break; case 4000000: - ir_baud = USB_IRDA_BR_4000000; + ir_baud = USB_IRDA_LS_4000000; break; default: - ir_baud = USB_IRDA_BR_9600; + ir_baud = USB_IRDA_LS_9600; baud = 9600; } diff --git a/include/linux/usb/irda.h b/include/linux/usb/irda.h index 396d2b043e64..556a801efce3 100644 --- a/include/linux/usb/irda.h +++ b/include/linux/usb/irda.h @@ -119,11 +119,22 @@ struct usb_irda_cs_descriptor { * 6 - 115200 bps * 7 - 576000 bps * 8 - 1.152 Mbps - * 9 - 5 mbps + * 9 - 4 Mbps * 10..15 - Reserved */ #define USB_IRDA_STATUS_LINK_SPEED 0x0f +#define USB_IRDA_LS_NO_CHANGE 0 +#define USB_IRDA_LS_2400 1 +#define USB_IRDA_LS_9600 2 +#define USB_IRDA_LS_19200 3 +#define USB_IRDA_LS_38400 4 +#define USB_IRDA_LS_57600 5 +#define USB_IRDA_LS_115200 6 +#define USB_IRDA_LS_576000 7 +#define USB_IRDA_LS_1152000 8 +#define USB_IRDA_LS_4000000 9 + /* The following is a 4-bit value used only for * outbound header: * From patchwork Wed Jan 22 10:15:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 11345451 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 331A11398 for ; Wed, 22 Jan 2020 10:15:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1193424689 for ; Wed, 22 Jan 2020 10:15:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579688156; bh=Yi8kGLqwUyfXJxXRhlUe5TyqWZUMK08ApcZxL6Pb40o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=QJ+C6klPqDk2VIDd4HfBw7jORBM6TEQO1msQb//n34UQPjF6EebHRw+o8pOL2Yx1t dmn0N77xK66NX53HncnnfSy26NUG2GuBBGHBrthsQNDLKhNRJKJ7D1pJJPeNDTOgS7 wcTHj391zy0cWAl2C0xMzdAm4nj1v8QjHm4RJJLk= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729538AbgAVKPy (ORCPT ); Wed, 22 Jan 2020 05:15:54 -0500 Received: from mail-lj1-f193.google.com ([209.85.208.193]:39418 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729384AbgAVKPy (ORCPT ); Wed, 22 Jan 2020 05:15:54 -0500 Received: by mail-lj1-f193.google.com with SMTP id o11so5836781ljc.6; Wed, 22 Jan 2020 02:15:52 -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=Em19EzjWfRgzXWLNmqkC5wijvfl7V9/+QdnPlZcD7+s=; b=Nm88Q1RzKjoLlZK4dZeMXSD7e7C3ULGZ0y8aFGZpWUDC8HVWYoH4JtNpyOQfwI1o6o 6Q7LPtR7teI3mgI5dN8UqkXnnPsomvFXA4EX1K+Ue87x1Oy9ZtJZDnmb2DuBZ0OWEAiK rwlCvbNF+8r1lEvi6MfLvPMxLXAqGa+VQEHLcHReZHdOEcLukcuslCLUtSKwrlnwJVNY 5o561flgRZiFC2cUREvsfdlJp3VwrYN17wTuqa45v4tXliR4FsPfYTVfb1sg6eAnKIys hpnKIviGGJcxJJEfoVGng78Vtz1Y8HKzkRqlHzQluDJsr++GI2bFON0ibJ8kDUo3zcil TQMg== X-Gm-Message-State: APjAAAW/MotwdIKRCMzRZ/c811kkRjecyjJmb2Z0i2pqqzUPupMFyR21 saDDbaIXGaxwK3FEuY+Cf5ifi7Yi X-Google-Smtp-Source: APXvYqzyu1e0zzpVNUaebmYd/1OK53ZCTp1+35cmK3LfXrtiKhKPmg/RpfKEymswco7AM07cL8sskQ== X-Received: by 2002:a2e:8745:: with SMTP id q5mr17803846ljj.208.1579688151805; Wed, 22 Jan 2020 02:15:51 -0800 (PST) Received: from xi.terra (c-14b8e655.07-184-6d6c6d4.bbcust.telenor.se. [85.230.184.20]) by smtp.gmail.com with ESMTPSA id 2sm20088114ljq.38.2020.01.22.02.15.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jan 2020 02:15:50 -0800 (PST) Received: from johan by xi.terra with local (Exim 4.92.3) (envelope-from ) id 1iuD34-0007bf-Ca; Wed, 22 Jan 2020 11:15:46 +0100 From: Johan Hovold To: Johan Hovold Cc: linux-usb@vger.kernel.org, stable Subject: [PATCH 3/5] USB: serial: ir-usb: fix IrLAP framing Date: Wed, 22 Jan 2020 11:15:28 +0100 Message-Id: <20200122101530.29176-4-johan@kernel.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200122101530.29176-1-johan@kernel.org> References: <20200122101530.29176-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 Commit f4a4cbb2047e ("USB: ir-usb: reimplement using generic framework") switched to using the generic write implementation which may combine multiple write requests into larger transfers. This can break the IrLAP protocol where end-of-frame is determined using the USB short packet mechanism, for example, if multiple frames are sent in rapid succession. Fixes: f4a4cbb2047e ("USB: ir-usb: reimplement using generic framework") Cc: stable # 2.6.35 Signed-off-by: Johan Hovold Reviewed-by: Greg Kroah-Hartman --- drivers/usb/serial/ir-usb.c | 113 +++++++++++++++++++++++++++++------- 1 file changed, 91 insertions(+), 22 deletions(-) diff --git a/drivers/usb/serial/ir-usb.c b/drivers/usb/serial/ir-usb.c index 26eab1307165..627bea7e6cfb 100644 --- a/drivers/usb/serial/ir-usb.c +++ b/drivers/usb/serial/ir-usb.c @@ -45,9 +45,10 @@ static int buffer_size; static int xbof = -1; static int ir_startup (struct usb_serial *serial); -static int ir_open(struct tty_struct *tty, struct usb_serial_port *port); -static int ir_prepare_write_buffer(struct usb_serial_port *port, - void *dest, size_t size); +static int ir_write(struct tty_struct *tty, struct usb_serial_port *port, + const unsigned char *buf, int count); +static int ir_write_room(struct tty_struct *tty); +static void ir_write_bulk_callback(struct urb *urb); static void ir_process_read_urb(struct urb *urb); static void ir_set_termios(struct tty_struct *tty, struct usb_serial_port *port, struct ktermios *old_termios); @@ -77,8 +78,9 @@ static struct usb_serial_driver ir_device = { .num_ports = 1, .set_termios = ir_set_termios, .attach = ir_startup, - .open = ir_open, - .prepare_write_buffer = ir_prepare_write_buffer, + .write = ir_write, + .write_room = ir_write_room, + .write_bulk_callback = ir_write_bulk_callback, .process_read_urb = ir_process_read_urb, }; @@ -254,35 +256,102 @@ static int ir_startup(struct usb_serial *serial) return 0; } -static int ir_open(struct tty_struct *tty, struct usb_serial_port *port) +static int ir_write(struct tty_struct *tty, struct usb_serial_port *port, + const unsigned char *buf, int count) { - int i; + struct urb *urb = NULL; + unsigned long flags; + int ret; - for (i = 0; i < ARRAY_SIZE(port->write_urbs); ++i) - port->write_urbs[i]->transfer_flags = URB_ZERO_PACKET; + if (port->bulk_out_size == 0) + return -EINVAL; - /* Start reading from the device */ - return usb_serial_generic_open(tty, port); -} + if (count == 0) + return 0; -static int ir_prepare_write_buffer(struct usb_serial_port *port, - void *dest, size_t size) -{ - unsigned char *buf = dest; - int count; + count = min(count, port->bulk_out_size - 1); + + spin_lock_irqsave(&port->lock, flags); + if (__test_and_clear_bit(0, &port->write_urbs_free)) { + urb = port->write_urbs[0]; + port->tx_bytes += count; + } + spin_unlock_irqrestore(&port->lock, flags); + + if (!urb) + return 0; /* * The first byte of the packet we send to the device contains an - * inbound header which indicates an additional number of BOFs and + * outbound header which indicates an additional number of BOFs and * a baud rate change. * * See section 5.4.2.2 of the USB IrDA spec. */ - *buf = ir_xbof | ir_baud; + *(u8 *)urb->transfer_buffer = ir_xbof | ir_baud; + + memcpy(urb->transfer_buffer + 1, buf, count); + + urb->transfer_buffer_length = count + 1; + urb->transfer_flags = URB_ZERO_PACKET; + + ret = usb_submit_urb(urb, GFP_ATOMIC); + if (ret) { + dev_err(&port->dev, "failed to submit write urb: %d\n", ret); + + spin_lock_irqsave(&port->lock, flags); + __set_bit(0, &port->write_urbs_free); + port->tx_bytes -= count; + spin_unlock_irqrestore(&port->lock, flags); + + return ret; + } + + return count; +} + +static void ir_write_bulk_callback(struct urb *urb) +{ + struct usb_serial_port *port = urb->context; + int status = urb->status; + unsigned long flags; + + spin_lock_irqsave(&port->lock, flags); + __set_bit(0, &port->write_urbs_free); + port->tx_bytes -= urb->transfer_buffer_length - 1; + spin_unlock_irqrestore(&port->lock, flags); + + switch (status) { + case 0: + break; + case -ENOENT: + case -ECONNRESET: + case -ESHUTDOWN: + dev_dbg(&port->dev, "write urb stopped: %d\n", status); + return; + case -EPIPE: + dev_err(&port->dev, "write urb stopped: %d\n", status); + return; + default: + dev_err(&port->dev, "nonzero write-urb status: %d\n", status); + break; + } + + usb_serial_port_softint(port); +} + +static int ir_write_room(struct tty_struct *tty) +{ + struct usb_serial_port *port = tty->driver_data; + int count = 0; + + if (port->bulk_out_size == 0) + return 0; + + if (test_bit(0, &port->write_urbs_free)) + count = port->bulk_out_size - 1; - count = kfifo_out_locked(&port->write_fifo, buf + 1, size - 1, - &port->lock); - return count + 1; + return count; } static void ir_process_read_urb(struct urb *urb) From patchwork Wed Jan 22 10:15:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 11345455 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 B0A616C1 for ; Wed, 22 Jan 2020 10:15:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8FECE24688 for ; Wed, 22 Jan 2020 10:15:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579688157; bh=BUERMAOuC1Sinkg+B37Aru4DoGizQFXJw71O7d8KNcQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=D2TdC4niNbjT0ZS4LGpKhR9IVX8+bRgQVzdt3MHUAz68MS7G/2uYJMFGddACO131Y 8dNMJ8GYZWeZAOXecx1yx/j/5uXLyvC0B8z+733wlr+h8d//FtF84/IB7Agwz4DVMr y8sL728NhG110qnpgStpDr3ELSS86s0oCEVEGRM4= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729546AbgAVKP4 (ORCPT ); Wed, 22 Jan 2020 05:15:56 -0500 Received: from mail-lj1-f196.google.com ([209.85.208.196]:44939 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729527AbgAVKPy (ORCPT ); Wed, 22 Jan 2020 05:15:54 -0500 Received: by mail-lj1-f196.google.com with SMTP id q8so6101140ljj.11 for ; Wed, 22 Jan 2020 02:15:53 -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=mwKxS8lXMv8Bi7mN+ImlUawO7kdYz2hgSq0PZVkhFR4=; b=O7SlTkY4ZDBFNrB1jRdu6o21yqB1bKAPyoHI7CDHV21r8F8OgDCcghd7N1dc/wpWko CfYmwHxIV4eAQMFYUAAMZ+iVI66V9HsJKKe3IrFlzh/BN2RqW7OFQ383zufkJUd9jxmT ltaiNWOhaE+g9x/PxpS2yz/P6GB0gPb87w5AJRs8Ue2mWgSG5gc9tOssjYcMGp7LQWAh 7TY6eGdsjjG5sNxwPxEzFPJL7KPTFS6XIX8Fz9QS4LUXV6e8MkEjAGBgLCrgxjtZkTst t9cSO8awLCoujBMDro2gYGpAWrXjCR7LsV+QdaV1A0Vx58bGB6NPLNHr5E+nbRKnqikV zjHw== X-Gm-Message-State: APjAAAUOAD1NHcMuQkALV277oU71nouaiBdGRlBlZl44CBS3Kvok20aZ PHbOAQ1f1dyM0J/k7Lz07GM= X-Google-Smtp-Source: APXvYqyRXSuD61JfM22IXd0w+lppHSUV/80+e5vdA5pA0npV/BLLQQDCMwYd4ZxmHMoMq7zQkM4VoQ== X-Received: by 2002:a2e:548:: with SMTP id 69mr19055598ljf.67.1579688152956; Wed, 22 Jan 2020 02:15:52 -0800 (PST) Received: from xi.terra (c-14b8e655.07-184-6d6c6d4.bbcust.telenor.se. [85.230.184.20]) by smtp.gmail.com with ESMTPSA id w9sm20003449ljh.106.2020.01.22.02.15.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jan 2020 02:15:51 -0800 (PST) Received: from johan by xi.terra with local (Exim 4.92.3) (envelope-from ) id 1iuD34-0007bj-Fl; Wed, 22 Jan 2020 11:15:46 +0100 From: Johan Hovold To: Johan Hovold Cc: linux-usb@vger.kernel.org Subject: [PATCH 4/5] USB: serial: ir-usb: make set_termios synchronous Date: Wed, 22 Jan 2020 11:15:29 +0100 Message-Id: <20200122101530.29176-5-johan@kernel.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200122101530.29176-1-johan@kernel.org> References: <20200122101530.29176-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 Use a synchronous usb_bulk_msg() when switching link speed in set_termios(). This way we do not need to keep track of outstanding URBs in order to be able to stop them at close. Note that there's no need to set URB_ZERO_PACKET as the one-byte transfer will always be short. Signed-off-by: Johan Hovold Reviewed-by: Greg Kroah-Hartman --- drivers/usb/serial/ir-usb.c | 50 ++++++++----------------------------- 1 file changed, 11 insertions(+), 39 deletions(-) diff --git a/drivers/usb/serial/ir-usb.c b/drivers/usb/serial/ir-usb.c index 627bea7e6cfb..3cd70392e2a2 100644 --- a/drivers/usb/serial/ir-usb.c +++ b/drivers/usb/serial/ir-usb.c @@ -376,23 +376,15 @@ static void ir_process_read_urb(struct urb *urb) tty_flip_buffer_push(&port->port); } -static void ir_set_termios_callback(struct urb *urb) -{ - kfree(urb->transfer_buffer); - - if (urb->status) - dev_dbg(&urb->dev->dev, "%s - non-zero urb status: %d\n", - __func__, urb->status); -} - static void ir_set_termios(struct tty_struct *tty, struct usb_serial_port *port, struct ktermios *old_termios) { - struct urb *urb; + struct usb_device *udev = port->serial->dev; unsigned char *transfer_buffer; - int result; + int actual_length; speed_t baud; int ir_baud; + int ret; baud = tty_get_baud_rate(tty); @@ -447,42 +439,22 @@ static void ir_set_termios(struct tty_struct *tty, /* * send the baud change out on an "empty" data packet */ - urb = usb_alloc_urb(0, GFP_KERNEL); - if (!urb) - return; - transfer_buffer = kmalloc(1, GFP_KERNEL); if (!transfer_buffer) - goto err_buf; + return; *transfer_buffer = ir_xbof | ir_baud; - usb_fill_bulk_urb( - urb, - port->serial->dev, - usb_sndbulkpipe(port->serial->dev, - port->bulk_out_endpointAddress), - transfer_buffer, - 1, - ir_set_termios_callback, - port); - - urb->transfer_flags = URB_ZERO_PACKET; - - result = usb_submit_urb(urb, GFP_KERNEL); - if (result) { - dev_err(&port->dev, "%s - failed to submit urb: %d\n", - __func__, result); - goto err_subm; + ret = usb_bulk_msg(udev, + usb_sndbulkpipe(udev, port->bulk_out_endpointAddress), + transfer_buffer, 1, &actual_length, 5000); + if (ret || actual_length != 1) { + if (actual_length != 1) + ret = -EIO; + dev_err(&port->dev, "failed to change line speed: %d\n", ret); } - usb_free_urb(urb); - - return; -err_subm: kfree(transfer_buffer); -err_buf: - usb_free_urb(urb); } static int __init ir_init(void) From patchwork Wed Jan 22 10:15:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 11345457 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 25BE76C1 for ; Wed, 22 Jan 2020 10:15:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EF06524683 for ; Wed, 22 Jan 2020 10:15:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579688159; bh=G5guZfxh4VLPtwbaauUs74YShpzAEj3HkARKkD2vSjU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=iDkM0Lk+V3nQWk26f6raW6wTVI9okeJXDAVqlG7s2+3vmPunCE4wkHt8RRQasNXZF CAOIbyZglLDq6HsR4ZVDuo6WA95SHJY/IgE6ByiaCT9MS7FwCqnlizxBGzdrMD+MHk oeY80Q4E6bH92i3IfrtZgPl5nFRflzRdvSZ8ZUOI= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729527AbgAVKP5 (ORCPT ); Wed, 22 Jan 2020 05:15:57 -0500 Received: from mail-lj1-f196.google.com ([209.85.208.196]:41506 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729281AbgAVKPz (ORCPT ); Wed, 22 Jan 2020 05:15:55 -0500 Received: by mail-lj1-f196.google.com with SMTP id h23so6136395ljc.8 for ; Wed, 22 Jan 2020 02:15:54 -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=Zn1emOAVflAfF5vEbElXusgVmExLsTwagOS9rshaUA4=; b=YBRYL7Qa8x2+M/w6yKz1LruUhBeu4eWaSQnkSsQHgDnnJZJ8hKLH4w2TsEE0JVVTwh aB+VItnKJqZ2b9s9dc6NhgTdmbZG70Oq2lc4Waz0FzUr+J4yZWoC0o2LHRXPHMdy1X7G qj/8z/y81BpsB0kx9AJV9z5uPwUBmIFdg3Ovx281BlajmJX2q34yen1FpQryq72KeEbf zZR70I+lCBe42688gLt3re1e7onXtBGFCHg1oEQGB7qe8ys3V2kbfNkinzIR4Jx913Of PCdq1tBn8SACsO6o47UfXs+PXO+9l+jVqIpRtnHGN7MRX1uP0DuNAgOh8aw2DUkpXeFG mQ3w== X-Gm-Message-State: APjAAAX/ijlRhXRsB3PEzZ9UphhN2h+rs+QT+waMnhU/+suGf5pAdkE7 qxY6IkfUUUgr7T9zf8JCPkfya2lk X-Google-Smtp-Source: APXvYqzMnNbWIXIefAZTc9OdV6AIr+ALaAImCOZDINFAMuERhuDXLIrVIkhta8WtjE8YeunGzbxdbQ== X-Received: by 2002:a2e:b044:: with SMTP id d4mr17766198ljl.158.1579688153345; Wed, 22 Jan 2020 02:15:53 -0800 (PST) Received: from xi.terra (c-14b8e655.07-184-6d6c6d4.bbcust.telenor.se. [85.230.184.20]) by smtp.gmail.com with ESMTPSA id n3sm20628886lfk.61.2020.01.22.02.15.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jan 2020 02:15:51 -0800 (PST) Received: from johan by xi.terra with local (Exim 4.92.3) (envelope-from ) id 1iuD34-0007bo-J4; Wed, 22 Jan 2020 11:15:46 +0100 From: Johan Hovold To: Johan Hovold Cc: linux-usb@vger.kernel.org Subject: [PATCH 5/5] USB: serial: ir-usb: simplify endpoint check Date: Wed, 22 Jan 2020 11:15:30 +0100 Message-Id: <20200122101530.29176-6-johan@kernel.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200122101530.29176-1-johan@kernel.org> References: <20200122101530.29176-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 Simplify the endpoint sanity check by letting core verify that the required endpoints are present. Signed-off-by: Johan Hovold Reviewed-by: Greg Kroah-Hartman --- drivers/usb/serial/ir-usb.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/usb/serial/ir-usb.c b/drivers/usb/serial/ir-usb.c index 3cd70392e2a2..79d0586e2b33 100644 --- a/drivers/usb/serial/ir-usb.c +++ b/drivers/usb/serial/ir-usb.c @@ -76,6 +76,8 @@ static struct usb_serial_driver ir_device = { .description = "IR Dongle", .id_table = ir_id_table, .num_ports = 1, + .num_bulk_in = 1, + .num_bulk_out = 1, .set_termios = ir_set_termios, .attach = ir_startup, .write = ir_write, @@ -197,9 +199,6 @@ static int ir_startup(struct usb_serial *serial) struct usb_irda_cs_descriptor *irda_desc; int rates; - if (serial->num_bulk_in < 1 || serial->num_bulk_out < 1) - return -ENODEV; - irda_desc = irda_usb_find_class_desc(serial, 0); if (!irda_desc) { dev_err(&serial->dev->dev,