From patchwork Sun Oct 25 17:45:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 11855345 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 1FFF092C for ; Sun, 25 Oct 2020 17:46:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F04F62222F for ; Sun, 25 Oct 2020 17:46:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603648003; bh=LPrg6dLW7sGXa35L0giBDfda+ByF0261ZFvh0hJ1k2g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=J9lCd/5REFcQvOuKMPV26J/46rL4k4TacxMg72WTqNocLQSDJZvlU/VgE5uSouUNF 7Pr0Q/p4TwPdOe5cT0XZrEc9/5buB9VqPwdydRye1hSbamorbYIKFJfP3OVhK6zyU7 qjsHQCB9O8IbHUW7Na6TZtEvF40UXTYZgV8L+ym0= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1417724AbgJYRqj (ORCPT ); Sun, 25 Oct 2020 13:46:39 -0400 Received: from mail-lj1-f194.google.com ([209.85.208.194]:38412 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1417705AbgJYRqi (ORCPT ); Sun, 25 Oct 2020 13:46:38 -0400 Received: by mail-lj1-f194.google.com with SMTP id m20so7303258ljj.5; Sun, 25 Oct 2020 10:46:36 -0700 (PDT) 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=ryLZzM6AeLljw7FhT9jJjorgcKimBmMyaAgnsuFGOJ8=; b=sw5KEo9n0mtrgSpZuX/PubMGgcYb3gohfDN5lssABBRCO+RvKNN64gML3g10fjGosE a36zHJouFKw+7bkVI+EcGta0Yt0mvlvYX3pyspeR/Yv5y6FFjGmXOKztJ+2UlEqhH5Z7 WAYKRlH2mx7wawrPgo+e++z2usFodGWwmhVgRE/PK20yj6KqNSQyiAh7dsFvZlimqctO tRDAoAhhdbUuk5IcAanZluJQnQfc1p20am79AcnHbvrlFl7R+8kb/rOTB+92Pzf7bl/E 73H6GQr/58lHDF71G/DKI3zCKNvtWTz12+K9CrjWorFxdL04h7NN09U1CpM/lR9xy6+O 9bdg== X-Gm-Message-State: AOAM532BJ4aMpf+sR+TGy66kdxwf5MmedfpzHxy25sGHjfK5YdU9CKCb 0+CzPGf1cfeTzEwUTMreoGbHIMQQWMTfxA== X-Google-Smtp-Source: ABdhPJzp9+8tU7hNK8dUch6AG4rzoM8aZWmKlQbR7EyEo7boJbW7ZHtMArRSx2nMe9x4IKw+v/7V6A== X-Received: by 2002:a2e:8096:: with SMTP id i22mr3937528ljg.176.1603647995906; Sun, 25 Oct 2020 10:46:35 -0700 (PDT) Received: from xi.terra (c-beaee455.07-184-6d6c6d4.bbcust.telenor.se. [85.228.174.190]) by smtp.gmail.com with ESMTPSA id d7sm875735ljg.140.2020.10.25.10.46.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Oct 2020 10:46:34 -0700 (PDT) Received: from johan by xi.terra with local (Exim 4.93.0.4) (envelope-from ) id 1kWk6I-0007HA-G8; Sun, 25 Oct 2020 18:46:38 +0100 From: Johan Hovold To: linux-usb@vger.kernel.org Cc: "Ahmed S . Darwish" , Sebastian Andrzej Siewior , Thomas Gleixner , linux-kernel@vger.kernel.org, Johan Hovold , stable Subject: [PATCH 01/14] USB: serial: keyspan_pda: fix dropped unthrottle interrupts Date: Sun, 25 Oct 2020 18:45:47 +0100 Message-Id: <20201025174600.27896-2-johan@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201025174600.27896-1-johan@kernel.org> References: <20201025174600.27896-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Commit c528fcb116e6 ("USB: serial: keyspan_pda: fix receive sanity checks") broke write-unthrottle handling by dropping well-formed unthrottle-interrupt packets which are precisely two bytes long. This could lead to blocked writers not being woken up when buffer space again becomes available. Instead, stop unconditionally printing the third byte which is (presumably) only valid on modem-line changes. Fixes: c528fcb116e6 ("USB: serial: keyspan_pda: fix receive sanity checks") Cc: stable # 4.11 Signed-off-by: Johan Hovold --- drivers/usb/serial/keyspan_pda.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/usb/serial/keyspan_pda.c b/drivers/usb/serial/keyspan_pda.c index c1333919716b..2d5ad579475a 100644 --- a/drivers/usb/serial/keyspan_pda.c +++ b/drivers/usb/serial/keyspan_pda.c @@ -172,11 +172,11 @@ static void keyspan_pda_rx_interrupt(struct urb *urb) break; case 1: /* status interrupt */ - if (len < 3) { + if (len < 2) { dev_warn(&port->dev, "short interrupt message received\n"); break; } - dev_dbg(&port->dev, "rx int, d1=%d, d2=%d\n", data[1], data[2]); + dev_dbg(&port->dev, "rx int, d1=%d\n", data[1]); switch (data[1]) { case 1: /* modemline change */ break; From patchwork Sun Oct 25 17:45:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 11855367 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 DCF12697 for ; Sun, 25 Oct 2020 17:48:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C4BD6222EA for ; Sun, 25 Oct 2020 17:48:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603648081; bh=wU5kdLqGuPzou5pOyQ2zQZZwZSSlZsVUATCf7FpjFJE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=2KxuXSHhVlNsW4lSueB4fmt5EWG6QfTDhjdufcedQ3xsjSviNH78agX0AimeO6uYn fgTUCVSOQInvdxoUbXFcZTzHEUssH1IsqFiWlalSb27XjHvlL7O4k+P84BJtj/yvJk KrLHzwZDAjx4gJeA/mjpIX+mK3tbQgVZDQOC0FpM= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1417863AbgJYRsA (ORCPT ); Sun, 25 Oct 2020 13:48:00 -0400 Received: from mail-lj1-f196.google.com ([209.85.208.196]:37198 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1417706AbgJYRqj (ORCPT ); Sun, 25 Oct 2020 13:46:39 -0400 Received: by mail-lj1-f196.google.com with SMTP id i2so7286354ljg.4; Sun, 25 Oct 2020 10:46:38 -0700 (PDT) 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=8F5bIaxdX0w1ouDNYj2bcxzTc3dOdSXKUtWoL55jsSs=; b=GjnRw5jyGUquqq7ClfTNt2lJah8pcLnv+/Wu7+cuEP26L8MKrr/d0IZKVdkG0b06A1 HV0SElbUagF5e4X1YY7VU69OaeP0AOyOLZixD1RBa3muvKmHXugig7a9iTOJ4Jf+wZ83 /ZTkkk5SK99f5DE0AJg1s51uOwN6bqiTwwNtIWIlP/Cvhu/qD7pC491ynINh32oJBQdT B1mak+Q+gAUG8KrigIqk+4wm5DaXxO3vUsktg+FWS5dFeSRt8PhaiN4JKgy+hwOQs4fy X2gPLn8HYC2iTjyhMtQYQAB6lkfu0FuhbhvLZRpDSIBQacOEMn9bTYL8rNxevcBu+xrF uGnQ== X-Gm-Message-State: AOAM531Zk0tzBIi6ejsNwlWGKNOCbJAeSVXRIHc3bmMTF1E9Ri2a/cOf lEZo+AWAeKuEO63xwr/1qGk5lYVZUBau4A== X-Google-Smtp-Source: ABdhPJyAZnlLiVQGH9JpmXnwbzpxeBbCOjWEjNVHAbx8vvb0U0Z4GJNV1tjTZaMnjdyEx6NQx+6X/A== X-Received: by 2002:a2e:8e6c:: with SMTP id t12mr4059103ljk.432.1603647996931; Sun, 25 Oct 2020 10:46:36 -0700 (PDT) Received: from xi.terra (c-beaee455.07-184-6d6c6d4.bbcust.telenor.se. [85.228.174.190]) by smtp.gmail.com with ESMTPSA id m18sm795963lfb.35.2020.10.25.10.46.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Oct 2020 10:46:34 -0700 (PDT) Received: from johan by xi.terra with local (Exim 4.93.0.4) (envelope-from ) id 1kWk6I-0007HF-JL; Sun, 25 Oct 2020 18:46:38 +0100 From: Johan Hovold To: linux-usb@vger.kernel.org Cc: "Ahmed S . Darwish" , Sebastian Andrzej Siewior , Thomas Gleixner , linux-kernel@vger.kernel.org, Johan Hovold , stable Subject: [PATCH 02/14] USB: serial: keyspan_pda: fix write deadlock Date: Sun, 25 Oct 2020 18:45:48 +0100 Message-Id: <20201025174600.27896-3-johan@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201025174600.27896-1-johan@kernel.org> References: <20201025174600.27896-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The write() callback can be called in interrupt context (e.g. when used as a console) so interrupts must be disabled while holding the port lock to prevent a possible deadlock. Fixes: e81ee637e4ae ("usb-serial: possible irq lock inversion (PPP vs. usb/serial)") Fixes: 507ca9bc0476 ("[PATCH] USB: add ability for usb-serial drivers to determine if their write urb is currently being used.") Cc: stable # 2.6.19 Signed-off-by: Johan Hovold --- drivers/usb/serial/keyspan_pda.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/usb/serial/keyspan_pda.c b/drivers/usb/serial/keyspan_pda.c index 2d5ad579475a..17b60e5a9f1f 100644 --- a/drivers/usb/serial/keyspan_pda.c +++ b/drivers/usb/serial/keyspan_pda.c @@ -443,6 +443,7 @@ static int keyspan_pda_write(struct tty_struct *tty, int request_unthrottle = 0; int rc = 0; struct keyspan_pda_private *priv; + unsigned long flags; priv = usb_get_serial_port_data(port); /* guess how much room is left in the device's ring buffer, and if we @@ -462,13 +463,13 @@ static int keyspan_pda_write(struct tty_struct *tty, the TX urb is in-flight (wait until it completes) the device is full (wait until it says there is room) */ - spin_lock_bh(&port->lock); + spin_lock_irqsave(&port->lock, flags); if (!test_bit(0, &port->write_urbs_free) || priv->tx_throttled) { - spin_unlock_bh(&port->lock); + spin_unlock_irqrestore(&port->lock, flags); return 0; } clear_bit(0, &port->write_urbs_free); - spin_unlock_bh(&port->lock); + spin_unlock_irqrestore(&port->lock, flags); /* At this point the URB is in our control, nobody else can submit it again (the only sudden transition was the one from EINPROGRESS to From patchwork Sun Oct 25 17:45:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 11855371 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 499C4697 for ; Sun, 25 Oct 2020 17:48:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 315642222F for ; Sun, 25 Oct 2020 17:48:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603648089; bh=rqS7t/UuqJYJA1VxRf6YfQd08Cm/w7bEF0DCTndfkEw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=CpTM/kMiA8fwqnJ/UcgzqOCGGoIYRQ4iY0JQiIQj76PJpRu0WCgMzjqjq+bpMozaY QQohfQ5fNYC9yQk/UwQ0+yjPaVZCAsAlgpx60rDu8skmeZjsO8TyUY+qmxQocUF0u+ WwBL0np5T4PysSmRPqKTx1Evdsm21cgzWo8vWphM= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1417876AbgJYRsF (ORCPT ); Sun, 25 Oct 2020 13:48:05 -0400 Received: from mail-lf1-f66.google.com ([209.85.167.66]:35431 "EHLO mail-lf1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387660AbgJYRqj (ORCPT ); Sun, 25 Oct 2020 13:46:39 -0400 Received: by mail-lf1-f66.google.com with SMTP id 77so8934560lfl.2; Sun, 25 Oct 2020 10:46:37 -0700 (PDT) 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=suE5N34er/4e4BcFNN72z7EVkNB7/KN/Giael/pa1Eg=; b=dcVgE0szjmvqDvecghcCSIlAMcXpIHSlb1rq1XGzxq6xciyPVWmyO4Sel255pRqtCw ackUrNRGrrq5PDD8U0kUozJlMsFf7Vhai1lz2E57YZh8q54tm8ttGRHoEJ3kTKpXNqLr 5FYmyaV0pGT41DRoKG/NSA8boKpwsVX6n3uJEiM7P0WLMM6I5/qjeTGvjClMGAFpG4Y5 8m5P0rvsibAMVJFRrjiPN++fukifcLT4ko3k7d3bphMH/DpoexAtd/uphuT9gsmjuN3c BloRiK4lQxEB8E2umsnDqQFlSAU1GZtDBG/rolV6w7UcNDkClWqcFdIceaV9s14pC6bn YFzw== X-Gm-Message-State: AOAM531JcOMNTRI2nbhBV9o/wRutGQcXIjwPsqLfgRGn3cMgwKNEADfR DSk4u5BE4xucbXbNU3N6EwIm+3m42zuQCg== X-Google-Smtp-Source: ABdhPJxIiOHtt8LWj7l6aKIHYE4NRB4+YxMnHGpo6FBMjKkduw2tIFd27OqFZ0B//u5KJzGeachBaw== X-Received: by 2002:ac2:5699:: with SMTP id 25mr4135956lfr.396.1603647996348; Sun, 25 Oct 2020 10:46:36 -0700 (PDT) Received: from xi.terra (c-beaee455.07-184-6d6c6d4.bbcust.telenor.se. [85.228.174.190]) by smtp.gmail.com with ESMTPSA id f21sm793933lfc.122.2020.10.25.10.46.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Oct 2020 10:46:34 -0700 (PDT) Received: from johan by xi.terra with local (Exim 4.93.0.4) (envelope-from ) id 1kWk6I-0007HK-Md; Sun, 25 Oct 2020 18:46:38 +0100 From: Johan Hovold To: linux-usb@vger.kernel.org Cc: "Ahmed S . Darwish" , Sebastian Andrzej Siewior , Thomas Gleixner , linux-kernel@vger.kernel.org, Johan Hovold , stable Subject: [PATCH 03/14] USB: serial: keyspan_pda: fix stalled writes Date: Sun, 25 Oct 2020 18:45:49 +0100 Message-Id: <20201025174600.27896-4-johan@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201025174600.27896-1-johan@kernel.org> References: <20201025174600.27896-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Make sure to clear the write-busy flag also in case no new data was submitted due to lack of device buffer space so that writing is resumed once space again becomes available. Fixes: 507ca9bc0476 ("[PATCH] USB: add ability for usb-serial drivers to determine if their write urb is currently being used.") Cc: stable # 2.6.13 Signed-off-by: Johan Hovold --- drivers/usb/serial/keyspan_pda.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/serial/keyspan_pda.c b/drivers/usb/serial/keyspan_pda.c index 17b60e5a9f1f..d6ebde779e85 100644 --- a/drivers/usb/serial/keyspan_pda.c +++ b/drivers/usb/serial/keyspan_pda.c @@ -548,7 +548,7 @@ static int keyspan_pda_write(struct tty_struct *tty, rc = count; exit: - if (rc < 0) + if (rc <= 0) set_bit(0, &port->write_urbs_free); return rc; } From patchwork Sun Oct 25 17:45:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 11855365 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 233DC92C for ; Sun, 25 Oct 2020 17:47:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 071DF21D41 for ; Sun, 25 Oct 2020 17:47:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603648077; bh=noUNEYlylHnzHTY2CrwJfTMODh4hhkeYQ9BH/0VZmYs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=A8Q1Zj5B7781WBQcm1a2mhmdbMSyRlc5W7mxq4tPd7NF6n3G+hzUYUS6wC7NZtrys wqgBLwK/AIxcEKga9uLp/TY6IAGsOfXY0smku9xD45T09Ge+tRKgJSwHgcKiOmhUOO 8yBkGaTDRWlgTCzL2WeLfyCeaPBbVeZGUCKLRpw4= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1417855AbgJYRrx (ORCPT ); Sun, 25 Oct 2020 13:47:53 -0400 Received: from mail-lf1-f67.google.com ([209.85.167.67]:44306 "EHLO mail-lf1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1417714AbgJYRqk (ORCPT ); Sun, 25 Oct 2020 13:46:40 -0400 Received: by mail-lf1-f67.google.com with SMTP id b1so8902342lfp.11; Sun, 25 Oct 2020 10:46:38 -0700 (PDT) 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=mLH2jEE7RKRcoLwhkzgaqRtvr7bnr4NSOoTQehYo+/Y=; b=Xjxtzz1LK6LO3HD8pQsXTS/iV5qEUHxTR5bytGUfmHoF8eBnUMAiH7orhn63C+NJ8F gWi9oxbpP2XcugGYtZngexfeeUWYCSr1EjUUlSmZrQoeqvopAH8DjbXMrHP6LI/8V1lL OZELH7DMyJLcaiw403lRxTDPPBWl1krq0enjnw4Fy5ghApqxIcjPA6qIZJ90Tm8ubipA bHlSr0AfVZdihzhVZJOVYPKXKN3GyYhFJVFKi2/1lkWoeETiyPXa2Gqw5ceSN3jyVqG6 BAnS/GFPkWUUgNEDEf4zCDVWfnAjDSEQNZbaUMNbjsqnd8Pe7fWcJeFKce/T3MMv+p5N 0DgQ== X-Gm-Message-State: AOAM5312DOIdYYyBQbyDeaEuN8M4n47LabFdFiRGlwfCSKONv4YDPgJd iKZjhzHAHUy7RLF/MTdMbl25HdCoSjPswQ== X-Google-Smtp-Source: ABdhPJwIu5JxZA5EikW7OmQwczCYOMug3Pz2X03kVWfXjycmiVx42exfzXnPBhNcDMbR5/FXYpDbzg== X-Received: by 2002:ac2:5a03:: with SMTP id q3mr4135228lfn.527.1603647997449; Sun, 25 Oct 2020 10:46:37 -0700 (PDT) Received: from xi.terra (c-beaee455.07-184-6d6c6d4.bbcust.telenor.se. [85.228.174.190]) by smtp.gmail.com with ESMTPSA id l6sm799335lfk.267.2020.10.25.10.46.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Oct 2020 10:46:34 -0700 (PDT) Received: from johan by xi.terra with local (Exim 4.93.0.4) (envelope-from ) id 1kWk6I-0007HP-P6; Sun, 25 Oct 2020 18:46:38 +0100 From: Johan Hovold To: linux-usb@vger.kernel.org Cc: "Ahmed S . Darwish" , Sebastian Andrzej Siewior , Thomas Gleixner , linux-kernel@vger.kernel.org, Johan Hovold , stable@vger.kernel.org Subject: [PATCH 04/14] USB: serial: keyspan_pda: fix write-wakeup use-after-free Date: Sun, 25 Oct 2020 18:45:50 +0100 Message-Id: <20201025174600.27896-5-johan@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201025174600.27896-1-johan@kernel.org> References: <20201025174600.27896-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The driver's deferred write wakeup was never flushed on disconnect, something which could lead to the driver port data being freed while the wakeup work is still scheduled. Fix this by using the usb-serial write wakeup which gets cancelled properly on disconnect. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Cc: stable@vger.kernel.org Signed-off-by: Johan Hovold --- drivers/usb/serial/keyspan_pda.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/drivers/usb/serial/keyspan_pda.c b/drivers/usb/serial/keyspan_pda.c index d6ebde779e85..d91180ab5f3b 100644 --- a/drivers/usb/serial/keyspan_pda.c +++ b/drivers/usb/serial/keyspan_pda.c @@ -43,8 +43,7 @@ struct keyspan_pda_private { int tx_room; int tx_throttled; - struct work_struct wakeup_work; - struct work_struct unthrottle_work; + struct work_struct unthrottle_work; struct usb_serial *serial; struct usb_serial_port *port; }; @@ -97,15 +96,6 @@ static const struct usb_device_id id_table_fake_xircom[] = { }; #endif -static void keyspan_pda_wakeup_write(struct work_struct *work) -{ - struct keyspan_pda_private *priv = - container_of(work, struct keyspan_pda_private, wakeup_work); - struct usb_serial_port *port = priv->port; - - tty_port_tty_wakeup(&port->port); -} - static void keyspan_pda_request_unthrottle(struct work_struct *work) { struct keyspan_pda_private *priv = @@ -183,7 +173,7 @@ static void keyspan_pda_rx_interrupt(struct urb *urb) case 2: /* tx unthrottle interrupt */ priv->tx_throttled = 0; /* queue up a wakeup at scheduler time */ - schedule_work(&priv->wakeup_work); + usb_serial_port_softint(port); break; default: break; @@ -563,7 +553,7 @@ static void keyspan_pda_write_bulk_callback(struct urb *urb) priv = usb_get_serial_port_data(port); /* queue up a wakeup at scheduler time */ - schedule_work(&priv->wakeup_work); + usb_serial_port_softint(port); } @@ -715,7 +705,6 @@ static int keyspan_pda_port_probe(struct usb_serial_port *port) if (!priv) return -ENOMEM; - INIT_WORK(&priv->wakeup_work, keyspan_pda_wakeup_write); INIT_WORK(&priv->unthrottle_work, keyspan_pda_request_unthrottle); priv->serial = port->serial; priv->port = port; From patchwork Sun Oct 25 17:45:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 11855373 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 E36A592C for ; Sun, 25 Oct 2020 17:48:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C2FBA2222F for ; Sun, 25 Oct 2020 17:48:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603648090; bh=ku5vLd5Iusn82tuAbgP5kPGe9nSMcfc94jRxyrE866M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=T9g+POVUDr3yxIiadinWigS1b28UdXWqXJKE7JMopsskiQlCJlBwhNSVamy9PNtVo yZeUPZdX0RJH1bzhDGCFvvb1LYG5BOenhCYhxxNJQa2MXA04fx7YYUP1uk/B8Yu2hB qTjAJLnoaNAnmzQD3RfetAwfW/OBaB7ckunBEgq4= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1417711AbgJYRqi (ORCPT ); Sun, 25 Oct 2020 13:46:38 -0400 Received: from mail-lf1-f65.google.com ([209.85.167.65]:33302 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1417703AbgJYRqi (ORCPT ); Sun, 25 Oct 2020 13:46:38 -0400 Received: by mail-lf1-f65.google.com with SMTP id l2so8946065lfk.0; Sun, 25 Oct 2020 10:46:36 -0700 (PDT) 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=DM3vq5KoxogYKwdBtmc66x0pBZlJ1K2bRpuSSZ/7cuI=; b=PV6HokVAeS0Hrokca8ZhpR5VV5hC0VgAq/HRz3BlUej8WxlwOOXhRhfO6Yo5j+B+5J TUpmxcPnzTXHjgiIDSAC/54Mc2x4iic0w8iG9uFWDQGuDZs2D2//Rcva90ABLgLsxLij x92JYF7G+cpTzbJCSnOB7UMdQYFiWj46sY0p6DoXg2Tl0rd4oq8uNX3rVyb2Cirnepbl m6FghfL6kWo5JCeHY5aPLgmmzr9KS9mtaYDX+d7kfTLAY8rnz8sUPzWZ2kagZ8utEtPb ULHz3E2Po/adGUZaLJxxTNshHCBL0lNRddfIrEfZw3sFFLKdlWh8EGBefST5yb4zqESq OFPw== X-Gm-Message-State: AOAM533hm79TIuoRpKrECCM6TPc1FWaludBX6VHIb7OIA90cWjFDjMsl Z/Nsll1/nGzUxCayhuUBmPCbnbrrehHInw== X-Google-Smtp-Source: ABdhPJz8eCUR10EUzfpCmmU3MRqzeq9ZIzxRab2NEJvy+Ss3yLa9zCaaM/4vWVutak0oImjYQDCWrg== X-Received: by 2002:ac2:4a88:: with SMTP id l8mr3563444lfp.380.1603647995602; Sun, 25 Oct 2020 10:46:35 -0700 (PDT) Received: from xi.terra (c-beaee455.07-184-6d6c6d4.bbcust.telenor.se. [85.228.174.190]) by smtp.gmail.com with ESMTPSA id j10sm880891ljb.93.2020.10.25.10.46.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Oct 2020 10:46:35 -0700 (PDT) Received: from johan by xi.terra with local (Exim 4.93.0.4) (envelope-from ) id 1kWk6I-0007HT-S1; Sun, 25 Oct 2020 18:46:38 +0100 From: Johan Hovold To: linux-usb@vger.kernel.org Cc: "Ahmed S . Darwish" , Sebastian Andrzej Siewior , Thomas Gleixner , linux-kernel@vger.kernel.org, Johan Hovold , stable@vger.kernel.org Subject: [PATCH 05/14] USB: serial: keyspan_pda: fix tx-unthrottle use-after-free Date: Sun, 25 Oct 2020 18:45:51 +0100 Message-Id: <20201025174600.27896-6-johan@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201025174600.27896-1-johan@kernel.org> References: <20201025174600.27896-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The driver's transmit-unthrottle work was never flushed on disconnect, something which could lead to the driver port data being freed while the unthrottle work is still scheduled. Fix this by cancelling the unthrottle work when shutting down the port. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Cc: stable@vger.kernel.org Signed-off-by: Johan Hovold --- drivers/usb/serial/keyspan_pda.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/usb/serial/keyspan_pda.c b/drivers/usb/serial/keyspan_pda.c index d91180ab5f3b..781b6723379f 100644 --- a/drivers/usb/serial/keyspan_pda.c +++ b/drivers/usb/serial/keyspan_pda.c @@ -647,8 +647,12 @@ static int keyspan_pda_open(struct tty_struct *tty, } static void keyspan_pda_close(struct usb_serial_port *port) { + struct keyspan_pda_private *priv = usb_get_serial_port_data(port); + usb_kill_urb(port->write_urb); usb_kill_urb(port->interrupt_in_urb); + + cancel_work_sync(&priv->unthrottle_work); } From patchwork Sun Oct 25 17:45:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 11855359 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 89451697 for ; Sun, 25 Oct 2020 17:47:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 700C72222F for ; Sun, 25 Oct 2020 17:47:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603648043; bh=QvKlmZH7sZiUOVx11OK8l2lA8aaQzJDwvcx7LYjF0+c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=Hqi0lbGY9um/QifLPPZg3vRsELYLlwTCPlW+qF7kemyzo/fbh0L9+r445ph+Y/Gjr DJzWX03RVgzBmjpWXWXeqpZkrcLxHtTIrpTivgV+sMkiAew6ZFJXypJwbfx+3zonUy 2sbY10x5yAs4a9pmWVF7Ud154uH1syG/QR2TJcag= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1417816AbgJYRrV (ORCPT ); Sun, 25 Oct 2020 13:47:21 -0400 Received: from mail-lf1-f65.google.com ([209.85.167.65]:42674 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1417720AbgJYRql (ORCPT ); Sun, 25 Oct 2020 13:46:41 -0400 Received: by mail-lf1-f65.google.com with SMTP id a7so8895825lfk.9; Sun, 25 Oct 2020 10:46:39 -0700 (PDT) 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=1H5cIB/bnI7O4kZIMRYu9JZwd7Rp7lhti4RdlQxKvBk=; b=bJ+al9spyiNr2zb8hBJZTWn8VhdKdLmJMnyrIBq69dAoaY8bCUdVBZpPlMSNqN/vUh nuy3ae9xU/Gl1dqxVbGxTmplLQO0L6UeJk5l7mfu7JEBswLHNo5ZJboHN3nAc8GPwI0G OZ0nA1oYAOGQEktsm+qRCSNpUsyqpWHp0NyhasUAMK7zd/37jrHs25EGWdrfE6ZO7ikq eDV1UebtLT8qWeuGh2o2JJJbkxSNoi4LGW9FkWijngIVMEDLrHlyX2M0mOUOONijtpax tr+lRwcRiTNTMCoVIsqyIp76B3JGpe0fprQBpb5jyt2nIilBXkJchGW/xKxEuZ/Rdrho rfjQ== X-Gm-Message-State: AOAM531ErzRTtEd40LZbHU91s2/Sab5pgfFgOv0wrgkkic4X/bQ9EVXt x/DwN+15hmOQ7HPQyzBqb/29K3aqcoyODw== X-Google-Smtp-Source: ABdhPJyMguwhTZ7jhhrj2tg6SKza40nPfJA+ZqzBJMbkx9j5BAM6dr2ysJbUAYTZFW+3YmxXZmukPw== X-Received: by 2002:a19:840d:: with SMTP id g13mr3443725lfd.225.1603647998179; Sun, 25 Oct 2020 10:46:38 -0700 (PDT) Received: from xi.terra (c-beaee455.07-184-6d6c6d4.bbcust.telenor.se. [85.228.174.190]) by smtp.gmail.com with ESMTPSA id k16sm873420ljc.39.2020.10.25.10.46.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Oct 2020 10:46:36 -0700 (PDT) Received: from johan by xi.terra with local (Exim 4.93.0.4) (envelope-from ) id 1kWk6I-0007HZ-Us; Sun, 25 Oct 2020 18:46:38 +0100 From: Johan Hovold To: linux-usb@vger.kernel.org Cc: "Ahmed S . Darwish" , Sebastian Andrzej Siewior , Thomas Gleixner , linux-kernel@vger.kernel.org, Johan Hovold , stable Subject: [PATCH 06/14] USB: serial: keyspan_pda: fix write unthrottling Date: Sun, 25 Oct 2020 18:45:52 +0100 Message-Id: <20201025174600.27896-7-johan@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201025174600.27896-1-johan@kernel.org> References: <20201025174600.27896-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The driver did not update its view of the available device buffer space until write() was called in task context. This meant that write_room() would return 0 even after the device had sent a write-unthrottle notification, something which could lead to blocked writers not being woken up (e.g. when using OPOST). Note that we must also request an unthrottle notification is case a write() request fills the device buffer exactly. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Cc: stable Signed-off-by: Johan Hovold --- drivers/usb/serial/keyspan_pda.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/drivers/usb/serial/keyspan_pda.c b/drivers/usb/serial/keyspan_pda.c index 781b6723379f..39ed3ad32365 100644 --- a/drivers/usb/serial/keyspan_pda.c +++ b/drivers/usb/serial/keyspan_pda.c @@ -40,6 +40,8 @@ #define DRIVER_AUTHOR "Brian Warner " #define DRIVER_DESC "USB Keyspan PDA Converter driver" +#define KEYSPAN_TX_THRESHOLD 16 + struct keyspan_pda_private { int tx_room; int tx_throttled; @@ -110,7 +112,7 @@ static void keyspan_pda_request_unthrottle(struct work_struct *work) 7, /* request_unthrottle */ USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT, - 16, /* value: threshold */ + KEYSPAN_TX_THRESHOLD, 0, /* index */ NULL, 0, @@ -129,6 +131,8 @@ static void keyspan_pda_rx_interrupt(struct urb *urb) int retval; int status = urb->status; struct keyspan_pda_private *priv; + unsigned long flags; + priv = usb_get_serial_port_data(port); switch (status) { @@ -171,7 +175,10 @@ static void keyspan_pda_rx_interrupt(struct urb *urb) case 1: /* modemline change */ break; case 2: /* tx unthrottle interrupt */ + spin_lock_irqsave(&port->lock, flags); priv->tx_throttled = 0; + priv->tx_room = max(priv->tx_room, KEYSPAN_TX_THRESHOLD); + spin_unlock_irqrestore(&port->lock, flags); /* queue up a wakeup at scheduler time */ usb_serial_port_softint(port); break; @@ -505,7 +512,8 @@ static int keyspan_pda_write(struct tty_struct *tty, goto exit; } } - if (count > priv->tx_room) { + + if (count >= priv->tx_room) { /* we're about to completely fill the Tx buffer, so we'll be throttled afterwards. */ count = priv->tx_room; @@ -560,14 +568,17 @@ static void keyspan_pda_write_bulk_callback(struct urb *urb) static int keyspan_pda_write_room(struct tty_struct *tty) { struct usb_serial_port *port = tty->driver_data; - struct keyspan_pda_private *priv; - priv = usb_get_serial_port_data(port); - /* used by n_tty.c for processing of tabs and such. Giving it our - conservative guess is probably good enough, but needs testing by - running a console through the device. */ - return priv->tx_room; -} + struct keyspan_pda_private *priv = usb_get_serial_port_data(port); + unsigned long flags; + int room = 0; + + spin_lock_irqsave(&port->lock, flags); + if (test_bit(0, &port->write_urbs_free) && !priv->tx_throttled) + room = priv->tx_room; + spin_unlock_irqrestore(&port->lock, flags); + return room; +} static int keyspan_pda_chars_in_buffer(struct tty_struct *tty) { From patchwork Sun Oct 25 17:45:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 11855361 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 DF4FF697 for ; Sun, 25 Oct 2020 17:47:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C77EF21D41 for ; Sun, 25 Oct 2020 17:47:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603648044; bh=v2BOd+QUQFFWXXNT01OTC5UMUZwR2lHturpiS/yUz+o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=jdVEuEZ6nwq8hBK5xuywAwmLV3DN8KVc/c4UF2tzckC4lnqOcBZmxQwKXTRI7wXOy 8nUWs1flIp8StyBv6rbc78z4ACYAUkEVru8p8ObB2mHE4hksYXvvWyu1KjquQ3tjNT HI5PIu32teqg74PGupG7vxGURePoy8W2FuJozeUk= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1417820AbgJYRrX (ORCPT ); Sun, 25 Oct 2020 13:47:23 -0400 Received: from mail-lj1-f193.google.com ([209.85.208.193]:40288 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1417725AbgJYRql (ORCPT ); Sun, 25 Oct 2020 13:46:41 -0400 Received: by mail-lj1-f193.google.com with SMTP id 23so7281525ljv.7; Sun, 25 Oct 2020 10:46:39 -0700 (PDT) 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=sp4NdDzvf7ets2jCUs0u83t/aBTY5svl7aNfj78wdxY=; b=h7jNzDOmVwgFf2D3YwOAOjz3CNfuy1HX8SfkjA1P2x46kFJLkcIOVYFmkxlO2bse6F SuaGHJQERta5t5YAdza0O5Ok+26IwJGzVSCraHUW6+kTQFVh7qhB9zGVfMMSD2vqZlXV 4acav2/ispsXnR0ddYXtq3I7WagSI4aBHDkeTdgo/XhOgoECjKwQbHWj93X2m8Zfe0p4 5PlN3li5mLfeyAM43TaNubMPklybV53TO1sY7DKnHsUriuDfTMACAJXoRU4UjNEuLUmz wA+Ubu0+IMpuntZG6OwYspL7BFUO1+5hW8tLcrnl+7lMZIejBB5VWL0rhSqusOTUaI1u 1RHQ== X-Gm-Message-State: AOAM5326LsypoMhWbKv+Noh+B5cgA8k78B7c4q2Cbbt2D8pZIzH1uJFV 4jTFNdoaTZT8xEAT00EwW4U3ZdrG8lzGKg== X-Google-Smtp-Source: ABdhPJynCx+XhHjVnmOHl6Fu5cj+2GpR6klM2BYqazOdZ/vWLANJctsuC9wd3+Pkihwx3V8OM4LTuA== X-Received: by 2002:a2e:a375:: with SMTP id i21mr4278088ljn.135.1603647998662; Sun, 25 Oct 2020 10:46:38 -0700 (PDT) Received: from xi.terra (c-beaee455.07-184-6d6c6d4.bbcust.telenor.se. [85.228.174.190]) by smtp.gmail.com with ESMTPSA id 28sm794158lfp.295.2020.10.25.10.46.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Oct 2020 10:46:37 -0700 (PDT) Received: from johan by xi.terra with local (Exim 4.93.0.4) (envelope-from ) id 1kWk6J-0007He-18; Sun, 25 Oct 2020 18:46:39 +0100 From: Johan Hovold To: linux-usb@vger.kernel.org Cc: "Ahmed S . Darwish" , Sebastian Andrzej Siewior , Thomas Gleixner , linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH 07/14] USB: serial: keyspan_pda: refactor write-room handling Date: Sun, 25 Oct 2020 18:45:53 +0100 Message-Id: <20201025174600.27896-8-johan@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201025174600.27896-1-johan@kernel.org> References: <20201025174600.27896-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Add helper to retrieve the available device transfer-buffer space. Signed-off-by: Johan Hovold --- drivers/usb/serial/keyspan_pda.c | 113 ++++++++++++++----------------- 1 file changed, 50 insertions(+), 63 deletions(-) diff --git a/drivers/usb/serial/keyspan_pda.c b/drivers/usb/serial/keyspan_pda.c index 39ed3ad32365..54a21a99c001 100644 --- a/drivers/usb/serial/keyspan_pda.c +++ b/drivers/usb/serial/keyspan_pda.c @@ -98,6 +98,42 @@ static const struct usb_device_id id_table_fake_xircom[] = { }; #endif +static int keyspan_pda_get_write_room(struct keyspan_pda_private *priv) +{ + struct usb_serial_port *port = priv->port; + struct usb_serial *serial = priv->serial; + u8 *room; + int rc; + + room = kmalloc(1, GFP_KERNEL); + if (!room) + return -ENOMEM; + + rc = usb_control_msg(serial->dev, + usb_rcvctrlpipe(serial->dev, 0), + 6, /* write_room */ + USB_TYPE_VENDOR | USB_RECIP_INTERFACE + | USB_DIR_IN, + 0, /* value: 0 means "remaining room" */ + 0, /* index */ + room, + 1, + 2000); + if (rc != 1) { + if (rc >= 0) + rc = -EIO; + dev_dbg(&port->dev, "roomquery failed: %d\n", rc); + goto out_free; + } + + dev_dbg(&port->dev, "roomquery says %d\n", *room); + rc = *room; +out_free: + kfree(room); + + return rc; +} + static void keyspan_pda_request_unthrottle(struct work_struct *work) { struct keyspan_pda_private *priv = @@ -436,7 +472,6 @@ static int keyspan_pda_tiocmset(struct tty_struct *tty, static int keyspan_pda_write(struct tty_struct *tty, struct usb_serial_port *port, const unsigned char *buf, int count) { - struct usb_serial *serial = port->serial; int request_unthrottle = 0; int rc = 0; struct keyspan_pda_private *priv; @@ -479,38 +514,11 @@ static int keyspan_pda_write(struct tty_struct *tty, device how much room it really has. This is done only on scheduler time, since usb_control_msg() sleeps. */ if (count > priv->tx_room && !in_interrupt()) { - u8 *room; - - room = kmalloc(1, GFP_KERNEL); - if (!room) { - rc = -ENOMEM; + rc = keyspan_pda_get_write_room(priv); + if (rc < 0) goto exit; - } - rc = usb_control_msg(serial->dev, - usb_rcvctrlpipe(serial->dev, 0), - 6, /* write_room */ - USB_TYPE_VENDOR | USB_RECIP_INTERFACE - | USB_DIR_IN, - 0, /* value: 0 means "remaining room" */ - 0, /* index */ - room, - 1, - 2000); - if (rc > 0) { - dev_dbg(&port->dev, "roomquery says %d\n", *room); - priv->tx_room = *room; - } - kfree(room); - if (rc < 0) { - dev_dbg(&port->dev, "roomquery failed\n"); - goto exit; - } - if (rc == 0) { - dev_dbg(&port->dev, "roomquery returned 0 bytes\n"); - rc = -EIO; /* device didn't return any data */ - goto exit; - } + priv->tx_room = rc; } if (count >= priv->tx_room) { @@ -614,48 +622,27 @@ static void keyspan_pda_dtr_rts(struct usb_serial_port *port, int on) static int keyspan_pda_open(struct tty_struct *tty, struct usb_serial_port *port) { - struct usb_serial *serial = port->serial; - u8 *room; - int rc = 0; - struct keyspan_pda_private *priv; + struct keyspan_pda_private *priv = usb_get_serial_port_data(port); + int rc; /* find out how much room is in the Tx ring */ - room = kmalloc(1, GFP_KERNEL); - if (!room) - return -ENOMEM; + rc = keyspan_pda_get_write_room(priv); + if (rc < 0) + return rc; - rc = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), - 6, /* write_room */ - USB_TYPE_VENDOR | USB_RECIP_INTERFACE - | USB_DIR_IN, - 0, /* value */ - 0, /* index */ - room, - 1, - 2000); - if (rc < 0) { - dev_dbg(&port->dev, "%s - roomquery failed\n", __func__); - goto error; - } - if (rc == 0) { - dev_dbg(&port->dev, "%s - roomquery returned 0 bytes\n", __func__); - rc = -EIO; - goto error; - } - priv = usb_get_serial_port_data(port); - priv->tx_room = *room; - priv->tx_throttled = *room ? 0 : 1; + priv->tx_room = rc; + priv->tx_throttled = rc ? 0 : 1; /*Start reading from the device*/ rc = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); if (rc) { dev_dbg(&port->dev, "%s - usb_submit_urb(read int) failed\n", __func__); - goto error; + return rc; } -error: - kfree(room); - return rc; + + return 0; } + static void keyspan_pda_close(struct usb_serial_port *port) { struct keyspan_pda_private *priv = usb_get_serial_port_data(port); From patchwork Sun Oct 25 17:45:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 11855349 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 8BCDB92C for ; Sun, 25 Oct 2020 17:46:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6EF11208A9 for ; Sun, 25 Oct 2020 17:46:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603648005; bh=1aspSR7S1DGbMIhQG88bDcR1s2k7da8K7nkUT/YzwZQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=PS+ygvdX/cjtZ3P0HP6n1/1CSfkTglYFVHgPkpMFw3j899PrTVDuvXjDmKTNUxTKM oFChWtMpVAFmUbRBQrDyOMpdLxBbwzD3dHTp3W+7BZM2g1LN5QJGuIk5MfP6EGEZ0P Db886inAsllamJ1+ZvokOQetFJHkiMovYaH9cHY4= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1417753AbgJYRqo (ORCPT ); Sun, 25 Oct 2020 13:46:44 -0400 Received: from mail-lf1-f66.google.com ([209.85.167.66]:41875 "EHLO mail-lf1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1417728AbgJYRqm (ORCPT ); Sun, 25 Oct 2020 13:46:42 -0400 Received: by mail-lf1-f66.google.com with SMTP id d24so8913928lfa.8; Sun, 25 Oct 2020 10:46:40 -0700 (PDT) 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=VSisBRKlms2bW6ryDsoA/vERvwhqA6Jy0C8Ke1HdF9Q=; b=lUqF2X1iGqTqZ5Gexk9R4SFL7/6ObN1CLnHxN4uyTVCtndyo4GAKveD2cQNhYbLsFy InFzqLR17JRWrooKo4XZXG9SwpCNkI1x8fAQ7y0rJ5Z4wkOU+DwiHZ439sgP0+mJqW6x 991mNXR1TJtmz5Q4Z7N3etms39na9YhTDwM9IJBa9R2TU5h4HUE/6y3e4SM6iRqeICb9 HBIlC+0LYXIKQSP/2FiffvIc46fZIDK9/VJqZYb/IU2y9gwCku8J1cjGOEvMXKmCy35/ cuxnT+9GNRKjLlRqq8r+pZ6wi1ivrGqVjMefkDKcCb21c1IybxqbuDlkDvzY7rmmrE+m RbFw== X-Gm-Message-State: AOAM531T8UbgykCEC8we4SgGxlVAOe+WFrYdBN0PBQYC+bD4knI9bWFQ mhjMqR9ajA86UQrd7qerUk+8ogLeCIGKiw== X-Google-Smtp-Source: ABdhPJxT6605LlYpDxX6K75QUSS9yytb6OuuIoE+RPRfEvAdaIOEllNL1HJM2QpAZRKdnjOIq8LAdw== X-Received: by 2002:a19:c142:: with SMTP id r63mr3415140lff.234.1603647999286; Sun, 25 Oct 2020 10:46:39 -0700 (PDT) Received: from xi.terra (c-beaee455.07-184-6d6c6d4.bbcust.telenor.se. [85.228.174.190]) by smtp.gmail.com with ESMTPSA id j12sm793172lfb.28.2020.10.25.10.46.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Oct 2020 10:46:37 -0700 (PDT) Received: from johan by xi.terra with local (Exim 4.93.0.4) (envelope-from ) id 1kWk6J-0007Hj-3i; Sun, 25 Oct 2020 18:46:39 +0100 From: Johan Hovold To: linux-usb@vger.kernel.org Cc: "Ahmed S . Darwish" , Sebastian Andrzej Siewior , Thomas Gleixner , linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH 08/14] USB: serial: keyspan_pda: fix write implementation Date: Sun, 25 Oct 2020 18:45:54 +0100 Message-Id: <20201025174600.27896-9-johan@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201025174600.27896-1-johan@kernel.org> References: <20201025174600.27896-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Fix stalled writes by checking the available buffer space after requesting an unthrottle notification in case the device buffer is already empty so that no notification is ever sent (e.g. when doing single character writes). This also means we can drop the room query from write() which was conditioned on in_interrupt() and prevented writing using this driver from atomic contexts (e.g. PPP). Signed-off-by: Johan Hovold --- drivers/usb/serial/keyspan_pda.c | 109 +++++++++++++++---------------- 1 file changed, 51 insertions(+), 58 deletions(-) diff --git a/drivers/usb/serial/keyspan_pda.c b/drivers/usb/serial/keyspan_pda.c index 54a21a99c001..b3fb2ecefb31 100644 --- a/drivers/usb/serial/keyspan_pda.c +++ b/drivers/usb/serial/keyspan_pda.c @@ -44,7 +44,6 @@ struct keyspan_pda_private { int tx_room; - int tx_throttled; struct work_struct unthrottle_work; struct usb_serial *serial; struct usb_serial_port *port; @@ -138,9 +137,13 @@ static void keyspan_pda_request_unthrottle(struct work_struct *work) { struct keyspan_pda_private *priv = container_of(work, struct keyspan_pda_private, unthrottle_work); + struct usb_serial_port *port = priv->port; struct usb_serial *serial = priv->serial; + unsigned long flags; int result; + dev_dbg(&port->dev, "%s\n", __func__); + /* ask the device to tell us when the tx buffer becomes sufficiently empty */ result = usb_control_msg(serial->dev, @@ -156,8 +159,19 @@ static void keyspan_pda_request_unthrottle(struct work_struct *work) if (result < 0) dev_dbg(&serial->dev->dev, "%s - error %d from usb_control_msg\n", __func__, result); -} + /* + * Need to check available space after requesting notification in case + * buffer is already empty so that no notification is sent. + */ + result = keyspan_pda_get_write_room(priv); + if (result > KEYSPAN_TX_THRESHOLD) { + spin_lock_irqsave(&port->lock, flags); + priv->tx_room = max(priv->tx_room, result); + spin_unlock_irqrestore(&port->lock, flags); + usb_serial_port_softint(port); + } +} static void keyspan_pda_rx_interrupt(struct urb *urb) { @@ -212,7 +226,6 @@ static void keyspan_pda_rx_interrupt(struct urb *urb) break; case 2: /* tx unthrottle interrupt */ spin_lock_irqsave(&port->lock, flags); - priv->tx_throttled = 0; priv->tx_room = max(priv->tx_room, KEYSPAN_TX_THRESHOLD); spin_unlock_irqrestore(&port->lock, flags); /* queue up a wakeup at scheduler time */ @@ -472,35 +485,42 @@ static int keyspan_pda_tiocmset(struct tty_struct *tty, static int keyspan_pda_write(struct tty_struct *tty, struct usb_serial_port *port, const unsigned char *buf, int count) { - int request_unthrottle = 0; - int rc = 0; struct keyspan_pda_private *priv; unsigned long flags; + int room; + int rc; priv = usb_get_serial_port_data(port); - /* guess how much room is left in the device's ring buffer, and if we - want to send more than that, check first, updating our notion of - what is left. If our write will result in no room left, ask the - device to give us an interrupt when the room available rises above - a threshold, and hold off all writers (eventually, those using - select() or poll() too) until we receive that unthrottle interrupt. - Block if we can't write anything at all, otherwise write as much as - we can. */ + /* + * Guess how much room is left in the device's ring buffer. If our + * write will result in no room left, ask the device to give us an + * interrupt when the room available rises above a threshold but also + * query how much room is currently available (in case our guess was + * too conservative and the buffer is already empty when the + * unthrottle work is scheduled). + */ if (count == 0) { dev_dbg(&port->dev, "write request of 0 bytes\n"); return 0; } + if (count > port->bulk_out_size) + count = port->bulk_out_size; + /* we might block because of: the TX urb is in-flight (wait until it completes) the device is full (wait until it says there is room) */ spin_lock_irqsave(&port->lock, flags); - if (!test_bit(0, &port->write_urbs_free) || priv->tx_throttled) { + room = priv->tx_room; + if (!test_bit(0, &port->write_urbs_free) || room == 0) { spin_unlock_irqrestore(&port->lock, flags); return 0; } clear_bit(0, &port->write_urbs_free); + if (count > room) + count = room; + priv->tx_room -= count; spin_unlock_irqrestore(&port->lock, flags); /* At this point the URB is in our control, nobody else can submit it @@ -508,58 +528,30 @@ static int keyspan_pda_write(struct tty_struct *tty, finished). Also, the tx process is not throttled. So we are ready to write. */ - count = (count > port->bulk_out_size) ? port->bulk_out_size : count; + dev_dbg(&port->dev, "%s - count = %d, txroom = %d\n", __func__, count, room); - /* Check if we might overrun the Tx buffer. If so, ask the - device how much room it really has. This is done only on - scheduler time, since usb_control_msg() sleeps. */ - if (count > priv->tx_room && !in_interrupt()) { - rc = keyspan_pda_get_write_room(priv); - if (rc < 0) - goto exit; - - priv->tx_room = rc; - } + memcpy(port->write_urb->transfer_buffer, buf, count); + port->write_urb->transfer_buffer_length = count; - if (count >= priv->tx_room) { - /* we're about to completely fill the Tx buffer, so - we'll be throttled afterwards. */ - count = priv->tx_room; - request_unthrottle = 1; - } + rc = usb_submit_urb(port->write_urb, GFP_ATOMIC); + if (rc) { + dev_dbg(&port->dev, "usb_submit_urb(write bulk) failed\n"); - if (count) { - /* now transfer data */ - memcpy(port->write_urb->transfer_buffer, buf, count); - /* send the data out the bulk port */ - port->write_urb->transfer_buffer_length = count; + spin_lock_irqsave(&port->lock, flags); + priv->tx_room = max(priv->tx_room, room + count); + spin_unlock_irqrestore(&port->lock, flags); - priv->tx_room -= count; + set_bit(0, &port->write_urbs_free); - rc = usb_submit_urb(port->write_urb, GFP_ATOMIC); - if (rc) { - dev_dbg(&port->dev, "usb_submit_urb(write bulk) failed\n"); - goto exit; - } - } else { - /* There wasn't any room left, so we are throttled until - the buffer empties a bit */ - request_unthrottle = 1; + return rc; } - if (request_unthrottle) { - priv->tx_throttled = 1; /* block writers */ + if (count == room) schedule_work(&priv->unthrottle_work); - } - rc = count; -exit: - if (rc <= 0) - set_bit(0, &port->write_urbs_free); - return rc; + return count; } - static void keyspan_pda_write_bulk_callback(struct urb *urb) { struct usb_serial_port *port = urb->context; @@ -581,7 +573,7 @@ static int keyspan_pda_write_room(struct tty_struct *tty) int room = 0; spin_lock_irqsave(&port->lock, flags); - if (test_bit(0, &port->write_urbs_free) && !priv->tx_throttled) + if (test_bit(0, &port->write_urbs_free)) room = priv->tx_room; spin_unlock_irqrestore(&port->lock, flags); @@ -601,7 +593,7 @@ static int keyspan_pda_chars_in_buffer(struct tty_struct *tty) n_tty.c:normal_poll() ) that we're not writeable. */ spin_lock_irqsave(&port->lock, flags); - if (!test_bit(0, &port->write_urbs_free) || priv->tx_throttled) + if (!test_bit(0, &port->write_urbs_free) || priv->tx_room == 0) ret = 256; spin_unlock_irqrestore(&port->lock, flags); return ret; @@ -630,8 +622,9 @@ static int keyspan_pda_open(struct tty_struct *tty, if (rc < 0) return rc; + spin_lock_irq(&port->lock); priv->tx_room = rc; - priv->tx_throttled = rc ? 0 : 1; + spin_unlock_irq(&port->lock); /*Start reading from the device*/ rc = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); From patchwork Sun Oct 25 17:45:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 11855347 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 CF95C697 for ; Sun, 25 Oct 2020 17:46:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B7A8921D41 for ; Sun, 25 Oct 2020 17:46:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603648004; bh=4SlHM5j/5vNgv2PmVV06G73zvgqVqCPshjp33FH6ViQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=U0Z5OlcW7oX3ehg9SrhTWB/378VSJSAPodnzE428kJvB7G4bo71svN0nfhkm8xTde ynrAOIgrwKgH5pe6QARzer8ZGytDrCuuWF5BGiyiYtFdgcCuS9ge4IGRbA8n1wWFle rkKq6EcaBsPR3c6kzFaZwlzUIAJxTq7zQMLk1jRI= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1417746AbgJYRqn (ORCPT ); Sun, 25 Oct 2020 13:46:43 -0400 Received: from mail-lf1-f68.google.com ([209.85.167.68]:44310 "EHLO mail-lf1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1417729AbgJYRqm (ORCPT ); Sun, 25 Oct 2020 13:46:42 -0400 Received: by mail-lf1-f68.google.com with SMTP id b1so8902419lfp.11; Sun, 25 Oct 2020 10:46:40 -0700 (PDT) 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=tGTT39jWlLeV6qw6JuECAsw5LeIu6htUw8WodmgXEVI=; b=XkVvJzDzd3Qn/fZ4eBvE/vaL7nah2jIhXOw59rXgbUpCPGNfg+Zj46Oa79BtXIc0zF zDzUsR7JkjpzrQgB3f6ywCFuI55suyyBb6gGV/Y9eYY4fisoSUEymxN8gXdcMnnv1oEd eCs4SgHH9y6aOiVqZhq3vKfylG+v2btIXlv40y7hwe9cWGnkpCOET52hTARxoOm6ukzD Q+7IqBDPoTtxqJ9EHRexx+cAP66LB4KB65gfJYi5whc5l58C363RyhgwlPnIlJ4WSWJj 7lnKZ1MwbW1ViSPEH0InGRQc0ZnNEI9jfZPUaVbHTuGU7NkB+A73ZBwWix5hvxjYfUJg dueA== X-Gm-Message-State: AOAM532f/qlMDOcE6WgqXsNVduhsSQls3JSIcg/xTkxm3h/lZuEJnpTG f8ldaNp6A+1qxXgXRYYOiV22MwccWg4fHg== X-Google-Smtp-Source: ABdhPJyg3MdoMNccmbHEu+WlbVdesSjkOhQXLYIvMsk57nibY5czw5DG9W3f7mjm8LuJdCh4vy7v6g== X-Received: by 2002:a19:407:: with SMTP id 7mr3676131lfe.291.1603647999803; Sun, 25 Oct 2020 10:46:39 -0700 (PDT) Received: from xi.terra (c-beaee455.07-184-6d6c6d4.bbcust.telenor.se. [85.228.174.190]) by smtp.gmail.com with ESMTPSA id e19sm793673lfn.241.2020.10.25.10.46.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Oct 2020 10:46:37 -0700 (PDT) Received: from johan by xi.terra with local (Exim 4.93.0.4) (envelope-from ) id 1kWk6J-0007Hn-6X; Sun, 25 Oct 2020 18:46:39 +0100 From: Johan Hovold To: linux-usb@vger.kernel.org Cc: "Ahmed S . Darwish" , Sebastian Andrzej Siewior , Thomas Gleixner , linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH 09/14] USB: serial: keyspan_pda: increase transmitter threshold Date: Sun, 25 Oct 2020 18:45:55 +0100 Message-Id: <20201025174600.27896-10-johan@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201025174600.27896-1-johan@kernel.org> References: <20201025174600.27896-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Increase the transmitter threshold so that writing isn't resumed until 128 bytes are available in the device buffer thereby allowing for larger and more efficient transfers. Signed-off-by: Johan Hovold --- drivers/usb/serial/keyspan_pda.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/serial/keyspan_pda.c b/drivers/usb/serial/keyspan_pda.c index b3fb2ecefb31..3816bbc928b2 100644 --- a/drivers/usb/serial/keyspan_pda.c +++ b/drivers/usb/serial/keyspan_pda.c @@ -40,7 +40,7 @@ #define DRIVER_AUTHOR "Brian Warner " #define DRIVER_DESC "USB Keyspan PDA Converter driver" -#define KEYSPAN_TX_THRESHOLD 16 +#define KEYSPAN_TX_THRESHOLD 128 struct keyspan_pda_private { int tx_room; From patchwork Sun Oct 25 17:45:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 11855351 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 9096092C for ; Sun, 25 Oct 2020 17:46:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 745BD21D41 for ; Sun, 25 Oct 2020 17:46:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603648009; bh=Bm6KB2M4nKN8AE3BjRrqjelLaf8H30JiwwP4k2OJMBo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=0FQMca1Y3lB8Y4cZsQ1N8e+/zfqo2h5k3+NLTL7a7PgQCrRraIpm1tCWcX77axdA7 HnaTDHyfFN/Pk+BaAlCYsypD8Pent7T7vTMg5KrxsSX2vLZV5JpDTRJktBz8rvWRWH PW57bztWtUEH87D5e5hu75AeRUtXt+Zh/N6IPju8= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1417765AbgJYRqr (ORCPT ); Sun, 25 Oct 2020 13:46:47 -0400 Received: from mail-lf1-f67.google.com ([209.85.167.67]:36120 "EHLO mail-lf1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1417747AbgJYRqp (ORCPT ); Sun, 25 Oct 2020 13:46:45 -0400 Received: by mail-lf1-f67.google.com with SMTP id h6so8907672lfj.3; Sun, 25 Oct 2020 10:46:43 -0700 (PDT) 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=CqbRKimYe1NyugKflXSgKWReJkFImiLBzd8ZfDSwYpg=; b=c6P38fDtk0csY9SZwIe0jYTSexBOJElTDPMA1xOvikZ1asO/cnQgSH2ZgTUZHj216f 7MQIhiVvPE+xfZocSQKpyS9iBZkXh2kvxczofCdM01dGeG02JPlq3cClnBu0YWQ6MLS/ G4NZD9FZAe5JyHbrShFPXs1mQfKfJx76JCghEckm/++CaLeorq2kDrw7Z3h4CR2XSpxT mo6ZnXqieHk/kT0BzT3CccecgoKxJFwbKAKtJEK7ZCUFiQ8gCYZA8y+b+c2uti3oFLhc 1m5fSTMHQBh3ev7+uZ7WMCMzxkKSYiAjUq1cDEx5qpq8zHtl2ujMNy2kvDjqNynvh48s IUiQ== X-Gm-Message-State: AOAM532x+4OWtBMt/6qZ+fDrpzGMcMYttUhQTfIqtFP29axdnarf98QF jwbwPvLEPqpbIJABmiYjlAi3hGYfjbndig== X-Google-Smtp-Source: ABdhPJx37cyoczEwaZ6YPMHYucOh9v9JYWqeuv+goTQG0oldDd7xZO8VWg1+xhCY34vfAJlw2rFnig== X-Received: by 2002:ac2:51ab:: with SMTP id f11mr4224755lfk.417.1603648002107; Sun, 25 Oct 2020 10:46:42 -0700 (PDT) Received: from xi.terra (c-beaee455.07-184-6d6c6d4.bbcust.telenor.se. [85.228.174.190]) by smtp.gmail.com with ESMTPSA id 18sm900581ljq.0.2020.10.25.10.46.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Oct 2020 10:46:37 -0700 (PDT) Received: from johan by xi.terra with local (Exim 4.93.0.4) (envelope-from ) id 1kWk6J-0007Ht-8m; Sun, 25 Oct 2020 18:46:39 +0100 From: Johan Hovold To: linux-usb@vger.kernel.org Cc: "Ahmed S . Darwish" , Sebastian Andrzej Siewior , Thomas Gleixner , linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH 10/14] USB: serial: keyspan_pda: add write-fifo support Date: Sun, 25 Oct 2020 18:45:56 +0100 Message-Id: <20201025174600.27896-11-johan@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201025174600.27896-1-johan@kernel.org> References: <20201025174600.27896-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Use the port write fifo and generic chars_and_buffer and write_room implementations when writing. This not only allows for more efficient transfers, but more importantly fixes the remaining issues related to the conservative write_room() implementation which could prevent the line discipline from making forward progress (e.g. waiting for n > 1 bytes of space to become available). Note that this also allows using the driver for the system console without dropping data when the write URB is busy (including when adding carriage return on line feed). Signed-off-by: Johan Hovold --- drivers/usb/serial/keyspan_pda.c | 115 +++++++++++++++---------------- 1 file changed, 55 insertions(+), 60 deletions(-) diff --git a/drivers/usb/serial/keyspan_pda.c b/drivers/usb/serial/keyspan_pda.c index 3816bbc928b2..aa19dd181e42 100644 --- a/drivers/usb/serial/keyspan_pda.c +++ b/drivers/usb/serial/keyspan_pda.c @@ -5,6 +5,7 @@ * Copyright (C) 1999 - 2001 Greg Kroah-Hartman * Copyright (C) 1999, 2000 Brian Warner * Copyright (C) 2000 Al Borchers + * Copyright (C) 2020 Johan Hovold * * See Documentation/usb/usb-serial.rst for more information on using this * driver @@ -37,7 +38,7 @@ #undef XIRCOM #endif -#define DRIVER_AUTHOR "Brian Warner " +#define DRIVER_AUTHOR "Brian Warner , Johan Hovold " #define DRIVER_DESC "USB Keyspan PDA Converter driver" #define KEYSPAN_TX_THRESHOLD 128 @@ -49,6 +50,7 @@ struct keyspan_pda_private { struct usb_serial_port *port; }; +static int keyspan_pda_write_start(struct usb_serial_port *port); #define KEYSPAN_VENDOR_ID 0x06cd #define KEYSPAN_PDA_FAKE_ID 0x0103 @@ -228,6 +230,9 @@ static void keyspan_pda_rx_interrupt(struct urb *urb) spin_lock_irqsave(&port->lock, flags); priv->tx_room = max(priv->tx_room, KEYSPAN_TX_THRESHOLD); spin_unlock_irqrestore(&port->lock, flags); + + keyspan_pda_write_start(port); + /* queue up a wakeup at scheduler time */ usb_serial_port_softint(port); break; @@ -482,15 +487,15 @@ static int keyspan_pda_tiocmset(struct tty_struct *tty, return rc; } -static int keyspan_pda_write(struct tty_struct *tty, - struct usb_serial_port *port, const unsigned char *buf, int count) +static int keyspan_pda_write_start(struct usb_serial_port *port) { - struct keyspan_pda_private *priv; + struct keyspan_pda_private *priv = usb_get_serial_port_data(port); unsigned long flags; + struct urb *urb; + int count; int room; int rc; - priv = usb_get_serial_port_data(port); /* * Guess how much room is left in the device's ring buffer. If our * write will result in no room left, ask the device to give us an @@ -499,50 +504,48 @@ static int keyspan_pda_write(struct tty_struct *tty, * too conservative and the buffer is already empty when the * unthrottle work is scheduled). */ - if (count == 0) { - dev_dbg(&port->dev, "write request of 0 bytes\n"); - return 0; - } - - if (count > port->bulk_out_size) - count = port->bulk_out_size; /* we might block because of: the TX urb is in-flight (wait until it completes) the device is full (wait until it says there is room) */ spin_lock_irqsave(&port->lock, flags); + room = priv->tx_room; - if (!test_bit(0, &port->write_urbs_free) || room == 0) { + count = kfifo_len(&port->write_fifo); + + if (!test_bit(0, &port->write_urbs_free) || count == 0 || room == 0) { spin_unlock_irqrestore(&port->lock, flags); return 0; } - clear_bit(0, &port->write_urbs_free); + __clear_bit(0, &port->write_urbs_free); + if (count > room) count = room; + if (count > port->bulk_out_size) + count = port->bulk_out_size; + + urb = port->write_urb; + count = kfifo_out(&port->write_fifo, urb->transfer_buffer, count); + urb->transfer_buffer_length = count; + + port->tx_bytes += count; priv->tx_room -= count; - spin_unlock_irqrestore(&port->lock, flags); - /* At this point the URB is in our control, nobody else can submit it - again (the only sudden transition was the one from EINPROGRESS to - finished). Also, the tx process is not throttled. So we are - ready to write. */ + spin_unlock_irqrestore(&port->lock, flags); dev_dbg(&port->dev, "%s - count = %d, txroom = %d\n", __func__, count, room); - memcpy(port->write_urb->transfer_buffer, buf, count); - port->write_urb->transfer_buffer_length = count; - - rc = usb_submit_urb(port->write_urb, GFP_ATOMIC); + rc = usb_submit_urb(urb, GFP_ATOMIC); if (rc) { dev_dbg(&port->dev, "usb_submit_urb(write bulk) failed\n"); spin_lock_irqsave(&port->lock, flags); + port->tx_bytes -= count; priv->tx_room = max(priv->tx_room, room + count); + __set_bit(0, &port->write_urbs_free); spin_unlock_irqrestore(&port->lock, flags); - set_bit(0, &port->write_urbs_free); - return rc; } @@ -555,51 +558,38 @@ static int keyspan_pda_write(struct tty_struct *tty, static void keyspan_pda_write_bulk_callback(struct urb *urb) { struct usb_serial_port *port = urb->context; - struct keyspan_pda_private *priv; + unsigned long flags; - set_bit(0, &port->write_urbs_free); - priv = usb_get_serial_port_data(port); + spin_lock_irqsave(&port->lock, flags); + port->tx_bytes -= urb->transfer_buffer_length; + __set_bit(0, &port->write_urbs_free); + spin_unlock_irqrestore(&port->lock, flags); + + keyspan_pda_write_start(port); /* queue up a wakeup at scheduler time */ usb_serial_port_softint(port); } - -static int keyspan_pda_write_room(struct tty_struct *tty) +static int keyspan_pda_write(struct tty_struct *tty, struct usb_serial_port *port, + const unsigned char *buf, int count) { - struct usb_serial_port *port = tty->driver_data; - struct keyspan_pda_private *priv = usb_get_serial_port_data(port); - unsigned long flags; - int room = 0; - - spin_lock_irqsave(&port->lock, flags); - if (test_bit(0, &port->write_urbs_free)) - room = priv->tx_room; - spin_unlock_irqrestore(&port->lock, flags); + int rc; - return room; -} + dev_dbg(&port->dev, "%s - count = %d\n", __func__, count); -static int keyspan_pda_chars_in_buffer(struct tty_struct *tty) -{ - struct usb_serial_port *port = tty->driver_data; - struct keyspan_pda_private *priv; - unsigned long flags; - int ret = 0; + if (!count) + return 0; - priv = usb_get_serial_port_data(port); + count = kfifo_in_locked(&port->write_fifo, buf, count, &port->lock); - /* when throttled, return at least WAKEUP_CHARS to tell select() (via - n_tty.c:normal_poll() ) that we're not writeable. */ + rc = keyspan_pda_write_start(port); + if (rc) + return rc; - spin_lock_irqsave(&port->lock, flags); - if (!test_bit(0, &port->write_urbs_free) || priv->tx_room == 0) - ret = 256; - spin_unlock_irqrestore(&port->lock, flags); - return ret; + return count; } - static void keyspan_pda_dtr_rts(struct usb_serial_port *port, int on) { struct usb_serial *serial = port->serial; @@ -640,12 +630,19 @@ static void keyspan_pda_close(struct usb_serial_port *port) { struct keyspan_pda_private *priv = usb_get_serial_port_data(port); - usb_kill_urb(port->write_urb); + /* + * Stop the interrupt URB first as its completion handler may submit + * the write URB. + */ usb_kill_urb(port->interrupt_in_urb); + usb_kill_urb(port->write_urb); cancel_work_sync(&priv->unthrottle_work); -} + spin_lock_irq(&port->lock); + kfifo_reset(&port->write_fifo); + spin_unlock_irq(&port->lock); +} /* download the firmware to a "fake" device (pre-renumeration) */ static int keyspan_pda_fake_startup(struct usb_serial *serial) @@ -759,10 +756,8 @@ static struct usb_serial_driver keyspan_pda_device = { .open = keyspan_pda_open, .close = keyspan_pda_close, .write = keyspan_pda_write, - .write_room = keyspan_pda_write_room, .write_bulk_callback = keyspan_pda_write_bulk_callback, .read_int_callback = keyspan_pda_rx_interrupt, - .chars_in_buffer = keyspan_pda_chars_in_buffer, .throttle = keyspan_pda_rx_throttle, .unthrottle = keyspan_pda_rx_unthrottle, .set_termios = keyspan_pda_set_termios, From patchwork Sun Oct 25 17:45:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 11855355 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 00F5A92C for ; Sun, 25 Oct 2020 17:47:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D8C0D21D41 for ; Sun, 25 Oct 2020 17:47:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603648025; bh=zkGIC9gBQ2oExaYmsGOOsJc8wFYioayl5UXRNMjOFf0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=I7RJTwyVG2iErMZJ74TT5EDisg2cXFWNWjR2pmrEbOuyd/Fk6oLIKIhjuS7OxhFOi Jj+DhNRgAz9d8BTfDewQqO3MBTa1/xyKeJflMpGBAzfktUlQmqudtUtwTNBxQKa/Ox 2YHXEmXCmKz0xAtOjabpLtwaSTRGLd1VeW2iyr8Y= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1417669AbgJYRqz (ORCPT ); Sun, 25 Oct 2020 13:46:55 -0400 Received: from mail-lj1-f196.google.com ([209.85.208.196]:33253 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1417705AbgJYRqp (ORCPT ); Sun, 25 Oct 2020 13:46:45 -0400 Received: by mail-lj1-f196.google.com with SMTP id c21so7310897ljj.0; Sun, 25 Oct 2020 10:46:41 -0700 (PDT) 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=AGDmsU51VlNmwvmrx+C4NjJ6P2Sb+1uW9es0aJLQvH8=; b=DLa9SNh2haVZnKJDCVh37vkltNkF6cAqXIWtgcb2hesJiYHDqEgTZj8yA4BSQ2+pa8 hWEvUXOsAGYxwjCnHT70sgHKKsZy+I1iObCLU0cVqtFgUhpIvCCKVqplQ27GTEuitw/n n7q6LGZuKXfIMVZHwT912MxVwXmPAWlN67Uca3YADGr7Dm9PhNajEuNj/Wpjl6+C3ABN i4wdiMz6rZc0uUhB8NmsZ0CziHkm3QMc07iQdAEZFnwq3CH7S4At+OfE74xVxn0Ko+mk POa7KrwGAtlh6g6IMLtz/HpEcGLJh7zBHil3gxTnSi84rIafnGW2Z2GijqUtETDOqBeu B48w== X-Gm-Message-State: AOAM532BeZe57fcT7PeQPoP1Q5hZMIxL4D60N39rWGvbllPGZzXOySRS F4POE6BOW9K5JeACCOYrGyi/Ji9lHnJWrA== X-Google-Smtp-Source: ABdhPJzB8QhtqcaIcFbIYe8gTJ0mYx6BYHnmh3pvknqCvi0ryg6HlLDaVdvtvbmLYksW8hrqfVMJ3Q== X-Received: by 2002:a2e:8612:: with SMTP id a18mr3950173lji.255.1603648000508; Sun, 25 Oct 2020 10:46:40 -0700 (PDT) Received: from xi.terra (c-beaee455.07-184-6d6c6d4.bbcust.telenor.se. [85.228.174.190]) by smtp.gmail.com with ESMTPSA id o4sm796693lfg.247.2020.10.25.10.46.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Oct 2020 10:46:37 -0700 (PDT) Received: from johan by xi.terra with local (Exim 4.93.0.4) (envelope-from ) id 1kWk6J-0007Hy-Bj; Sun, 25 Oct 2020 18:46:39 +0100 From: Johan Hovold To: linux-usb@vger.kernel.org Cc: "Ahmed S . Darwish" , Sebastian Andrzej Siewior , Thomas Gleixner , linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH 11/14] USB: serial: keyspan_pda: clean up xircom/entrega support Date: Sun, 25 Oct 2020 18:45:57 +0100 Message-Id: <20201025174600.27896-12-johan@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201025174600.27896-1-johan@kernel.org> References: <20201025174600.27896-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Drop the separate Kconfig symbol for Xircom / Entrega and always include support in the keyspan_pda driver. Signed-off-by: Johan Hovold --- drivers/usb/serial/Kconfig | 19 ++------- drivers/usb/serial/Makefile | 1 - drivers/usb/serial/keyspan_pda.c | 68 +++++--------------------------- 3 files changed, 13 insertions(+), 75 deletions(-) diff --git a/drivers/usb/serial/Kconfig b/drivers/usb/serial/Kconfig index 4007fa25a8ff..a21ff5ab6df9 100644 --- a/drivers/usb/serial/Kconfig +++ b/drivers/usb/serial/Kconfig @@ -298,12 +298,12 @@ config USB_SERIAL_IUU module will be called iuu_phoenix.o config USB_SERIAL_KEYSPAN_PDA - tristate "USB Keyspan PDA Single Port Serial Driver" + tristate "USB Keyspan PDA / Xircom Single Port Serial Driver" select USB_EZUSB_FX2 help - Say Y here if you want to use a Keyspan PDA single port USB to - serial converter device. This driver makes use of firmware - developed from scratch by Brian Warner. + Say Y here if you want to use a Keyspan PDA, Xircom or Entrega single + port USB to serial converter device. This driver makes use of + firmware developed from scratch by Brian Warner. To compile this driver as a module, choose M here: the module will be called keyspan_pda. @@ -538,17 +538,6 @@ config USB_SERIAL_CYBERJACK If unsure, say N. -config USB_SERIAL_XIRCOM - tristate "USB Xircom / Entrega Single Port Serial Driver" - select USB_EZUSB_FX2 - help - Say Y here if you want to use a Xircom or Entrega single port USB to - serial converter device. This driver makes use of firmware - developed from scratch by Brian Warner. - - To compile this driver as a module, choose M here: the - module will be called keyspan_pda. - config USB_SERIAL_WWAN tristate diff --git a/drivers/usb/serial/Makefile b/drivers/usb/serial/Makefile index 2d491e434f11..50c53aed787a 100644 --- a/drivers/usb/serial/Makefile +++ b/drivers/usb/serial/Makefile @@ -61,5 +61,4 @@ obj-$(CONFIG_USB_SERIAL_UPD78F0730) += upd78f0730.o obj-$(CONFIG_USB_SERIAL_VISOR) += visor.o obj-$(CONFIG_USB_SERIAL_WISHBONE) += wishbone-serial.o obj-$(CONFIG_USB_SERIAL_WHITEHEAT) += whiteheat.o -obj-$(CONFIG_USB_SERIAL_XIRCOM) += keyspan_pda.o obj-$(CONFIG_USB_SERIAL_XSENS_MT) += xsens_mt.o diff --git a/drivers/usb/serial/keyspan_pda.c b/drivers/usb/serial/keyspan_pda.c index aa19dd181e42..f102dbf83492 100644 --- a/drivers/usb/serial/keyspan_pda.c +++ b/drivers/usb/serial/keyspan_pda.c @@ -26,18 +26,6 @@ #include #include -/* make a simple define to handle if we are compiling keyspan_pda or xircom support */ -#if IS_ENABLED(CONFIG_USB_SERIAL_KEYSPAN_PDA) - #define KEYSPAN -#else - #undef KEYSPAN -#endif -#if IS_ENABLED(CONFIG_USB_SERIAL_XIRCOM) - #define XIRCOM -#else - #undef XIRCOM -#endif - #define DRIVER_AUTHOR "Brian Warner , Johan Hovold " #define DRIVER_DESC "USB Keyspan PDA Converter driver" @@ -64,18 +52,13 @@ static int keyspan_pda_write_start(struct usb_serial_port *port); #define ENTREGA_FAKE_ID 0x8093 static const struct usb_device_id id_table_combined[] = { -#ifdef KEYSPAN { USB_DEVICE(KEYSPAN_VENDOR_ID, KEYSPAN_PDA_FAKE_ID) }, -#endif -#ifdef XIRCOM { USB_DEVICE(XIRCOM_VENDOR_ID, XIRCOM_FAKE_ID) }, { USB_DEVICE(XIRCOM_VENDOR_ID, XIRCOM_FAKE_ID_2) }, { USB_DEVICE(ENTREGA_VENDOR_ID, ENTREGA_FAKE_ID) }, -#endif { USB_DEVICE(KEYSPAN_VENDOR_ID, KEYSPAN_PDA_ID) }, { } /* Terminating entry */ }; - MODULE_DEVICE_TABLE(usb, id_table_combined); static const struct usb_device_id id_table_std[] = { @@ -83,21 +66,13 @@ static const struct usb_device_id id_table_std[] = { { } /* Terminating entry */ }; -#ifdef KEYSPAN static const struct usb_device_id id_table_fake[] = { { USB_DEVICE(KEYSPAN_VENDOR_ID, KEYSPAN_PDA_FAKE_ID) }, - { } /* Terminating entry */ -}; -#endif - -#ifdef XIRCOM -static const struct usb_device_id id_table_fake_xircom[] = { { USB_DEVICE(XIRCOM_VENDOR_ID, XIRCOM_FAKE_ID) }, { USB_DEVICE(XIRCOM_VENDOR_ID, XIRCOM_FAKE_ID_2) }, { USB_DEVICE(ENTREGA_VENDOR_ID, ENTREGA_FAKE_ID) }, - { } + { } /* Terminating entry */ }; -#endif static int keyspan_pda_get_write_room(struct keyspan_pda_private *priv) { @@ -647,22 +622,21 @@ static void keyspan_pda_close(struct usb_serial_port *port) /* download the firmware to a "fake" device (pre-renumeration) */ static int keyspan_pda_fake_startup(struct usb_serial *serial) { + unsigned int vid = le16_to_cpu(serial->dev->descriptor.idVendor); const char *fw_name; /* download the firmware here ... */ ezusb_fx1_set_reset(serial->dev, 1); - if (0) { ; } -#ifdef KEYSPAN - else if (le16_to_cpu(serial->dev->descriptor.idVendor) == KEYSPAN_VENDOR_ID) + switch (vid) { + case KEYSPAN_VENDOR_ID: fw_name = "keyspan_pda/keyspan_pda.fw"; -#endif -#ifdef XIRCOM - else if ((le16_to_cpu(serial->dev->descriptor.idVendor) == XIRCOM_VENDOR_ID) || - (le16_to_cpu(serial->dev->descriptor.idVendor) == ENTREGA_VENDOR_ID)) + break; + case XIRCOM_VENDOR_ID: + case ENTREGA_VENDOR_ID: fw_name = "keyspan_pda/xircom_pgs.fw"; -#endif - else { + break; + default: dev_err(&serial->dev->dev, "%s: unknown vendor, aborting.\n", __func__); return -ENODEV; @@ -681,12 +655,8 @@ static int keyspan_pda_fake_startup(struct usb_serial *serial) return 1; } -#ifdef KEYSPAN MODULE_FIRMWARE("keyspan_pda/keyspan_pda.fw"); -#endif -#ifdef XIRCOM MODULE_FIRMWARE("keyspan_pda/xircom_pgs.fw"); -#endif static int keyspan_pda_port_probe(struct usb_serial_port *port) { @@ -716,7 +686,6 @@ static int keyspan_pda_port_remove(struct usb_serial_port *port) return 0; } -#ifdef KEYSPAN static struct usb_serial_driver keyspan_pda_fake_device = { .driver = { .owner = THIS_MODULE, @@ -727,20 +696,6 @@ static struct usb_serial_driver keyspan_pda_fake_device = { .num_ports = 1, .attach = keyspan_pda_fake_startup, }; -#endif - -#ifdef XIRCOM -static struct usb_serial_driver xircom_pgs_fake_device = { - .driver = { - .owner = THIS_MODULE, - .name = "xircom_no_firm", - }, - .description = "Xircom / Entrega PGS - (prerenumeration)", - .id_table = id_table_fake_xircom, - .num_ports = 1, - .attach = keyspan_pda_fake_startup, -}; -#endif static struct usb_serial_driver keyspan_pda_device = { .driver = { @@ -770,12 +725,7 @@ static struct usb_serial_driver keyspan_pda_device = { static struct usb_serial_driver * const serial_drivers[] = { &keyspan_pda_device, -#ifdef KEYSPAN &keyspan_pda_fake_device, -#endif -#ifdef XIRCOM - &xircom_pgs_fake_device, -#endif NULL }; From patchwork Sun Oct 25 17:45:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 11855377 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 C4D97139F for ; Sun, 25 Oct 2020 18:02:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 96D0521D41 for ; Sun, 25 Oct 2020 18:02:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603648933; bh=svPqoa0FcIoanPIjGYn36MwHZlJMa/DhoSp5BMTFB68=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=hu7l3ZsFjOE5eKyF7Pwh8/BPcHMHpYviDMO1XIjjCbCoCB748CCEVHu0u8jl/CxAg WYAcw9OWXBm1Ikb2Xd45tnUftewRDSHt7LQxzXGJ+8naGpdxRbSdkZdfKXu8yqLoQi vD7Hmjcfs/zZ3PqBToajr1nsxVV11pfHBCmrVV+A= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1417750AbgJYSCJ (ORCPT ); Sun, 25 Oct 2020 14:02:09 -0400 Received: from mail-lf1-f66.google.com ([209.85.167.66]:41995 "EHLO mail-lf1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2437136AbgJYSCI (ORCPT ); Sun, 25 Oct 2020 14:02:08 -0400 Received: by mail-lf1-f66.google.com with SMTP id a7so8929843lfk.9; Sun, 25 Oct 2020 11:02:05 -0700 (PDT) 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=MYxrGPwPmNlWY3Qwx3a7M1zBcj46Y4g6IU5EjbG12vA=; b=Q9tDIlb0adTetHZP0xF4OihPn6LUvzZykcS1HysN+JA3x6uNYopuYPYxKLqpJFwKi/ YRzLE9woyYH8ftiuOhlcbFOlF54rZCrxT0/WO6gjUhkWKY1xdewvr7OYTbFEPGyYn378 HwaE1x6mgDZhSWxp/N4FKLxzG79DePIQok7NUBKtgq5uUX3kIBB5UYFKv3y7RkyPZp9B LqmzmaOxGkkf3oJnDELPPCNik7hLznpEsg7r0ouWqC2fl6a8oxLr7NknKTWaHJIzO6k7 kDXKSTqXVa0eRQS7zhB933q3PkpPAKi7CgHd/pRPQXa9nFps0dRJcdXPj00yTmCi7jZe WB8A== X-Gm-Message-State: AOAM533Spd8CIMTM114hiPjOjtcYTq6AGQ+cNXr5rgVLSOOGvt0xPp6V GVmCBZFBDM3sJGolV3b5YEn4C16CTho1jw== X-Google-Smtp-Source: ABdhPJwjCHr0Va2ItWvQ3V06dkbEmIwTzfuW608yK9FwVSxCpUDDHK+X5gKeq3tcQOClLU2dnalBfQ== X-Received: by 2002:a19:8488:: with SMTP id g130mr3872370lfd.424.1603648923737; Sun, 25 Oct 2020 11:02:03 -0700 (PDT) Received: from xi.terra (c-beaee455.07-184-6d6c6d4.bbcust.telenor.se. [85.228.174.190]) by smtp.gmail.com with ESMTPSA id y5sm797192lff.179.2020.10.25.11.02.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Oct 2020 11:02:02 -0700 (PDT) Received: from johan by xi.terra with local (Exim 4.93.0.4) (envelope-from ) id 1kWk6J-0007I3-ED; Sun, 25 Oct 2020 18:46:39 +0100 From: Johan Hovold To: linux-usb@vger.kernel.org Cc: "Ahmed S . Darwish" , Sebastian Andrzej Siewior , Thomas Gleixner , linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH 12/14] USB: serial: keyspan_pda: clean up comments and whitespace Date: Sun, 25 Oct 2020 18:45:58 +0100 Message-Id: <20201025174600.27896-13-johan@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201025174600.27896-1-johan@kernel.org> References: <20201025174600.27896-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Clean up comment style, remove some stale or redundant comments and drop superfluous white space. Signed-off-by: Johan Hovold --- drivers/usb/serial/keyspan_pda.c | 116 +++++++++++++++---------------- 1 file changed, 56 insertions(+), 60 deletions(-) diff --git a/drivers/usb/serial/keyspan_pda.c b/drivers/usb/serial/keyspan_pda.c index f102dbf83492..8df7c54d6986 100644 --- a/drivers/usb/serial/keyspan_pda.c +++ b/drivers/usb/serial/keyspan_pda.c @@ -11,7 +11,6 @@ * driver */ - #include #include #include @@ -121,8 +120,10 @@ static void keyspan_pda_request_unthrottle(struct work_struct *work) dev_dbg(&port->dev, "%s\n", __func__); - /* ask the device to tell us when the tx buffer becomes - sufficiently empty */ + /* + * Ask the device to tell us when the tx buffer becomes + * sufficiently empty. + */ result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), 7, /* request_unthrottle */ @@ -208,7 +209,6 @@ static void keyspan_pda_rx_interrupt(struct urb *urb) keyspan_pda_write_start(port); - /* queue up a wakeup at scheduler time */ usb_serial_port_softint(port); break; default: @@ -227,31 +227,30 @@ static void keyspan_pda_rx_interrupt(struct urb *urb) __func__, retval); } - static void keyspan_pda_rx_throttle(struct tty_struct *tty) { - /* stop receiving characters. We just turn off the URB request, and - let chars pile up in the device. If we're doing hardware - flowcontrol, the device will signal the other end when its buffer - fills up. If we're doing XON/XOFF, this would be a good time to - send an XOFF, although it might make sense to foist that off - upon the device too. */ struct usb_serial_port *port = tty->driver_data; + /* + * Stop receiving characters. We just turn off the URB request, and + * let chars pile up in the device. If we're doing hardware + * flowcontrol, the device will signal the other end when its buffer + * fills up. If we're doing XON/XOFF, this would be a good time to + * send an XOFF, although it might make sense to foist that off upon + * the device too. + */ usb_kill_urb(port->interrupt_in_urb); } - static void keyspan_pda_rx_unthrottle(struct tty_struct *tty) { struct usb_serial_port *port = tty->driver_data; - /* just restart the receive interrupt URB */ + /* just restart the receive interrupt URB */ if (usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL)) dev_dbg(&port->dev, "usb_submit_urb(read urb) failed\n"); } - static speed_t keyspan_pda_setbaud(struct usb_serial *serial, speed_t baud) { int rc; @@ -293,8 +292,6 @@ static speed_t keyspan_pda_setbaud(struct usb_serial *serial, speed_t baud) baud = 9600; } - /* rather than figure out how to sleep while waiting for this - to complete, I just use the "legacy" API. */ rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), 0, /* set baud */ USB_TYPE_VENDOR @@ -307,10 +304,10 @@ static speed_t keyspan_pda_setbaud(struct usb_serial *serial, speed_t baud) 2000); /* timeout */ if (rc < 0) return 0; + return baud; } - static void keyspan_pda_break_ctl(struct tty_struct *tty, int break_state) { struct usb_serial_port *port = tty->driver_data; @@ -322,6 +319,7 @@ static void keyspan_pda_break_ctl(struct tty_struct *tty, int break_state) value = 1; /* start break */ else value = 0; /* clear break */ + result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), 4, /* set break */ USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT, @@ -329,39 +327,35 @@ static void keyspan_pda_break_ctl(struct tty_struct *tty, int break_state) if (result < 0) dev_dbg(&port->dev, "%s - error %d from usb_control_msg\n", __func__, result); - /* there is something funky about this.. the TCSBRK that 'cu' performs - ought to translate into a break_ctl(-1),break_ctl(0) pair HZ/4 - seconds apart, but it feels like the break sent isn't as long as it - is on /dev/ttyS0 */ } - static void keyspan_pda_set_termios(struct tty_struct *tty, struct usb_serial_port *port, struct ktermios *old_termios) { struct usb_serial *serial = port->serial; speed_t speed; - /* cflag specifies lots of stuff: number of stop bits, parity, number - of data bits, baud. What can the device actually handle?: - CSTOPB (1 stop bit or 2) - PARENB (parity) - CSIZE (5bit .. 8bit) - There is minimal hw support for parity (a PSW bit seems to hold the - parity of whatever is in the accumulator). The UART either deals - with 10 bits (start, 8 data, stop) or 11 bits (start, 8 data, - 1 special, stop). So, with firmware changes, we could do: - 8N1: 10 bit - 8N2: 11 bit, extra bit always (mark?) - 8[EOMS]1: 11 bit, extra bit is parity - 7[EOMS]1: 10 bit, b0/b7 is parity - 7[EOMS]2: 11 bit, b0/b7 is parity, extra bit always (mark?) - - HW flow control is dictated by the tty->termios.c_cflags & CRTSCTS - bit. - - For now, just do baud. */ - + /* + * cflag specifies lots of stuff: number of stop bits, parity, number + * of data bits, baud. What can the device actually handle?: + * CSTOPB (1 stop bit or 2) + * PARENB (parity) + * CSIZE (5bit .. 8bit) + * There is minimal hw support for parity (a PSW bit seems to hold the + * parity of whatever is in the accumulator). The UART either deals + * with 10 bits (start, 8 data, stop) or 11 bits (start, 8 data, + * 1 special, stop). So, with firmware changes, we could do: + * 8N1: 10 bit + * 8N2: 11 bit, extra bit always (mark?) + * 8[EOMS]1: 11 bit, extra bit is parity + * 7[EOMS]1: 10 bit, b0/b7 is parity + * 7[EOMS]2: 11 bit, b0/b7 is parity, extra bit always (mark?) + * + * HW flow control is dictated by the tty->termios.c_cflags & CRTSCTS + * bit. + * + * For now, just do baud. + */ speed = tty_get_baud_rate(tty); speed = keyspan_pda_setbaud(serial, speed); @@ -370,17 +364,19 @@ static void keyspan_pda_set_termios(struct tty_struct *tty, /* It hasn't changed so.. */ speed = tty_termios_baud_rate(old_termios); } - /* Only speed can change so copy the old h/w parameters - then encode the new speed */ + /* + * Only speed can change so copy the old h/w parameters then encode + * the new speed. + */ tty_termios_copy_hw(&tty->termios, old_termios); tty_encode_baud_rate(tty, speed, speed); } - -/* modem control pins: DTR and RTS are outputs and can be controlled. - DCD, RI, DSR, CTS are inputs and can be read. All outputs can also be - read. The byte passed is: DTR(b7) DCD RI DSR CTS RTS(b2) unused unused */ - +/* + * Modem control pins: DTR and RTS are outputs and can be controlled. + * DCD, RI, DSR, CTS are inputs and can be read. All outputs can also be + * read. The byte passed is: DTR(b7) DCD RI DSR CTS RTS(b2) unused unused. + */ static int keyspan_pda_get_modem_info(struct usb_serial *serial, unsigned char *value) { @@ -404,7 +400,6 @@ static int keyspan_pda_get_modem_info(struct usb_serial *serial, return rc; } - static int keyspan_pda_set_modem_info(struct usb_serial *serial, unsigned char value) { @@ -480,10 +475,11 @@ static int keyspan_pda_write_start(struct usb_serial_port *port) * unthrottle work is scheduled). */ - /* we might block because of: - the TX urb is in-flight (wait until it completes) - the device is full (wait until it says there is room) - */ + /* + * We might block because of: + * the TX urb is in-flight (wait until it completes) + * the device is full (wait until it says there is room) + */ spin_lock_irqsave(&port->lock, flags); room = priv->tx_room; @@ -542,7 +538,6 @@ static void keyspan_pda_write_bulk_callback(struct urb *urb) keyspan_pda_write_start(port); - /* queue up a wakeup at scheduler time */ usb_serial_port_softint(port); } @@ -591,7 +586,6 @@ static int keyspan_pda_open(struct tty_struct *tty, priv->tx_room = rc; spin_unlock_irq(&port->lock); - /*Start reading from the device*/ rc = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); if (rc) { dev_dbg(&port->dev, "%s - usb_submit_urb(read int) failed\n", __func__); @@ -648,10 +642,12 @@ static int keyspan_pda_fake_startup(struct usb_serial *serial) return -ENOENT; } - /* after downloading firmware Renumeration will occur in a - moment and the new device will bind to the real driver */ + /* + * After downloading firmware renumeration will occur in a moment and + * the new device will bind to the real driver. + */ - /* we want this device to fail to have a driver assigned to it. */ + /* We want this device to fail to have a driver assigned to it. */ return 1; } @@ -711,7 +707,7 @@ static struct usb_serial_driver keyspan_pda_device = { .open = keyspan_pda_open, .close = keyspan_pda_close, .write = keyspan_pda_write, - .write_bulk_callback = keyspan_pda_write_bulk_callback, + .write_bulk_callback = keyspan_pda_write_bulk_callback, .read_int_callback = keyspan_pda_rx_interrupt, .throttle = keyspan_pda_rx_throttle, .unthrottle = keyspan_pda_rx_unthrottle, From patchwork Sun Oct 25 17:45:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 11855353 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 1E64492C for ; Sun, 25 Oct 2020 17:46:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 05B0C21D41 for ; Sun, 25 Oct 2020 17:46:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603648018; bh=+nqdmEedrz2ej2wSa/84Jmn3Nqaq4tIZ99VmGtYOF2o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=U3HnBVhLgycrXLeufSyUHudKn8/02O6aigrXaBRN/dcC71FwPzZG5fmmDsYc8KVBf tuzpklctCqUk+cts8I4tV7GbCu1LtFCpzCSQEXw6rfODGEwmaQAy+gfuZCIUZEBfHd /YxmVaI6GM61MWZjkOirNFFs7nvejxN5rC50kSY8= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1417779AbgJYRq4 (ORCPT ); Sun, 25 Oct 2020 13:46:56 -0400 Received: from mail-lf1-f67.google.com ([209.85.167.67]:40870 "EHLO mail-lf1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1417743AbgJYRqo (ORCPT ); Sun, 25 Oct 2020 13:46:44 -0400 Received: by mail-lf1-f67.google.com with SMTP id a9so8915762lfc.7; Sun, 25 Oct 2020 10:46:42 -0700 (PDT) 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=QfMi3ClKlPdDVMDtR633RD5RCm08X2WBNam9SHBHedk=; b=ZK2GE2Rj61LFyfkYpr9oJD9+OyRy40u0ZCQZj01KI8DiPhYNY4qZSI5L901IA9KMFy kAh+0mglx7wHdBlobN0tfaEoulfLIl+cOqZ01jqPViEKK0selfwFqKf4lxqIB44s3EXi e6nfIVBQPAjePvCBwVBS58+77kDhWJHcPHQtVTF1pI7de/cPz9Vvb0kur9/Pm3SrcY4a AIDOvnuQCdukyUMwzj8q2+vWM+PqrK0Wm7HVIJLefIT7IeKJu77bpVsB6W7TcJn5WonI YKnphkIHDwCciqwXOgmrGGkVbP9a2pNFJv6VuEseBxuoHHmS63PlPUzjjbE/Z1rKG58B KeSA== X-Gm-Message-State: AOAM530s6POVe1Bcdu7Ev8loV5LMXHbU3KvQWPN6snMnRLf+0AGy8g/d SRDD4nZiYWog54mmEGoKN1xUzE1bIjRZyg== X-Google-Smtp-Source: ABdhPJwYRoT8mWeYWYoRpSepxVWAm21du12FdTMat07W4/e71QLZi3BS43YwB9JIV4BGZtyE3nkyig== X-Received: by 2002:a05:6512:1182:: with SMTP id g2mr3601380lfr.198.1603648001750; Sun, 25 Oct 2020 10:46:41 -0700 (PDT) Received: from xi.terra (c-beaee455.07-184-6d6c6d4.bbcust.telenor.se. [85.228.174.190]) by smtp.gmail.com with ESMTPSA id s19sm793732lfb.224.2020.10.25.10.46.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Oct 2020 10:46:37 -0700 (PDT) Received: from johan by xi.terra with local (Exim 4.93.0.4) (envelope-from ) id 1kWk6J-0007I7-Gi; Sun, 25 Oct 2020 18:46:39 +0100 From: Johan Hovold To: linux-usb@vger.kernel.org Cc: "Ahmed S . Darwish" , Sebastian Andrzej Siewior , Thomas Gleixner , linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH 13/14] USB: serial: keyspan_pda: use BIT() macro Date: Sun, 25 Oct 2020 18:45:59 +0100 Message-Id: <20201025174600.27896-14-johan@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201025174600.27896-1-johan@kernel.org> References: <20201025174600.27896-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Use the BIT() macro instead of open coding. Signed-off-by: Johan Hovold --- drivers/usb/serial/keyspan_pda.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/drivers/usb/serial/keyspan_pda.c b/drivers/usb/serial/keyspan_pda.c index 8df7c54d6986..f582e0a3ae56 100644 --- a/drivers/usb/serial/keyspan_pda.c +++ b/drivers/usb/serial/keyspan_pda.c @@ -422,13 +422,14 @@ static int keyspan_pda_tiocmget(struct tty_struct *tty) rc = keyspan_pda_get_modem_info(serial, &status); if (rc < 0) return rc; - value = - ((status & (1<<7)) ? TIOCM_DTR : 0) | - ((status & (1<<6)) ? TIOCM_CAR : 0) | - ((status & (1<<5)) ? TIOCM_RNG : 0) | - ((status & (1<<4)) ? TIOCM_DSR : 0) | - ((status & (1<<3)) ? TIOCM_CTS : 0) | - ((status & (1<<2)) ? TIOCM_RTS : 0); + + value = ((status & BIT(7)) ? TIOCM_DTR : 0) | + ((status & BIT(6)) ? TIOCM_CAR : 0) | + ((status & BIT(5)) ? TIOCM_RNG : 0) | + ((status & BIT(4)) ? TIOCM_DSR : 0) | + ((status & BIT(3)) ? TIOCM_CTS : 0) | + ((status & BIT(2)) ? TIOCM_RTS : 0); + return value; } @@ -445,14 +446,14 @@ static int keyspan_pda_tiocmset(struct tty_struct *tty, return rc; if (set & TIOCM_RTS) - status |= (1<<2); + status |= BIT(2); if (set & TIOCM_DTR) - status |= (1<<7); + status |= BIT(7); if (clear & TIOCM_RTS) - status &= ~(1<<2); + status &= ~BIT(2); if (clear & TIOCM_DTR) - status &= ~(1<<7); + status &= ~BIT(7); rc = keyspan_pda_set_modem_info(serial, status); return rc; } @@ -565,7 +566,7 @@ static void keyspan_pda_dtr_rts(struct usb_serial_port *port, int on) struct usb_serial *serial = port->serial; if (on) - keyspan_pda_set_modem_info(serial, (1 << 7) | (1 << 2)); + keyspan_pda_set_modem_info(serial, BIT(7) | BIT(2)); else keyspan_pda_set_modem_info(serial, 0); } From patchwork Sun Oct 25 17:46:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 11855357 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 CB32C697 for ; Sun, 25 Oct 2020 17:47:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AA08D21D41 for ; Sun, 25 Oct 2020 17:47:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603648030; bh=Ktt2g+jiMARinnvyV05Be+tBgWe5CNburp1M1IWGI/Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=2oQRKXc1lmdsykEnVX6K6zwMnC/49CnaZcr+EmiynkygRXeDJb0sBwsCYSP1C/+RF dNmcz8i+DP9cJoSBS43UgOLWHDebeeZpFpbS7L4SPn8WaCZge1CpiKo7YBzgUNtGm7 /hxRPdjvd4e336E1swJjmEjfa51B4V1iAWAB5mR4= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1417798AbgJYRrJ (ORCPT ); Sun, 25 Oct 2020 13:47:09 -0400 Received: from mail-lf1-f67.google.com ([209.85.167.67]:44311 "EHLO mail-lf1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1417738AbgJYRqn (ORCPT ); Sun, 25 Oct 2020 13:46:43 -0400 Received: by mail-lf1-f67.google.com with SMTP id b1so8902453lfp.11; Sun, 25 Oct 2020 10:46:42 -0700 (PDT) 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=77GzeQG87LnkHIGFnWR/f42oB74q65RC2+RYqg9LfxE=; b=mHOwOQwkZcz3Iuoa9vTzGH0MgxQL59HvkHP4bKdxuhOkhjbLjlXelby3FxCrGxL588 6eFyo8z/Bw6d8IzYWxCBbS6ABZNfiVWkQb9uhvI3rFZzguVTkZgxlOk47A5MpmugoBXp +CexKGgs/0Ym+ukdiMa4NNe2z7oCzNxhrMseHAaw/8mcXZrDO+b1/UKbf+GfzNnKxmW1 2qr7n5sfehVacMbX4zy2s4eKdAAX0kYbnxcSjyKQme7Fm7KR+2TVkbe6RyqE7mrfehuM TRjPQ55+Gfh8SLPJ3A2Kz5UDyv7izEn/cw7jIcmyZTP4ubGBnRISt0l8YNVXLX22mbCp AFmg== X-Gm-Message-State: AOAM530JLpmZl+Lp1zBPWFNJJBomTe9QSMJJVAVBzJIB9D67k3a6p3zR /gAI9tKZZTo8r7hbxqv5l3gINhj5HuKlbw== X-Google-Smtp-Source: ABdhPJydIn6vU9cPJvKdPOun7F9klGxXe/Dm004xscAiVrPVAdUMDertUE+YHJo4sYIRfoDJcCnQ6w== X-Received: by 2002:ac2:5c05:: with SMTP id r5mr4115205lfp.27.1603648000975; Sun, 25 Oct 2020 10:46:40 -0700 (PDT) Received: from xi.terra (c-beaee455.07-184-6d6c6d4.bbcust.telenor.se. [85.228.174.190]) by smtp.gmail.com with ESMTPSA id p14sm824010lfc.40.2020.10.25.10.46.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Oct 2020 10:46:37 -0700 (PDT) Received: from johan by xi.terra with local (Exim 4.93.0.4) (envelope-from ) id 1kWk6J-0007IC-JZ; Sun, 25 Oct 2020 18:46:39 +0100 From: Johan Hovold To: linux-usb@vger.kernel.org Cc: "Ahmed S . Darwish" , Sebastian Andrzej Siewior , Thomas Gleixner , linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH 14/14] USB: serial: keyspan_pda: drop redundant usb-serial pointer Date: Sun, 25 Oct 2020 18:46:00 +0100 Message-Id: <20201025174600.27896-15-johan@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201025174600.27896-1-johan@kernel.org> References: <20201025174600.27896-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Drop the redundant struct usb_serial pointer from the driver port data. Signed-off-by: Johan Hovold --- drivers/usb/serial/keyspan_pda.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/usb/serial/keyspan_pda.c b/drivers/usb/serial/keyspan_pda.c index f582e0a3ae56..e6f933e8d25f 100644 --- a/drivers/usb/serial/keyspan_pda.c +++ b/drivers/usb/serial/keyspan_pda.c @@ -76,7 +76,7 @@ static const struct usb_device_id id_table_fake[] = { static int keyspan_pda_get_write_room(struct keyspan_pda_private *priv) { struct usb_serial_port *port = priv->port; - struct usb_serial *serial = priv->serial; + struct usb_serial *serial = port->serial; u8 *room; int rc; @@ -114,7 +114,7 @@ static void keyspan_pda_request_unthrottle(struct work_struct *work) struct keyspan_pda_private *priv = container_of(work, struct keyspan_pda_private, unthrottle_work); struct usb_serial_port *port = priv->port; - struct usb_serial *serial = priv->serial; + struct usb_serial *serial = port->serial; unsigned long flags; int result; @@ -665,7 +665,6 @@ static int keyspan_pda_port_probe(struct usb_serial_port *port) return -ENOMEM; INIT_WORK(&priv->unthrottle_work, keyspan_pda_request_unthrottle); - priv->serial = port->serial; priv->port = port; usb_set_serial_port_data(port, priv);