From patchwork Mon Mar 22 15:53:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 12155195 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=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 841D8C433E1 for ; Mon, 22 Mar 2021 15:53:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 573BF61924 for ; Mon, 22 Mar 2021 15:53:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230142AbhCVPxT (ORCPT ); Mon, 22 Mar 2021 11:53:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:49034 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230401AbhCVPxP (ORCPT ); Mon, 22 Mar 2021 11:53:15 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id BA01D619AB; Mon, 22 Mar 2021 15:53:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1616428394; bh=iahYK4r7WtNOdjL/Bg1oM/WoYw/NIOXasi54gp8KbEQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Q2sJ7slOeIHlf3Q8GdYebQNBIiz8WkOMIYxta7kN3IgOWQD9AVjhaSEpowsbSHW4t BAnmOlKCt+GZRle1GLEy+DbP4+eEDWUChRNmQSf4VfVRRU6VARgZOzomWsVTMmx5z8 yNG0lOMFoNT2UZ5vIhu+CqFB8e+AJ7vb1v9wTMtSILBcywhbiXar0TP19M16ttLZZm evVYGqFjiZApflVk6GYa/hX6qsY+UCb3U77LdMzHo0mklDgMblLCJfMyHCS+ojLl0h 2Cz6i3wY7RKHxzOsiOG865+JJTbc9uK+WDyU52jm6vZR8tIjGlEu9nEUQANEHwtJZU uEaelfClbCqFA== Received: from johan by xi.lan with local (Exim 4.93.0.4) (envelope-from ) id 1lOMs0-0002ZY-IJ; Mon, 22 Mar 2021 16:53:32 +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 v2 1/8] USB: cdc-acm: fix double free on probe failure Date: Mon, 22 Mar 2021 16:53:11 +0100 Message-Id: <20210322155318.9837-2-johan@kernel.org> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210322155318.9837-1-johan@kernel.org> References: <20210322155318.9837-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 Acked-by: Oliver Neukum Signed-off-by: Johan Hovold --- 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 Mon Mar 22 15:53:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 12155197 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=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 93A80C433E2 for ; Mon, 22 Mar 2021 15:53:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7CB2D6187E for ; Mon, 22 Mar 2021 15:53:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231175AbhCVPxU (ORCPT ); Mon, 22 Mar 2021 11:53:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:49030 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230385AbhCVPxP (ORCPT ); Mon, 22 Mar 2021 11:53:15 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id B48DB6199F; Mon, 22 Mar 2021 15:53:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1616428394; bh=+Zhc0a9ydorofyGsDShMu+wWptgazNqMAEcHASrxkjc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AIFuHItZDUfQfbKDQN0PRbJrOiU/izGVQyMW3LpNgkvvtshaovfwv33tg3BwpfuTY OEpk/hDoS/JJh0jOMRzOANFWMyREMG2UqJHlsO2pRphqog5C6SqObl9YQPJz5tNwxp SikATzOhA+kTjvX2HS2yyoKXk6uQH1OHEq2IwRb6TG1PvbbO5eXEnGMe+j+TtTuSHA j7E77jKrSm4oYG232aP0p+XwnXhwvNKgThNICffP/lpxv//wvHJENs6cK2oABfTFSf CJWlNkE/wxa1TCCr0G0mfnx8KmlvmDuzwEbZmFp40Dm/fkqEa3t7UfpavJzknnjd7D X41gUPuFyA7PQ== Received: from johan by xi.lan with local (Exim 4.93.0.4) (envelope-from ) id 1lOMs0-0002Za-Lk; Mon, 22 Mar 2021 16:53:32 +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 v2 2/8] USB: cdc-acm: fix use-after-free after probe failure Date: Mon, 22 Mar 2021 16:53:12 +0100 Message-Id: <20210322155318.9837-3-johan@kernel.org> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210322155318.9837-1-johan@kernel.org> References: <20210322155318.9837-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 Acked-by: Oliver Neukum Signed-off-by: Johan Hovold --- 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 Mon Mar 22 15:53:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 12155201 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=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 DF079C433E9 for ; Mon, 22 Mar 2021 15:53:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C367961924 for ; Mon, 22 Mar 2021 15:53:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231312AbhCVPxW (ORCPT ); Mon, 22 Mar 2021 11:53:22 -0400 Received: from mail.kernel.org ([198.145.29.99]:49036 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230445AbhCVPxP (ORCPT ); Mon, 22 Mar 2021 11:53:15 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id BCFDD619AC; Mon, 22 Mar 2021 15:53:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1616428394; bh=p9/L/RnAIz9Ft9DWD/UAt/UImgrzNAZ5kXDabwhbbog=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AmDLfz0sAimC9K9jL5nqrYcoHNwbihdyfFW5tatowRlsZqw4ISqRLX4RLbM87dnE5 BMRNGtMVfbtSC+ffOx432iXgPLhE06CdnDYzmWpsFbd3wVNV3gbu7C8zPv95XOzow9 KPsWNd097AC84UN1mXT+JbiLw75g6TFneGIEtOnrD2XSfFCMzAfimd/QskQeHxDpa5 Bc8ZmNuxKKy1yNxHhoMGsl3xQOONcMHLCh++Fx88oz+4/PEks1czur6o89S52w0q81 ePNuIsPOZ3IsY9yhl6ymGwoaKmRXAu9Z/4QLwwlLnqJY/zTFtY++e1ZdccKMeqUUpc PePccX4LNpoNQ== Received: from johan by xi.lan with local (Exim 4.93.0.4) (envelope-from ) id 1lOMs0-0002Zd-PN; Mon, 22 Mar 2021 16:53:32 +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 v2 3/8] USB: cdc-acm: drop redundant driver-data assignment Date: Mon, 22 Mar 2021 16:53:13 +0100 Message-Id: <20210322155318.9837-4-johan@kernel.org> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210322155318.9837-1-johan@kernel.org> References: <20210322155318.9837-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. Acked-by: Oliver Neukum Signed-off-by: Johan Hovold --- 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 Mon Mar 22 15:53:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 12155205 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=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 135EEC433EA for ; Mon, 22 Mar 2021 15:53:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id ECD586199F for ; Mon, 22 Mar 2021 15:53:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231334AbhCVPxY (ORCPT ); Mon, 22 Mar 2021 11:53:24 -0400 Received: from mail.kernel.org ([198.145.29.99]:49020 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230240AbhCVPxP (ORCPT ); Mon, 22 Mar 2021 11:53:15 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id B77D3619AA; Mon, 22 Mar 2021 15:53:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1616428394; bh=amt4EOUNrN/3n/C6UUQwCgfx7XJdgceD5wYMZTIbcm4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fHclThhD9o4ZFHtkNc7Mn1LGuR7y0Dod/DzEJc+AEmrhPH0ij8zF0brGz9JNCGux1 75R1ksXtQfKXo/KnGJN37WpgsvfB3lSPEjHQCCxy698/G5M32XrFrgl1x+Q3ZssjR0 C4S5v5yvNE6rGmjkSWf1EQcLWL/UVQsLkwXASlpmcA/tx/bQ4IvR5iOF5e3BqVmM2o KLGfXVtx55zwcqp1DwU+JY2mex71Z9UPDKTh6kjZY/xRnSOVZc0FhXselSSLWTdQx7 ZsKTaekftNJBtU1ikbY/FuO0gJLPp5b4SdrOVpDHvHOKGGqtuta+jJIhWY11MFzVQq XjTsDdOcLo7nA== Received: from johan by xi.lan with local (Exim 4.93.0.4) (envelope-from ) id 1lOMs0-0002Zf-SO; Mon, 22 Mar 2021 16:53:32 +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 v2 4/8] USB: cdc-acm: drop redundant driver-data reset Date: Mon, 22 Mar 2021 16:53:14 +0100 Message-Id: <20210322155318.9837-5-johan@kernel.org> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210322155318.9837-1-johan@kernel.org> References: <20210322155318.9837-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). Acked-by: Oliver Neukum Signed-off-by: Johan Hovold --- 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 Mon Mar 22 15:53:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 12155207 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=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 4238CC433F1 for ; Mon, 22 Mar 2021 15:53:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 300FC6199E for ; Mon, 22 Mar 2021 15:53:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231366AbhCVPx0 (ORCPT ); Mon, 22 Mar 2021 11:53:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:49074 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230460AbhCVPxQ (ORCPT ); Mon, 22 Mar 2021 11:53:16 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id C250F619B1; Mon, 22 Mar 2021 15:53:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1616428394; bh=QzFnCyWYsPFGWW84RHeLi1FJ/mRqnIThg/6zCYz66Ls=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Q8OzWDEFFirAQnnssmRs8JrJRbBuatA+YIX0DR/uOsEWuTkTKkDTk0cv2Dxt68qhF 9RAQUmT+9b9kKf592F6I4yKijW31NUUxf/zHJb7yQ1gvBuDgMFMm2VjryA9mkqYIQ5 HbsTd3ISlxDlfc1MPYlc8gOPQ5xsxhjODBgYcP1eeGLMzkbbvHV2NMRHFpR//ZWsEq oKMK+HozKzhL8xDng1bNVGfqW826tTNTxhHr3tOU6UILZ2ifAoAJDUroW3P90R4uxs yUUz5TMkl/DanMnSYeE9DbwzA+r+egANeXkKaT7uQAf0qL/coLoiu5OfHRaDcuy3by VHEO4u8ULEYCg== Received: from johan by xi.lan with local (Exim 4.93.0.4) (envelope-from ) id 1lOMs0-0002Zk-VA; Mon, 22 Mar 2021 16:53:32 +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 v2 5/8] USB: cdc-acm: clean up probe error labels Date: Mon, 22 Mar 2021 16:53:15 +0100 Message-Id: <20210322155318.9837-6-johan@kernel.org> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210322155318.9837-1-johan@kernel.org> References: <20210322155318.9837-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). Acked-by: Oliver Neukum Signed-off-by: Johan Hovold --- 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 Mon Mar 22 15:53:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 12155209 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=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 5684FC433ED for ; Mon, 22 Mar 2021 15:53:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4178A6192E for ; Mon, 22 Mar 2021 15:53:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231376AbhCVPx2 (ORCPT ); Mon, 22 Mar 2021 11:53:28 -0400 Received: from mail.kernel.org ([198.145.29.99]:49076 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230450AbhCVPxQ (ORCPT ); Mon, 22 Mar 2021 11:53:16 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id BFB93619AD; Mon, 22 Mar 2021 15:53:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1616428394; bh=VZ6mpIEVz/dYilkRg2l19PXHpiyaBPX/Ce0HWBs7Zwo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=I/zFRrZEZRZojLWcfZI5UhPw5GkYeL2P09Bq4fnQKiQME9XMzpR3ZVsyFA800/awi IMSfr34jZaCeyYarutOqUv60jaCY0j6TOUmlDq5BZjnFHTVrX+pY7dWyQDZyGz1E5W 3aeVe8U2x6aENhnuDkyFUc3VXP5ZnrfiM4l9auF+dGx3XBEFfvOyphLKE402tuCri5 0CdjyoRhhp9MsRzULtZ+PaKXixMOqRh5EWUGFkM5cH75jGOR7ci2NG2RSZCmsb9tvJ A8jRgp8J8redtN0vMhA0ZGuAyWuZ9CZduNux9iNlsE2JzuAoQ+C3hhose1G0ZgBAQd BaLMnXE1DBfDQ== Received: from johan by xi.lan with local (Exim 4.93.0.4) (envelope-from ) id 1lOMs1-0002Zn-1s; Mon, 22 Mar 2021 16:53:33 +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 v2 6/8] USB: cdc-acm: use negation for NULL checks Date: Mon, 22 Mar 2021 16:53:16 +0100 Message-Id: <20210322155318.9837-7-johan@kernel.org> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210322155318.9837-1-johan@kernel.org> References: <20210322155318.9837-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. Acked-by: Oliver Neukum Signed-off-by: Johan Hovold --- 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 Mon Mar 22 15:53:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 12155211 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 A0575C433F2 for ; Mon, 22 Mar 2021 15:53:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7BD506186A for ; Mon, 22 Mar 2021 15:53:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231384AbhCVPxd (ORCPT ); Mon, 22 Mar 2021 11:53:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:49078 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230470AbhCVPxQ (ORCPT ); Mon, 22 Mar 2021 11:53:16 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D4C18619B2; Mon, 22 Mar 2021 15:53:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1616428395; bh=m9RkJRpOqNy6mEIOmx0QNTVYF98YnapfldKqE/duUTU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dxXhSBstpwr3VjWNoywqxoziDh/NfCjfK1C/+6mMJEp5aIQaFSrhys/xM1VX9e4EQ v6AAUyDsBiHN0YyNbUZULSn/9VavVm7wwIklJBlxgnvchvbniAdGHaLa0Q6heovcpw sF8p92G5GTs8ztDjtzqel9EQFK4BZbUW+OzHcRVo4da58HtktZgWTCwaZgzDtNN4mU VmrL1zgbJa7iQP2fVy9cCtJeoPgT6NRayvBcnQVTX1dIoJnTZNph9kfPwBVkFiMWQ/ AYfHF/kYy4OYh2cwDFYoAL1ACyN6Idtm2XbPPG306BMUqljNXDErQ651f6uUi7s90u Uw8anSRB9m/Lw== Received: from johan by xi.lan with local (Exim 4.93.0.4) (envelope-from ) id 1lOMs1-0002Zq-4d; Mon, 22 Mar 2021 16:53:33 +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 v2 7/8] USB: cdc-acm: always claim data interface Date: Mon, 22 Mar 2021 16:53:17 +0100 Message-Id: <20210322155318.9837-8-johan@kernel.org> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210322155318.9837-1-johan@kernel.org> References: <20210322155318.9837-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 binding fails. Note that the driver had a check to verify that the data interface was not already bound to a driver but would not detect other failures (e.g. if the interface was not authorised). Signed-off-by: Johan Hovold --- drivers/usb/class/cdc-acm.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c index 6991ffd66c5d..914486d0f68c 100644 --- a/drivers/usb/class/cdc-acm.c +++ b/drivers/usb/class/cdc-acm.c @@ -1296,13 +1296,6 @@ static int acm_probe(struct usb_interface *intf, if (!combined_interfaces && intf != control_interface) return -ENODEV; - if (!combined_interfaces && usb_interface_claimed(data_interface)) { - /* valid in this context */ - dev_dbg(&intf->dev, "The data interface isn't available\n"); - return -EBUSY; - } - - if (data_interface->cur_altsetting->desc.bNumEndpoints < 2 || control_interface->cur_altsetting->desc.bNumEndpoints == 0) return -EINVAL; @@ -1486,7 +1479,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 +1505,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); From patchwork Mon Mar 22 15:53:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 12155203 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 23CFBC433EC for ; Mon, 22 Mar 2021 15:53:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0C9E46199E for ; Mon, 22 Mar 2021 15:53:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231352AbhCVPxZ (ORCPT ); Mon, 22 Mar 2021 11:53:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:49084 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230509AbhCVPxQ (ORCPT ); Mon, 22 Mar 2021 11:53:16 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id E539A619B4; Mon, 22 Mar 2021 15:53:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1616428395; bh=s3XS9YGp3yirmpuzyX0/v+esTxrw11dcDwqSBc2f1fY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=f770zkeQAXn33pPTlotkaYXR4dq3UoNrBGol822TLNfm6QcyN3KeZKONRU7Gf6kML sA9nY0EeqoqtVyOIG5sSbPtbTo9om/rkF9aYBd8KsWXnQE9/N4UHWtCu55SjdpGghz 4PmhFn+OBk0WB3C+g24C4eJJCUX53B39QCXKL94Crdi1/jTGmwnkuVwDcL4UvnJtU2 zrsGjz6dLMepMmv+Rtdj3m61m5/a3M/KcAsCeif7rLLa9+H1PgyaXc5J7ArKN812Mr JuiDuHZUXI5jxWdp5LbPZKWR88NlJmmRgLXB4KVnARtrCDutZRUY5RwEGuHV6Oc3BT 9SERgoBbUuylg== Received: from johan by xi.lan with local (Exim 4.93.0.4) (envelope-from ) id 1lOMs1-0002Zt-7f; Mon, 22 Mar 2021 16:53:33 +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 v2 8/8] USB: cdc-acm: do not log successful probe on later errors Date: Mon, 22 Mar 2021 16:53:18 +0100 Message-Id: <20210322155318.9837-9-johan@kernel.org> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210322155318.9837-1-johan@kernel.org> References: <20210322155318.9837-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Do not log the successful-probe message until the tty device has been registered. Signed-off-by: Johan Hovold --- 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 914486d0f68c..337ffced9c40 100644 --- a/drivers/usb/class/cdc-acm.c +++ b/drivers/usb/class/cdc-acm.c @@ -1473,8 +1473,6 @@ static int acm_probe(struct usb_interface *intf, acm->nb_index = 0; acm->nb_size = 0; - dev_info(&intf->dev, "ttyACM%d: USB ACM device\n", minor); - acm->line.dwDTERate = cpu_to_le32(9600); acm->line.bDataBits = 8; acm_set_line(acm, &acm->line); @@ -1497,6 +1495,8 @@ static int acm_probe(struct usb_interface *intf, usb_clear_halt(usb_dev, acm->out); } + dev_info(&intf->dev, "ttyACM%d: USB ACM device\n", minor); + return 0; err_release_data_interface: