From patchwork Sat Jul 13 21:10:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ladislav Michl X-Patchwork-Id: 11043135 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E48D11395 for ; Sat, 13 Jul 2019 21:10:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D07A9219AC for ; Sat, 13 Jul 2019 21:10:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BF4842223E; Sat, 13 Jul 2019 21:10:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 51D28219AC for ; Sat, 13 Jul 2019 21:10:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728016AbfGMVKe (ORCPT ); Sat, 13 Jul 2019 17:10:34 -0400 Received: from eddie.linux-mips.org ([148.251.95.138]:37654 "EHLO cvs.linux-mips.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727553AbfGMVKe (ORCPT ); Sat, 13 Jul 2019 17:10:34 -0400 Received: (from localhost user: 'ladis' uid#1021 fake: STDIN (ladis@eddie.linux-mips.org)) by eddie.linux-mips.org id S23992479AbfGMVKcjU9tN (ORCPT + 1 other); Sat, 13 Jul 2019 23:10:32 +0200 Date: Sat, 13 Jul 2019 23:10:31 +0200 From: Ladislav Michl To: linux-usb@vger.kernel.org, linux-serial@vger.kernel.org Cc: Felipe Balbi , Greg Kroah-Hartman , =?iso-8859-2?q?Micha=B3_Mi?= =?iso-8859-2?q?ros=B3aw?= Subject: [PATCH v2 1/5] usb: gadget: u_serial: Fix console_req complete event race Message-ID: <20190713211031.GB25753@lenoch> References: <20190713210853.GA25753@lenoch> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20190713210853.GA25753@lenoch> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP gs_complete_out might be called before con_lock following usb_ep_queue is locked, which prevents any future output on the console. Fix that by resetting req_busy only if usb_ep_queue fails. While there also put variable access we are racing with connection/disconnection events under con_lock as well. Fixes: a5beaaf39455 ("usb: gadget: Add the console support for usb-to-serial port") Signed-off-by: Ladislav Michl --- Changes: - v2: None drivers/usb/gadget/function/u_serial.c | 41 +++++++++++--------------- 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/drivers/usb/gadget/function/u_serial.c b/drivers/usb/gadget/function/u_serial.c index 65f634ec7fc2..876af4085cea 100644 --- a/drivers/usb/gadget/function/u_serial.c +++ b/drivers/usb/gadget/function/u_serial.c @@ -984,47 +984,40 @@ static int gs_console_thread(void *data) struct gs_port *port; struct usb_request *req; struct usb_ep *ep; - int xfer, ret, count, size; + int len, size, status; + spin_lock_irq(&info->con_lock); do { port = info->port; - set_current_state(TASK_INTERRUPTIBLE); - if (!port || !port->port_usb - || !port->port_usb->in || !info->console_req) + if (!port || !port->port_usb || !info->console_req) goto sched; req = info->console_req; ep = port->port_usb->in; + len = kfifo_len(&info->con_buf); + if (len > 0 && !info->req_busy) { + size = ep->maxpacket; + if (len < size) + size = len; - spin_lock_irq(&info->con_lock); - count = kfifo_len(&info->con_buf); - size = ep->maxpacket; - - if (count > 0 && !info->req_busy) { - set_current_state(TASK_RUNNING); - if (count < size) - size = count; - - xfer = kfifo_out(&info->con_buf, req->buf, size); - req->length = xfer; - - spin_unlock(&info->con_lock); - ret = usb_ep_queue(ep, req, GFP_ATOMIC); - spin_lock(&info->con_lock); - if (ret < 0) - info->req_busy = 0; - else - info->req_busy = 1; + req->length = kfifo_out(&info->con_buf, req->buf, size); + info->req_busy = 1; spin_unlock_irq(&info->con_lock); + status = usb_ep_queue(ep, req, GFP_ATOMIC); + spin_lock_irq(&info->con_lock); + if (status < 0) + info->req_busy = 0; } else { - spin_unlock_irq(&info->con_lock); sched: + spin_unlock_irq(&info->con_lock); if (kthread_should_stop()) { set_current_state(TASK_RUNNING); break; } schedule(); + set_current_state(TASK_INTERRUPTIBLE); + spin_lock_irq(&info->con_lock); } } while (1); From patchwork Sat Jul 13 21:10:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ladislav Michl X-Patchwork-Id: 11043137 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7AA416C5 for ; Sat, 13 Jul 2019 21:11:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 66B87219AC for ; Sat, 13 Jul 2019 21:11:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 559412223E; Sat, 13 Jul 2019 21:11:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E6647219AC for ; Sat, 13 Jul 2019 21:11:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728051AbfGMVLA (ORCPT ); Sat, 13 Jul 2019 17:11:00 -0400 Received: from eddie.linux-mips.org ([148.251.95.138]:37654 "EHLO cvs.linux-mips.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727553AbfGMVLA (ORCPT ); Sat, 13 Jul 2019 17:11:00 -0400 Received: (from localhost user: 'ladis' uid#1021 fake: STDIN (ladis@eddie.linux-mips.org)) by eddie.linux-mips.org id S23992479AbfGMVK7AdiON (ORCPT + 1 other); Sat, 13 Jul 2019 23:10:59 +0200 Date: Sat, 13 Jul 2019 23:10:58 +0200 From: Ladislav Michl To: linux-usb@vger.kernel.org, linux-serial@vger.kernel.org Cc: Felipe Balbi , Greg Kroah-Hartman , =?iso-8859-2?q?Micha=B3_Mi?= =?iso-8859-2?q?ros=B3aw?= Subject: [PATCH v2 2/5] usb: gadget: u_serial: Remove console specific alloc/free req functions Message-ID: <20190713211057.GC25753@lenoch> References: <20190713210853.GA25753@lenoch> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20190713210853.GA25753@lenoch> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Driver already contains request allocation and deallocation functions, so use them also for console_req. Signed-off-by: Ladislav Michl --- Changes: - v2: Move locking changes into separate patch drivers/usb/gadget/function/u_serial.c | 28 ++------------------------ 1 file changed, 2 insertions(+), 26 deletions(-) diff --git a/drivers/usb/gadget/function/u_serial.c b/drivers/usb/gadget/function/u_serial.c index 876af4085cea..cb88a640179e 100644 --- a/drivers/usb/gadget/function/u_serial.c +++ b/drivers/usb/gadget/function/u_serial.c @@ -892,30 +892,6 @@ static struct tty_driver *gs_tty_driver; static struct gscons_info gscons_info; static struct console gserial_cons; -static struct usb_request *gs_request_new(struct usb_ep *ep) -{ - struct usb_request *req = usb_ep_alloc_request(ep, GFP_ATOMIC); - if (!req) - return NULL; - - req->buf = kmalloc(ep->maxpacket, GFP_ATOMIC); - if (!req->buf) { - usb_ep_free_request(ep, req); - return NULL; - } - - return req; -} - -static void gs_request_free(struct usb_request *req, struct usb_ep *ep) -{ - if (!req) - return; - - kfree(req->buf); - usb_ep_free_request(ep, req); -} - static void gs_complete_out(struct usb_ep *ep, struct usb_request *req) { struct gscons_info *info = &gscons_info; @@ -955,7 +931,7 @@ static int gs_console_connect(int port_num) port = ports[port_num].port; ep = port->port_usb->in; if (!info->console_req) { - info->console_req = gs_request_new(ep); + info->console_req = gs_alloc_req(ep, ep->maxpacket, GFP_ATOMIC); if (!info->console_req) return -ENOMEM; info->console_req->complete = gs_complete_out; @@ -974,7 +950,7 @@ static void gs_console_disconnect(struct usb_ep *ep) struct gscons_info *info = &gscons_info; struct usb_request *req = info->console_req; - gs_request_free(req, ep); + gs_free_req(ep, req); info->console_req = NULL; } From patchwork Sat Jul 13 21:11:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ladislav Michl X-Patchwork-Id: 11043139 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 114A71395 for ; Sat, 13 Jul 2019 21:11:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 001432821F for ; Sat, 13 Jul 2019 21:11:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E58A4282EC; Sat, 13 Jul 2019 21:11:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8C7E92821F for ; Sat, 13 Jul 2019 21:11:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728065AbfGMVLZ (ORCPT ); Sat, 13 Jul 2019 17:11:25 -0400 Received: from eddie.linux-mips.org ([148.251.95.138]:37654 "EHLO cvs.linux-mips.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727553AbfGMVLZ (ORCPT ); Sat, 13 Jul 2019 17:11:25 -0400 Received: (from localhost user: 'ladis' uid#1021 fake: STDIN (ladis@eddie.linux-mips.org)) by eddie.linux-mips.org id S23992479AbfGMVLXnQrDN (ORCPT + 1 other); Sat, 13 Jul 2019 23:11:23 +0200 Date: Sat, 13 Jul 2019 23:11:22 +0200 From: Ladislav Michl To: linux-usb@vger.kernel.org, linux-serial@vger.kernel.org Cc: Felipe Balbi , Greg Kroah-Hartman , =?iso-8859-2?q?Micha=B3_Mi?= =?iso-8859-2?q?ros=B3aw?= Subject: [PATCH v2 3/5] usb: gadget: u_serial: Fix console_req access race Message-ID: <20190713211122.GD25753@lenoch> References: <20190713210853.GA25753@lenoch> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20190713210853.GA25753@lenoch> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP console_req is always null when calling gs_console_connect, so remove check and put access under con_lock as we are racing with gs_console_thread. Signed-off-by: Ladislav Michl --- Changes: - v2: New patch drivers/usb/gadget/function/u_serial.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/drivers/usb/gadget/function/u_serial.c b/drivers/usb/gadget/function/u_serial.c index cb88a640179e..558a6929ce68 100644 --- a/drivers/usb/gadget/function/u_serial.c +++ b/drivers/usb/gadget/function/u_serial.c @@ -930,15 +930,12 @@ static int gs_console_connect(int port_num) port = ports[port_num].port; ep = port->port_usb->in; - if (!info->console_req) { - info->console_req = gs_alloc_req(ep, ep->maxpacket, GFP_ATOMIC); - if (!info->console_req) - return -ENOMEM; - info->console_req->complete = gs_complete_out; - } - - info->port = port; spin_lock(&info->con_lock); + info->console_req = gs_alloc_req(ep, ep->maxpacket, GFP_ATOMIC); + if (!info->console_req) + return -ENOMEM; + info->console_req->complete = gs_complete_out; + info->port = port; info->req_busy = 0; spin_unlock(&info->con_lock); pr_vdebug("port[%d] console connect!\n", port_num); @@ -948,10 +945,11 @@ static int gs_console_connect(int port_num) static void gs_console_disconnect(struct usb_ep *ep) { struct gscons_info *info = &gscons_info; - struct usb_request *req = info->console_req; - gs_free_req(ep, req); + spin_lock(&info->con_lock); + gs_free_req(ep, info->console_req); info->console_req = NULL; + spin_unlock(&info->con_lock); } static int gs_console_thread(void *data) @@ -1008,7 +1006,6 @@ static int gs_console_setup(struct console *co, char *options) info->port = NULL; info->console_req = NULL; info->req_busy = 0; - spin_lock_init(&info->con_lock); status = kfifo_alloc(&info->con_buf, GS_CONSOLE_BUF_SIZE, GFP_KERNEL); if (status) { @@ -1064,6 +1061,9 @@ static struct console gserial_cons = { static void gserial_console_init(void) { + struct gscons_info *info = &gscons_info; + + spin_lock_init(&info->con_lock); register_console(&gserial_cons); } From patchwork Sat Jul 13 21:11:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ladislav Michl X-Patchwork-Id: 11043141 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9F1BE6C5 for ; Sat, 13 Jul 2019 21:12:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8B13C2821F for ; Sat, 13 Jul 2019 21:12:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7C6422832B; Sat, 13 Jul 2019 21:12:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F1D3E2821F for ; Sat, 13 Jul 2019 21:12:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728080AbfGMVMC (ORCPT ); Sat, 13 Jul 2019 17:12:02 -0400 Received: from eddie.linux-mips.org ([148.251.95.138]:37654 "EHLO cvs.linux-mips.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727553AbfGMVMB (ORCPT ); Sat, 13 Jul 2019 17:12:01 -0400 Received: (from localhost user: 'ladis' uid#1021 fake: STDIN (ladis@eddie.linux-mips.org)) by eddie.linux-mips.org id S23992479AbfGMVMAQB0uN (ORCPT + 1 other); Sat, 13 Jul 2019 23:12:00 +0200 Date: Sat, 13 Jul 2019 23:11:58 +0200 From: Ladislav Michl To: linux-usb@vger.kernel.org, linux-serial@vger.kernel.org Cc: Felipe Balbi , Greg Kroah-Hartman , =?iso-8859-2?q?Micha=B3_Mi?= =?iso-8859-2?q?ros=B3aw?= Subject: [PATCH v2 4/5] usb: gadget: u_serial: Fix starving write Message-ID: <20190713211158.GE25753@lenoch> References: <20190713210853.GA25753@lenoch> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20190713210853.GA25753@lenoch> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Writing to ttyGS unconnected to host currently fills port_write_buf which then causes gs_write_room to return 0 and boot hangs waiting for connection. Fix that by dropping previsous data if free space in port_write_buf reaches treshold and host is unconnected. Signed-off-by: Ladislav Michl --- Changes: - v2: New patch drivers/usb/gadget/function/u_serial.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/drivers/usb/gadget/function/u_serial.c b/drivers/usb/gadget/function/u_serial.c index 558a6929ce68..2dd6e1211d4a 100644 --- a/drivers/usb/gadget/function/u_serial.c +++ b/drivers/usb/gadget/function/u_serial.c @@ -79,6 +79,7 @@ */ #define QUEUE_SIZE 16 #define WRITE_BUF_SIZE 8192 /* TX only */ +#define WRITE_BUF_TRESHOLD 1024 #define GS_CONSOLE_BUF_SIZE 8192 /* console info */ @@ -562,7 +563,7 @@ static int gs_start_io(struct gs_port *port) /* unblock any pending writes into our circular buffer */ if (started) { - tty_wakeup(port->port.tty); + gs_start_tx(port); } else { gs_free_requests(ep, head, &port->read_allocated); gs_free_requests(port->port_usb->in, &port->write_pool, @@ -758,6 +759,7 @@ static int gs_write(struct tty_struct *tty, const unsigned char *buf, int count) { struct gs_port *port = tty->driver_data; unsigned long flags; + int avail, cnt; pr_vdebug("gs_write: ttyGS%d (%p) writing %d bytes\n", port->port_num, tty, count); @@ -766,8 +768,16 @@ static int gs_write(struct tty_struct *tty, const unsigned char *buf, int count) if (count) count = kfifo_in(&port->port_write_buf, buf, count); /* treat count == 0 as flush_chars() */ - if (port->port_usb) + if (port->port_usb) { gs_start_tx(port); + } else { + avail = kfifo_avail(&port->port_write_buf); + if (avail < WRITE_BUF_TRESHOLD) { + cnt = WRITE_BUF_TRESHOLD - avail; + while (cnt--) + kfifo_skip(&port->port_write_buf); + } + } spin_unlock_irqrestore(&port->port_lock, flags); return count; @@ -784,6 +794,9 @@ static int gs_put_char(struct tty_struct *tty, unsigned char ch) spin_lock_irqsave(&port->port_lock, flags); status = kfifo_put(&port->port_write_buf, ch); + if (!port->port_usb && + kfifo_avail(&port->port_write_buf) < WRITE_BUF_TRESHOLD) + kfifo_skip(&port->port_write_buf); spin_unlock_irqrestore(&port->port_lock, flags); return status; @@ -799,6 +812,8 @@ static void gs_flush_chars(struct tty_struct *tty) spin_lock_irqsave(&port->port_lock, flags); if (port->port_usb) gs_start_tx(port); + else + kfifo_reset_out(&port->port_write_buf); spin_unlock_irqrestore(&port->port_lock, flags); } @@ -806,11 +821,10 @@ static int gs_write_room(struct tty_struct *tty) { struct gs_port *port = tty->driver_data; unsigned long flags; - int room = 0; + int room; spin_lock_irqsave(&port->port_lock, flags); - if (port->port_usb) - room = kfifo_avail(&port->port_write_buf); + room = kfifo_avail(&port->port_write_buf); spin_unlock_irqrestore(&port->port_lock, flags); pr_vdebug("gs_write_room: (%d,%p) room=%d\n", @@ -823,7 +837,7 @@ static int gs_chars_in_buffer(struct tty_struct *tty) { struct gs_port *port = tty->driver_data; unsigned long flags; - int chars = 0; + int chars; spin_lock_irqsave(&port->port_lock, flags); chars = kfifo_len(&port->port_write_buf); From patchwork Sat Jul 13 21:12:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ladislav Michl X-Patchwork-Id: 11043143 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DC11D6C5 for ; Sat, 13 Jul 2019 21:12:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CB2F32821F for ; Sat, 13 Jul 2019 21:12:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BF3B32832B; Sat, 13 Jul 2019 21:12:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 521D12821F for ; Sat, 13 Jul 2019 21:12:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728086AbfGMVMj (ORCPT ); Sat, 13 Jul 2019 17:12:39 -0400 Received: from eddie.linux-mips.org ([148.251.95.138]:37654 "EHLO cvs.linux-mips.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727553AbfGMVMj (ORCPT ); Sat, 13 Jul 2019 17:12:39 -0400 Received: (from localhost user: 'ladis' uid#1021 fake: STDIN (ladis@eddie.linux-mips.org)) by eddie.linux-mips.org id S23992886AbfGMVMh6VykN (ORCPT + 1 other); Sat, 13 Jul 2019 23:12:37 +0200 Date: Sat, 13 Jul 2019 23:12:33 +0200 From: Ladislav Michl To: linux-usb@vger.kernel.org, linux-serial@vger.kernel.org Cc: Felipe Balbi , Greg Kroah-Hartman , =?iso-8859-2?q?Micha=B3_Mi?= =?iso-8859-2?q?ros=B3aw?= Subject: [PATCH v2 5/5] usb: gadget: u_serial: Use bool for req_busy Message-ID: <20190713211233.GF25753@lenoch> References: <20190713210853.GA25753@lenoch> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20190713210853.GA25753@lenoch> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Let's make code more consistent by using bool for req_busy as it is done for similar variables in struct gs_port. Signed-off-by: Ladislav Michl --- Changes: - v2: None drivers/usb/gadget/function/u_serial.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/drivers/usb/gadget/function/u_serial.c b/drivers/usb/gadget/function/u_serial.c index 2dd6e1211d4a..1b1359a168e7 100644 --- a/drivers/usb/gadget/function/u_serial.c +++ b/drivers/usb/gadget/function/u_serial.c @@ -89,7 +89,7 @@ struct gscons_info { struct kfifo con_buf; /* protect the buf and busy flag */ spinlock_t con_lock; - int req_busy; + bool req_busy; struct usb_request *console_req; }; @@ -918,7 +918,7 @@ static void gs_complete_out(struct usb_ep *ep, struct usb_request *req) case 0: /* normal completion */ spin_lock(&info->con_lock); - info->req_busy = 0; + info->req_busy = false; spin_unlock(&info->con_lock); wake_up_process(info->console_thread); @@ -950,7 +950,6 @@ static int gs_console_connect(int port_num) return -ENOMEM; info->console_req->complete = gs_complete_out; info->port = port; - info->req_busy = 0; spin_unlock(&info->con_lock); pr_vdebug("port[%d] console connect!\n", port_num); return 0; @@ -989,13 +988,13 @@ static int gs_console_thread(void *data) size = len; req->length = kfifo_out(&info->con_buf, req->buf, size); - info->req_busy = 1; + info->req_busy = true; spin_unlock_irq(&info->con_lock); status = usb_ep_queue(ep, req, GFP_ATOMIC); spin_lock_irq(&info->con_lock); if (status < 0) - info->req_busy = 0; + info->req_busy = false; } else { sched: spin_unlock_irq(&info->con_lock); @@ -1019,7 +1018,7 @@ static int gs_console_setup(struct console *co, char *options) info->port = NULL; info->console_req = NULL; - info->req_busy = 0; + info->req_busy = false; status = kfifo_alloc(&info->con_buf, GS_CONSOLE_BUF_SIZE, GFP_KERNEL); if (status) {