From patchwork Fri Jun 3 16:31:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiaohui Zhang X-Patchwork-Id: 12869208 X-Patchwork-Delegate: kuba@kernel.org 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 3DF94C43334 for ; Fri, 3 Jun 2022 16:32:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343951AbiFCQc0 (ORCPT ); Fri, 3 Jun 2022 12:32:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343938AbiFCQcV (ORCPT ); Fri, 3 Jun 2022 12:32:21 -0400 Received: from m12-11.163.com (m12-11.163.com [220.181.12.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B29F633EB3; Fri, 3 Jun 2022 09:32:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=UbU9S6Rop7ic3pmKN4 Lz4yzIPUYdBXjItpANyNVVeb8=; b=Op/8GgX4M/t952BNr+YAq6LGzXkkQw6lOh bCY6a2zLRKaDBfcZjweBo5cWiJybFpbW/cL0ImuQxa5hk+UbSUmtrxdcaYSYmYhn 5PmM7MEzg487/ZeJGVgS0i9P/qu1LQmmP+xaywB698lnMoamlDYBv12JY4Z8NmPp CLcBj1OVg= Received: from localhost.localdomain (unknown [202.112.113.212]) by smtp7 (Coremail) with SMTP id C8CowAAnr5ZiN5pisngmGA--.49354S4; Sat, 04 Jun 2022 00:31:38 +0800 (CST) From: Xiaohui Zhang To: Xiaohui Zhang , Krzysztof Kozlowski , "David S . Miller" , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: hifoolno <553441439@qq.com> Subject: [PATCH 1/1] nfc: nfcmrvl: Fix memory leak in nfcmrvl_play_deferred Date: Sat, 4 Jun 2022 00:31:27 +0800 Message-Id: <20220603163127.4994-1-ruc_zhangxiaohui@163.com> X-Mailer: git-send-email 2.17.1 X-CM-TRANSID: C8CowAAnr5ZiN5pisngmGA--.49354S4 X-Coremail-Antispam: 1Uf129KBjvJXoW7ArWDJry7Kw4fGFyxKF45Jrb_yoW8XF4Upr Z8GryYvrykKrWaqr13Arsxua45Jw4xC3yjkF1xu343Xa45Kay8KayxtF13AFZ5Kr4rGw12 vFsFvay5W3WrK3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zKiihhUUUUU= X-Originating-IP: [202.112.113.212] X-CM-SenderInfo: puxfs6pkdqw5xldrx3rl6rljoofrz/1tbiYwoVMFaEIyukDAAAs+ Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: hifoolno <553441439@qq.com> 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: hifoolno <553441439@qq.com> --- drivers/nfc/nfcmrvl/usb.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/drivers/nfc/nfcmrvl/usb.c b/drivers/nfc/nfcmrvl/usb.c index a99aedff795d..815255b8d72e 100644 --- a/drivers/nfc/nfcmrvl/usb.c +++ b/drivers/nfc/nfcmrvl/usb.c @@ -388,13 +388,27 @@ 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) { + if (err != -EPERM && err != -ENODEV) + BT_ERR("%s urb %p submission failed (%d)", + drv_data->hdev->name, urb, -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)