Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp6138251iog; Thu, 23 Jun 2022 12:08:38 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uhN3PI/H/vtCZT2q0GY/o4qJ2ha6wZlau8IAOqXT3b9485ULvnn73dRzlbbbrN2ystNpDg X-Received: by 2002:a17:902:c944:b0:16a:3ed0:e60c with SMTP id i4-20020a170902c94400b0016a3ed0e60cmr13095814pla.51.1656011318441; Thu, 23 Jun 2022 12:08:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656011318; cv=none; d=google.com; s=arc-20160816; b=EO4b7RcRnnR7lkX35iMco3/GCkg2cXQI8AbKicMbyrUDPG9UFEcXVi/knvP0kYBFdB 8nNotn/Lf7+0Fu6q0UFy1Nr5ON9SwcnELZ+qmWaRpmUShPxsp+RczM0B83BNvF8eFdbB il772WdgZ0aIQu4tgHvZiDiz3MRBz17LJcqK5Q1JfdDafcXLOasNPfkVO3ZBVKSvVdfJ kQIbb2nt2DE0s3GyXpCpzbOgTdOJvlkw3JCfbxvVWZ7we1uETZ124ICSAcAArnKq0i6u JUr5rIVBNa5la+jeKT807EpNTgdIl/Ve2Gf+Q4BanTa+LVp8r77VFVIP3T85XQlX9hi7 /kjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=dVBH+x8vsg5xaLPGXEG4TzBcDxj0er25QnYs315LCC0=; b=F2Y/2lpX7uSKd7LUCXTbYKaS4mut9vRgFON37izW10HDpqJ1/4Q4zX971gSxa09Vk0 EO4WqtwAzDf/o4SmrOYpv76ESSdjWWJUWDE69E06qft6RP24DXT63w8a9dyGsfw8nehA G1dEp7Em6DS94tBuX2VecVui8akQwS7KQDFw8kr0A9GYcYDzc8MAQHAViyf0mIcWX12N v8kfGh87Dn8d2B70wFbern2TXfqSh26dmDgxUPPbJvJKIiYTNFjJaUpC2ierqbFbMcry c0wyx+QTvG7WfokBC+KmlpKel7qRTEWEW6/q2msHL/5im1Af1KBmiWH980Jv+B0fc4IC fDeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=KywxOXBs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m13-20020a65564d000000b003fba6a7f38esi25536059pgs.603.2022.06.23.12.08.22; Thu, 23 Jun 2022 12:08:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=KywxOXBs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236791AbiFWSQl (ORCPT + 99 others); Thu, 23 Jun 2022 14:16:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236648AbiFWSPr (ORCPT ); Thu, 23 Jun 2022 14:15:47 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 334DE828B3; Thu, 23 Jun 2022 10:22:12 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 9AB7061DC6; Thu, 23 Jun 2022 17:22:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 66FF5C3411B; Thu, 23 Jun 2022 17:22:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1656004930; bh=2aLdP/aNbtKqn9jTpTpT0xifj7OJXFEgTqbU/YlfGfc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KywxOXBshS7LQMGr9lb9wf58ilDZf9MruMEvwpRxaCNEWeLm20e+9Afc64rfVzhIS c/FsS8lCYLDLs8Q2z3GcO+EIFGC/ginPKEEyFwhN8+ZM/Yqj17jKxQ2VMjSVPvbflr YDJK35rvaN2kgOENnABuIL4c8XzBUZvPb4riwufA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xiaohui Zhang , Krzysztof Kozlowski , Jakub Kicinski , Sasha Levin Subject: [PATCH 4.19 195/234] nfc: nfcmrvl: Fix memory leak in nfcmrvl_play_deferred Date: Thu, 23 Jun 2022 18:44:22 +0200 Message-Id: <20220623164348.566309060@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220623164343.042598055@linuxfoundation.org> References: <20220623164343.042598055@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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: 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 888e298f610b..f26986eb53f1 100644 --- a/drivers/nfc/nfcmrvl/usb.c +++ b/drivers/nfc/nfcmrvl/usb.c @@ -401,13 +401,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