From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2D643CCA47B for ; Tue, 14 Jun 2022 02:11:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352908AbiFNCLU (ORCPT ); Mon, 13 Jun 2022 22:11:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54734 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352605AbiFNCK0 (ORCPT ); Mon, 13 Jun 2022 22:10:26 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 86A2536E24; Mon, 13 Jun 2022 19:06:47 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 2B208B8168A; Tue, 14 Jun 2022 02:06:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CC74CC34114; Tue, 14 Jun 2022 02:06:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1655172405; bh=WVB2cZoIsM8ti2+D/PLRAPxWV297NPg1wTNvLUzUnTo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FC9WJ6Kn2g7N5exSQWpCsbYnHIltof/9LBmDuC/gUjwE26ntXlLpCyK9NQVPFb3zf uaJirIJBl5ZG0VMq++repb2x5bZmsnnW0ToEvGOWEW0lZaxeG6TUyT3UPS+m8IkbS7 1A/HY4+3pa+4jIrWExuDWhzoBcwFRjSofJdPWKc/NzmZzyFn97upy9UVVhCppazXdS UsW3wp4UJKxBpJ7rEmBvljYncXX5o9HbbuCiBH1OgTu9EgVaG6CTQUV1P/gQPEBFFa F0eOEWWR9x9DUzsl7KtUxlzIKkJIcgN9NUwPwSz8GVle2fcFiHZWFv8MZ2cgmZr7Rb f81l2zOAjZmtA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Xiaohui Zhang , Krzysztof Kozlowski , Jakub Kicinski , Sasha Levin , lauro.venancio@openbossa.org, aloisio.almeida@openbossa.org, sameo@linux.intel.com, linux-wireless@vger.kernel.org Subject: [PATCH AUTOSEL 5.17 29/43] nfc: nfcmrvl: Fix memory leak in nfcmrvl_play_deferred Date: Mon, 13 Jun 2022 22:05:48 -0400 Message-Id: <20220614020602.1098943-29-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220614020602.1098943-1-sashal@kernel.org> References: <20220614020602.1098943-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Xiaohui Zhang [ Upstream commit 8a4d480702b71184fabcf379b80bf7539716752e ] Similar to the handling of play_deferred in commit 19cfe912c37b ("Bluetooth: btusb: Fix memory leak in play_deferred"), we thought a patch might be needed here as well. Currently usb_submit_urb is called directly to submit deferred tx urbs after unanchor them. So the usb_giveback_urb_bh would failed to unref it in usb_unanchor_urb and cause memory leak. Put those urbs in tx_anchor to avoid the leak, and also fix the error handling. Signed-off-by: Xiaohui Zhang Acked-by: Krzysztof Kozlowski Link: https://lore.kernel.org/r/20220607083230.6182-1-xiaohuizhang@ruc.edu.cn Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- drivers/nfc/nfcmrvl/usb.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/drivers/nfc/nfcmrvl/usb.c b/drivers/nfc/nfcmrvl/usb.c index a99aedff795d..ea7309453096 100644 --- a/drivers/nfc/nfcmrvl/usb.c +++ b/drivers/nfc/nfcmrvl/usb.c @@ -388,13 +388,25 @@ static void nfcmrvl_play_deferred(struct nfcmrvl_usb_drv_data *drv_data) int err; while ((urb = usb_get_from_anchor(&drv_data->deferred))) { + usb_anchor_urb(urb, &drv_data->tx_anchor); + err = usb_submit_urb(urb, GFP_ATOMIC); - if (err) + if (err) { + kfree(urb->setup_packet); + usb_unanchor_urb(urb); + usb_free_urb(urb); break; + } drv_data->tx_in_flight++; + usb_free_urb(urb); + } + + /* Cleanup the rest deferred urbs. */ + while ((urb = usb_get_from_anchor(&drv_data->deferred))) { + kfree(urb->setup_packet); + usb_free_urb(urb); } - usb_scuttle_anchored_urbs(&drv_data->deferred); } static int nfcmrvl_resume(struct usb_interface *intf) -- 2.35.1