Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp69806iof; Sun, 5 Jun 2022 21:24:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyTS3UyC5yPbd3M1lv+AzHTzjTUFGJlkm6kZBlH4sWLB0uLAJdOQvw8JU4IzoVCLvpIORo+ X-Received: by 2002:a63:2b97:0:b0:3fd:231:eba1 with SMTP id r145-20020a632b97000000b003fd0231eba1mr15997826pgr.144.1654489459148; Sun, 05 Jun 2022 21:24:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654489459; cv=none; d=google.com; s=arc-20160816; b=g68OX9yFoFjKdVkA6XVR+STIhhbXUQhLODPkDA/FJ60baXfk0gsxF6T3HVR2q8DdbY GXI7EP1pZlpHHvRQBlg4If0imj7IHtChyIXH7t+UcocHZBSw4dc7/0KAbA9V6jsH0rSV yKsyDxshQmZlpqgetnR8PDroPPXOIcGQw813H8MtcO4rt5qhLvXdTN1MKbT6SDwAJXPR qp8HsN2Q3h+B6AvsrjweOagMykcD913G2cDffBoDlykM0Xf0RMqxKRDYpcvLXyDJCprb DNknoBqR4oS98qgHlct6HZd4eJUPW1WuLyec2Y+qUnv92N6rlQ8qmY12cBIDfbArHhCk VnLQ== 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:to:from:dkim-signature; bh=lEcK3LonWdWGRModNJ64JeNky6+6P88OyA7vjpOXQiU=; b=yyO3RrOxQShZy2kPr3hOSo94idB/pQOlP1A2DYffLmepDsIaJmCoBrZMIwusyJmXHo zEI12K7m3ndu1Kkwy8hDgNaoaerh6XNchxjFIAigpoBeCb45hhsgVaJj/FlhvYMfayfv V8m66DpjmIrZQmhm5zBqnJZQmO3HojMyImbr2iup+uiNw8F/gaxxYC6gq8SBeS0IElEv Pcy/bARRE+K5LYM6gxEmL3vgR5kYIo+cNTfUo7GM4tOAehxMqYgpHHWxyCFTIPgW369L dgdsdfsyKqi1OQ9+6v/DU/0mqainrOEVO1i/jiWGP/NqzZDy2voLMRJS1V46DU3UDTc3 cO6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=eVTIXHX2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id b21-20020a170902d31500b00161f1960b5dsi20293063plc.291.2022.06.05.21.24.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jun 2022 21:24:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=eVTIXHX2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 CCD1A93991; Sun, 5 Jun 2022 20:56:26 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244702AbiFEIPY (ORCPT + 99 others); Sun, 5 Jun 2022 04:15:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244674AbiFEIPW (ORCPT ); Sun, 5 Jun 2022 04:15:22 -0400 Received: from m12-12.163.com (m12-12.163.com [220.181.12.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0C5F627158; Sun, 5 Jun 2022 01:15:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=lEcK3LonWdWGRModNJ 64JeNky6+6P88OyA7vjpOXQiU=; b=eVTIXHX2ua17qlGeaAiWG7ha5+IIY7z3dR O21bfl/gEqY/oD+IjQ0q2X+PPeovrVVmkYN009HZ5NfLOwECP38F5J0Hb5AmSrr7 Vi6uWpT+uUqPTLu3AlXYIE1TFXogZoyCY2qeaTfjnhyWx278L6Zt+OcVpW7x+FD3 ydite3eZY= Received: from localhost.localdomain (unknown [202.112.113.212]) by smtp8 (Coremail) with SMTP id DMCowAAHFRoEZpxiWhXTGA--.25686S4; Sun, 05 Jun 2022 16:15:02 +0800 (CST) From: Xiaohui Zhang To: Xiaohui Zhang , Krzysztof Kozlowski , "David S . Miller" , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/1] nfc: nfcmrvl: Fix memory leak in nfcmrvl_play_deferred Date: Sun, 5 Jun 2022 16:14:55 +0800 Message-Id: <20220605081455.34610-1-ruc_zhangxiaohui@163.com> X-Mailer: git-send-email 2.17.1 X-CM-TRANSID: DMCowAAHFRoEZpxiWhXTGA--.25686S4 X-Coremail-Antispam: 1Uf129KBjvJXoW7KF1kury5JF4rWr17AF4UCFg_yoW8WFWrpr Z8GrWYvrWjgrWSqwsxAwsxua45Jw4xC3yjkr17u343X3WYg3W8GaySqFyfAFykKr1rGw12 vr4jvayrW3Z5Kw7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0piy89_UUUUU= X-Originating-IP: [202.112.113.212] X-CM-SenderInfo: puxfs6pkdqw5xldrx3rl6rljoofrz/1tbiTgYXMFUDPVh78wAAsU 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: xiaohuizhang98 We detected a suspected bug with our code clone detection tool. 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: xiaohuizhang98 --- 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.17.1