Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp91034iof; Sun, 5 Jun 2022 22:04:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxEalPXD8Q+wr3NdJwLPvOC5S3UIRaqoMotb64qPwLgRX+OgCUzkSww5NM6RN28S5/BzPXV X-Received: by 2002:a05:6a00:2402:b0:4e1:46ca:68bd with SMTP id z2-20020a056a00240200b004e146ca68bdmr22387151pfh.70.1654491897167; Sun, 05 Jun 2022 22:04:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654491897; cv=none; d=google.com; s=arc-20160816; b=J2JWm9fBQ4bbQHoSrjzEpI6Y9iulizj0StFkQovF50VLDluL2SBq+4wTX2oFs50m+6 XuSk0oxaXc5pnj/7Tx5LNtDgo651PDfPJ7Fme9d0yBflz70rZUjFUNUffGbyAtRMkKkR txDsRwrBRPbu+zS8juRfa0H8yoRf+V5Hr6Ch14RIVTQ0sX1sC8GDTBJJLUVi0i2keRVN 90RHsJ4j5to84KzKGGMsdm5kp2FL18/jCVdh0Rw4YXWeoVex5XrcpEJQ+5i0clYL4juY wGtYLvU6XTWDPx5vwuz9FZBECB4LitK7xudR4GgXHJzpnwzglDpNDJKedKoElysIzc2O WhGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from :dkim-signature; bh=UbU9S6Rop7ic3pmKN4Lz4yzIPUYdBXjItpANyNVVeb8=; b=n1nZMPKqS55586DgVtKi/SzfJJC4BAlmzTTv7L6rjNUUcYqEjjRdn7qXgQF2p3i6It aajfYMUhQfw7Z/dVXMJT39ml4Y2E6U6H/py1dlhLAPm0yH5cqiUP8JKLS0dREt3tZRmj OyVBuH6R+lcQ/MDzrT1wI3cdSD3uySzWOUsJKK0sQ126w6IAhd6vQVK0B/ETpzlFkpc0 W4LJAj07LkT7HVcgTPYVjf5NnwbgJhCeCAjZmSYSkeVAOpjd+PoqLdLim4DqGUk/H+Ib lK046OPWz7bJRsTBv9mQRf+bmsT+yVrz4mdkxH3DScyORz7A/yFi7XMyyeCedlLrVUi3 tcew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b="Op/8GgX4"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id d11-20020a170902cecb00b0015f3d889431si22212899plg.446.2022.06.05.22.04.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jun 2022 22:04:57 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b="Op/8GgX4"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id DCF5A11905E; Sun, 5 Jun 2022 21:13:47 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343954AbiFCQc0 (ORCPT + 99 others); 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+ X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.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) -- 2.17.1