From patchwork Thu Mar 18 15:51:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 405230 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E72ACC4321A for ; Thu, 18 Mar 2021 15:52:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C141D64EF6 for ; Thu, 18 Mar 2021 15:52:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231903AbhCRPwW (ORCPT ); Thu, 18 Mar 2021 11:52:22 -0400 Received: from mail.kernel.org ([198.145.29.99]:54668 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231640AbhCRPwA (ORCPT ); Thu, 18 Mar 2021 11:52:00 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2A0B364F2B; Thu, 18 Mar 2021 15:52:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1616082720; bh=e/lpZ0wThnKoFB2K3ago5r1z4Pnc0Pi1QIWPHg8ZIis=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=i2f991Fp9+EGj3b9w0kw5Uab5TCCeytBeL+jShcRQeU/yB3qKGmG2NStUqWsJrRX5 L33LvCWnzfWzNSW4Ao1A8O02hQJB9LJpwqrFa1Y+Ko2KcJmif/AeEqtUC4zh6kRWN8 18y5FkcNKSnqFhD0BcTfEF7Peu+mdNzXrhsBTL0NUZ/IgwtnXocd+uOJf8XW+BA5Ln YdRGRcFL1opuzkotir6nQKKsaGdZkGlsOvGBpYCI6kA11ON+0DBeZtMGG2ScibNnpD sr0eOdyTxy9kq+54ndShc73TQnAaDbXxerTD6JoiF4grFhC/3Z3oqQ0Eu9Z2XB7Aph eEgNXRsXzQ0ug== Received: from johan by xi.lan with local (Exim 4.93.0.4) (envelope-from ) id 1lMuwb-0005nQ-Vb; Thu, 18 Mar 2021 16:52:18 +0100 From: Johan Hovold To: Oliver Neukum , Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold , stable@vger.kernel.org, Jaejoong Kim Subject: [PATCH 1/7] USB: cdc-acm: fix double free on probe failure Date: Thu, 18 Mar 2021 16:51:56 +0100 Message-Id: <20210318155202.22230-2-johan@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210318155202.22230-1-johan@kernel.org> References: <20210318155202.22230-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org If tty-device registration fails the driver copy of any Country Selection functional descriptor would end up being freed twice; first explicitly in the error path and then again in the tty-port destructor. Drop the first erroneous free that was left when fixing a tty-port resource leak. Fixes: cae2bc768d17 ("usb: cdc-acm: Decrement tty port's refcount if probe() fail") Cc: stable@vger.kernel.org # 4.19 Cc: Jaejoong Kim Signed-off-by: Johan Hovold Acked-by: Oliver Neukum --- drivers/usb/class/cdc-acm.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c index 39ddb5585ded..d75a78ad464d 100644 --- a/drivers/usb/class/cdc-acm.c +++ b/drivers/usb/class/cdc-acm.c @@ -1508,7 +1508,6 @@ static int acm_probe(struct usb_interface *intf, &dev_attr_wCountryCodes); device_remove_file(&acm->control->dev, &dev_attr_iCountryCodeRelDate); - kfree(acm->country_codes); } device_remove_file(&acm->control->dev, &dev_attr_bmCapabilities); alloc_fail5: From patchwork Thu Mar 18 15:51:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 404525 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 460D6C4332E for ; Thu, 18 Mar 2021 15:52:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0D2C664F18 for ; Thu, 18 Mar 2021 15:52:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231890AbhCRPwV (ORCPT ); Thu, 18 Mar 2021 11:52:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:54664 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231273AbhCRPwA (ORCPT ); Thu, 18 Mar 2021 11:52:00 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 32EC664F3B; Thu, 18 Mar 2021 15:52:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1616082720; bh=qO3rm93arLtFLEEeNwJWlSISTAbncxMUvYOkKzvd61k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GQPYdIV1eZImNBox0Vy5sSgjatrMZjWFAKn7P4c0XeG1cAH2Oz/Gio9sfOmJUzsUg J5IY3MNFolABuheKHRXB+TZupyKfhVZB2pmEHszJauk/bW6gmT0bhkSBS9n7AqWD6k PzPmioIQjm+YOH0M6+bvMxXCXODbwxYEwWqW4bUh9NiqYgLqR3Lpeqny3uIwfE/QXu YpZK3/mUVdrJrtYBWEhHE4miuS18HZE3Q09ZuQYqhwUwey1ReGLMjhNDf/ZcE/5Ezj QYD8qHdsWpr3Q1uYfbMjKoubSt1mtiIudlMqq006AikKSqwwkClH5L8ZY2hdcox9i8 4P5eY6TY13NrA== Received: from johan by xi.lan with local (Exim 4.93.0.4) (envelope-from ) id 1lMuwc-0005nS-2b; Thu, 18 Mar 2021 16:52:18 +0100 From: Johan Hovold To: Oliver Neukum , Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold , stable@vger.kernel.org, Alexey Khoroshilov Subject: [PATCH 2/7] USB: cdc-acm: fix use-after-free after probe failure Date: Thu, 18 Mar 2021 16:51:57 +0100 Message-Id: <20210318155202.22230-3-johan@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210318155202.22230-1-johan@kernel.org> References: <20210318155202.22230-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org If tty-device registration fails the driver would fail to release the data interface. When the device is later disconnected, the disconnect callback would still be called for the data interface and would go about releasing already freed resources. Fixes: c93d81955005 ("usb: cdc-acm: fix error handling in acm_probe()") Cc: stable@vger.kernel.org # 3.9 Cc: Alexey Khoroshilov Signed-off-by: Johan Hovold Acked-by: Oliver Neukum --- drivers/usb/class/cdc-acm.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c index d75a78ad464d..dfc2480add91 100644 --- a/drivers/usb/class/cdc-acm.c +++ b/drivers/usb/class/cdc-acm.c @@ -1503,6 +1503,11 @@ static int acm_probe(struct usb_interface *intf, return 0; alloc_fail6: + if (!acm->combined_interfaces) { + /* Clear driver data so that disconnect() returns early. */ + usb_set_intfdata(data_interface, NULL); + usb_driver_release_interface(&acm_driver, data_interface); + } if (acm->country_codes) { device_remove_file(&acm->control->dev, &dev_attr_wCountryCodes); From patchwork Thu Mar 18 15:51:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 405232 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B2723C433E6 for ; Thu, 18 Mar 2021 15:52:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6CC1864F3B for ; Thu, 18 Mar 2021 15:52:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229508AbhCRPwU (ORCPT ); Thu, 18 Mar 2021 11:52:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:54640 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230477AbhCRPwA (ORCPT ); Thu, 18 Mar 2021 11:52:00 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2240B64EF6; Thu, 18 Mar 2021 15:52:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1616082720; bh=+yNLBBpLQUesjQU9zH7hMX1JnxqzSjRK9z0Q3x+/JT8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hVkNpbIwu3KUht+BSIMxlDTC66nH0LJJuUUmJFIL7HUp2E/3BIAVCIiIdl+KZWL32 75kEEJs0ed7sfGdKrmvkXXNuW5ZmZrJqBBvXFv1xbL76b2xCYDl4Q4ex2z6UK6ju8l s1M0UCPiit+PEpct2Hep2Y8PnnZ8LMju98XYk36b+49QEjgtIOcIKvYdu5NzMbbwSN +k+CpG6F/C6GfKTCATfZU9790yVkJBNpGRDtlcdaZD4cYosu7pwr341/7x7+WcTAuT K6lhxUBDiWGyN7zqfk94vaKC8gsoKUM+HYpVDZoQw4ulkDDEHdphfPyKy04BZvtSDm djxfSDunEu1Xg== Received: from johan by xi.lan with local (Exim 4.93.0.4) (envelope-from ) id 1lMuwc-0005nU-5r; Thu, 18 Mar 2021 16:52:18 +0100 From: Johan Hovold To: Oliver Neukum , Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH 3/7] USB: cdc-acm: drop redundant driver-data assignment Date: Thu, 18 Mar 2021 16:51:58 +0100 Message-Id: <20210318155202.22230-4-johan@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210318155202.22230-1-johan@kernel.org> References: <20210318155202.22230-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The interface driver data has already been set by usb_driver_claim_interface() so drop the redundant subsequent assignment. Signed-off-by: Johan Hovold Acked-by: Oliver Neukum --- drivers/usb/class/cdc-acm.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c index dfc2480add91..36dd1e05e455 100644 --- a/drivers/usb/class/cdc-acm.c +++ b/drivers/usb/class/cdc-acm.c @@ -1487,7 +1487,6 @@ static int acm_probe(struct usb_interface *intf, acm_set_line(acm, &acm->line); usb_driver_claim_interface(&acm_driver, data_interface, acm); - usb_set_intfdata(data_interface, acm); tty_dev = tty_port_register_device(&acm->port, acm_tty_driver, minor, &control_interface->dev); From patchwork Thu Mar 18 15:51:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 404527 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 19492C4332D for ; Thu, 18 Mar 2021 15:52:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D382E64F38 for ; Thu, 18 Mar 2021 15:52:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231841AbhCRPwU (ORCPT ); Thu, 18 Mar 2021 11:52:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:54648 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231162AbhCRPwA (ORCPT ); Thu, 18 Mar 2021 11:52:00 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2743364F2A; Thu, 18 Mar 2021 15:52:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1616082720; bh=XCpyHJcikJIMvXUV+Xi8p6BJrS4vSE8cEJvypsVosz8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RAnAbtHQjlgQ/a8838gvKTg9IMOJzO7m/Ls2MCQ22pBQHGktHwsUShiUVKpRhqY1w R3jxIybkImNdII/IN+YHN7Q5NiZGXK+P8loxcLHmhziHF78wPu7yD7YK+2TsZJHMUg XNwQ8vio2CU+nmPfSCXBxd/xAx2kvv51+nWpSRT0I3Jvs20p51eZ7j3EdBKCqagS0d Ly99jD7en6PWFpWXa34Zlw9K+lAPFKVgGwotpwcFXFTtWHy2iWkkqW02JPfHeyu7WM XCu+nCwoecZR5M9WnmK5mCOakIT/Pb3VbNIV8sNwu1NIB7Rom91GwVJ15Knox1glHE JXGRsT9IRI4Yg== Received: from johan by xi.lan with local (Exim 4.93.0.4) (envelope-from ) id 1lMuwc-0005nY-8S; Thu, 18 Mar 2021 16:52:18 +0100 From: Johan Hovold To: Oliver Neukum , Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH 4/7] USB: cdc-acm: drop redundant driver-data reset Date: Thu, 18 Mar 2021 16:51:59 +0100 Message-Id: <20210318155202.22230-5-johan@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210318155202.22230-1-johan@kernel.org> References: <20210318155202.22230-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org There's no need to clear the interface driver data on failed probe (and driver core will clear it anyway). Signed-off-by: Johan Hovold Acked-by: Oliver Neukum --- drivers/usb/class/cdc-acm.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c index 36dd1e05e455..682772b8a4f7 100644 --- a/drivers/usb/class/cdc-acm.c +++ b/drivers/usb/class/cdc-acm.c @@ -1515,7 +1515,6 @@ static int acm_probe(struct usb_interface *intf, } device_remove_file(&acm->control->dev, &dev_attr_bmCapabilities); alloc_fail5: - usb_set_intfdata(intf, NULL); for (i = 0; i < ACM_NW; i++) usb_free_urb(acm->wb[i].urb); alloc_fail4: From patchwork Thu Mar 18 15:52:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 404528 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3265BC433DB for ; Thu, 18 Mar 2021 15:52:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E711A64F2A for ; Thu, 18 Mar 2021 15:52:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231802AbhCRPwT (ORCPT ); Thu, 18 Mar 2021 11:52:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:54654 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230465AbhCRPwA (ORCPT ); Thu, 18 Mar 2021 11:52:00 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 24B2A64EF2; Thu, 18 Mar 2021 15:52:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1616082720; bh=DX0hq+tbj++s6Jy8noJrCLIzxuMHgJ5jusyx7A2Vmkw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZqOVqLWcz5vyUbQyf9zz7dY17+eAVM+PZmjFiFJ+80ltTkFgYMSjhBWOqWEk25uQg cJp0xCEKhAh48L5HJJrnI7S12zFiNIQE+cNEF4LfwHFDSl4+ExpyFAZnWOmVutbZ4S hjUR1O7zDNLyuUAijeG0fxRD8eO4RcUFqqWLIMlCcs2oscyWYZxD58K/KETvS9bzbR JX3obSLvl1rV2w6xCP6CU9kOMzS13/yfLn5KYWoQlEzN7OfruPHFQvkvPJBqlBEPjM MYPcw61Sc26V+fmig4f12idsKVuOsYjitdp3zSbY17p6fyD8ppiZz1YOd0JvmTWINv 3QxS9gqucEG7Q== Received: from johan by xi.lan with local (Exim 4.93.0.4) (envelope-from ) id 1lMuwc-0005nd-Bm; Thu, 18 Mar 2021 16:52:18 +0100 From: Johan Hovold To: Oliver Neukum , Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH 5/7] USB: cdc-acm: clean up probe error labels Date: Thu, 18 Mar 2021 16:52:00 +0100 Message-Id: <20210318155202.22230-6-johan@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210318155202.22230-1-johan@kernel.org> References: <20210318155202.22230-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Name the probe error labels after what they do rather than using sequence numbers which is harder to review and maintain (e.g. may require renaming unrelated labels when a label is added or removed). Signed-off-by: Johan Hovold Acked-by: Oliver Neukum --- drivers/usb/class/cdc-acm.c | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c index 682772b8a4f7..e3c45f5880fc 100644 --- a/drivers/usb/class/cdc-acm.c +++ b/drivers/usb/class/cdc-acm.c @@ -1324,7 +1324,7 @@ static int acm_probe(struct usb_interface *intf, acm = kzalloc(sizeof(struct acm), GFP_KERNEL); if (acm == NULL) - goto alloc_fail; + return -ENOMEM; tty_port_init(&acm->port); acm->port.ops = &acm_port_ops; @@ -1341,7 +1341,7 @@ static int acm_probe(struct usb_interface *intf, minor = acm_alloc_minor(acm); if (minor < 0) - goto alloc_fail1; + goto err_put_port; acm->minor = minor; acm->dev = usb_dev; @@ -1372,15 +1372,15 @@ static int acm_probe(struct usb_interface *intf, buf = usb_alloc_coherent(usb_dev, ctrlsize, GFP_KERNEL, &acm->ctrl_dma); if (!buf) - goto alloc_fail1; + goto err_put_port; acm->ctrl_buffer = buf; if (acm_write_buffers_alloc(acm) < 0) - goto alloc_fail2; + goto err_free_ctrl_buffer; acm->ctrlurb = usb_alloc_urb(0, GFP_KERNEL); if (!acm->ctrlurb) - goto alloc_fail3; + goto err_free_write_buffers; for (i = 0; i < num_rx_buf; i++) { struct acm_rb *rb = &(acm->read_buffers[i]); @@ -1389,13 +1389,13 @@ static int acm_probe(struct usb_interface *intf, rb->base = usb_alloc_coherent(acm->dev, readsize, GFP_KERNEL, &rb->dma); if (!rb->base) - goto alloc_fail4; + goto err_free_read_urbs; rb->index = i; rb->instance = acm; urb = usb_alloc_urb(0, GFP_KERNEL); if (!urb) - goto alloc_fail4; + goto err_free_read_urbs; urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; urb->transfer_dma = rb->dma; @@ -1417,7 +1417,7 @@ static int acm_probe(struct usb_interface *intf, snd->urb = usb_alloc_urb(0, GFP_KERNEL); if (snd->urb == NULL) - goto alloc_fail5; + goto err_free_write_urbs; if (usb_endpoint_xfer_int(epwrite)) usb_fill_int_urb(snd->urb, usb_dev, acm->out, @@ -1435,7 +1435,7 @@ static int acm_probe(struct usb_interface *intf, i = device_create_file(&intf->dev, &dev_attr_bmCapabilities); if (i < 0) - goto alloc_fail5; + goto err_free_write_urbs; if (h.usb_cdc_country_functional_desc) { /* export the country data */ struct usb_cdc_country_functional_desc * cfd = @@ -1492,7 +1492,7 @@ static int acm_probe(struct usb_interface *intf, &control_interface->dev); if (IS_ERR(tty_dev)) { rv = PTR_ERR(tty_dev); - goto alloc_fail6; + goto err_release_data_interface; } if (quirks & CLEAR_HALT_CONDITIONS) { @@ -1501,7 +1501,8 @@ static int acm_probe(struct usb_interface *intf, } return 0; -alloc_fail6: + +err_release_data_interface: if (!acm->combined_interfaces) { /* Clear driver data so that disconnect() returns early. */ usb_set_intfdata(data_interface, NULL); @@ -1514,21 +1515,21 @@ static int acm_probe(struct usb_interface *intf, &dev_attr_iCountryCodeRelDate); } device_remove_file(&acm->control->dev, &dev_attr_bmCapabilities); -alloc_fail5: +err_free_write_urbs: for (i = 0; i < ACM_NW; i++) usb_free_urb(acm->wb[i].urb); -alloc_fail4: +err_free_read_urbs: for (i = 0; i < num_rx_buf; i++) usb_free_urb(acm->read_urbs[i]); acm_read_buffers_free(acm); usb_free_urb(acm->ctrlurb); -alloc_fail3: +err_free_write_buffers: acm_write_buffers_free(acm); -alloc_fail2: +err_free_ctrl_buffer: usb_free_coherent(usb_dev, ctrlsize, acm->ctrl_buffer, acm->ctrl_dma); -alloc_fail1: +err_put_port: tty_port_put(&acm->port); -alloc_fail: + return rv; } From patchwork Thu Mar 18 15:52:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 405231 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 726A4C43331 for ; Thu, 18 Mar 2021 15:52:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 30D8964F68 for ; Thu, 18 Mar 2021 15:52:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231857AbhCRPwV (ORCPT ); Thu, 18 Mar 2021 11:52:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:54656 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231225AbhCRPwA (ORCPT ); Thu, 18 Mar 2021 11:52:00 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2F9E264F38; Thu, 18 Mar 2021 15:52:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1616082720; bh=invk8uhjFwTQ4535wzfeJv1w5fOcdHfeU/XjQ+K0Ngc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Pv/ODodkYSZgjSCx+NfSNT6vVUQhqyCjq50BqY5PlrrILQpB1l7NTl0a9AYfF/vIV eDf2Su3fEQTv8R2Vr7P9tDjbgtVdtu12Nxail2GhgjPyuf/wN41jCt/kJUNo51RVFv kAdMIitXQm7y6cHGYPzuLAAfzJ0Lgx8tLKW2dFSK4XHNBFMnzfTmebKSu+yXKH+o/M 056khjKa9oz+pQw9r7qeWOm2V/jBmLm78g71dtsv8mAG157Pe2UcSh614y/uK5iYFx 6zBFHzghlQUk2rZs89xs7ktwDAK52eyseD/4g+n/K6sINfslP6ggGvcSz3egHO+r7x 4GWYDziV8T9hQ== Received: from johan by xi.lan with local (Exim 4.93.0.4) (envelope-from ) id 1lMuwc-0005nf-FN; Thu, 18 Mar 2021 16:52:18 +0100 From: Johan Hovold To: Oliver Neukum , Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH 6/7] USB: cdc-acm: use negation for NULL checks Date: Thu, 18 Mar 2021 16:52:01 +0100 Message-Id: <20210318155202.22230-7-johan@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210318155202.22230-1-johan@kernel.org> References: <20210318155202.22230-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Use negation consistently throughout the driver for NULL checks. Signed-off-by: Johan Hovold Acked-by: Oliver Neukum --- drivers/usb/class/cdc-acm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c index e3c45f5880fc..6991ffd66c5d 100644 --- a/drivers/usb/class/cdc-acm.c +++ b/drivers/usb/class/cdc-acm.c @@ -1323,7 +1323,7 @@ static int acm_probe(struct usb_interface *intf, dev_dbg(&intf->dev, "interfaces are valid\n"); acm = kzalloc(sizeof(struct acm), GFP_KERNEL); - if (acm == NULL) + if (!acm) return -ENOMEM; tty_port_init(&acm->port); @@ -1416,7 +1416,7 @@ static int acm_probe(struct usb_interface *intf, struct acm_wb *snd = &(acm->wb[i]); snd->urb = usb_alloc_urb(0, GFP_KERNEL); - if (snd->urb == NULL) + if (!snd->urb) goto err_free_write_urbs; if (usb_endpoint_xfer_int(epwrite)) From patchwork Thu Mar 18 15:52:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 404526 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DB854C432C3 for ; Thu, 18 Mar 2021 15:52:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A36AC64F4D for ; Thu, 18 Mar 2021 15:52:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231908AbhCRPwW (ORCPT ); Thu, 18 Mar 2021 11:52:22 -0400 Received: from mail.kernel.org ([198.145.29.99]:54666 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231648AbhCRPwA (ORCPT ); Thu, 18 Mar 2021 11:52:00 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 35DC564F40; Thu, 18 Mar 2021 15:52:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1616082720; bh=M4E3BvFfJP/+cfDrdryeJREcm4+lpbukXe5ZikaLhv4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MfXzBnl9oEGLOV/1dzcu+MGzrB9X/2r3O509gkDf+QRs7uxLmY+iA7EAKpj/SCzy8 C5CEodM/Wo0LNkRthAMqTd0UbFLFq+1aE/F2Yhw4Vua4qLt/hpxsBXiHGhBFBa2Oqa 62tNuUSk1mEamqVZSUZwdiKdc1Bf7bOlZhX0mBQ25u9GRv1iLyaVptdfwxq7ZBvmXR xGnpiISq4+/fjdgaPOaQwtT2Ey8j59hvWJnIB4XJ4zzcPnyiu6fxH6e8CxKK3huja2 clA1PDlioMmEz8dBpBKfeibUe6hGbx4QosVb0BmZvqx5FizY8uZ9hFDRoRI11ELjsr vqltxk/tbaSkQ== Received: from johan by xi.lan with local (Exim 4.93.0.4) (envelope-from ) id 1lMuwc-0005ni-ID; Thu, 18 Mar 2021 16:52:18 +0100 From: Johan Hovold To: Oliver Neukum , Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH 7/7] USB: cdc-acm: always claim data interface Date: Thu, 18 Mar 2021 16:52:02 +0100 Message-Id: <20210318155202.22230-8-johan@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210318155202.22230-1-johan@kernel.org> References: <20210318155202.22230-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Make sure to always claim the data interface and bail out if it's already bound to another driver or isn't authorised. Signed-off-by: Johan Hovold --- drivers/usb/class/cdc-acm.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c index 6991ffd66c5d..58c444f9db5e 100644 --- a/drivers/usb/class/cdc-acm.c +++ b/drivers/usb/class/cdc-acm.c @@ -1486,7 +1486,11 @@ static int acm_probe(struct usb_interface *intf, acm->line.bDataBits = 8; acm_set_line(acm, &acm->line); - usb_driver_claim_interface(&acm_driver, data_interface, acm); + if (!acm->combined_interfaces) { + rv = usb_driver_claim_interface(&acm_driver, data_interface, acm); + if (rv) + goto err_remove_files; + } tty_dev = tty_port_register_device(&acm->port, acm_tty_driver, minor, &control_interface->dev); @@ -1508,6 +1512,7 @@ static int acm_probe(struct usb_interface *intf, usb_set_intfdata(data_interface, NULL); usb_driver_release_interface(&acm_driver, data_interface); } +err_remove_files: if (acm->country_codes) { device_remove_file(&acm->control->dev, &dev_attr_wCountryCodes);