Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp2932723iog; Mon, 20 Jun 2022 07:46:07 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tn6UHF8eGD/LoI1eCcTAdklTpwmMmpc2cQma8G8guIwDlSqtqHQPdtQvOZXR8Yz5mVYknE X-Received: by 2002:a17:90a:560b:b0:1ec:75f3:1f8d with SMTP id r11-20020a17090a560b00b001ec75f31f8dmr20471996pjf.95.1655736367242; Mon, 20 Jun 2022 07:46:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655736367; cv=none; d=google.com; s=arc-20160816; b=sSZKxIRWwFXuTSxVuJUWiaKevfjGVSuYnd7PULUpv2dZBKLKCVd401sKFSM6m0BkDB iraelZEyQKjfoRSE66FAxjaemSEVV2YVLiQOWB/FcDMn6rkCGZmRo646fqyVl/quKr/J ujlVzHVArHFznBQtwETakYwIX+OAARtXhn4OTuxg5C35KrCqW+y4kXBFyEI+VxEmPfTX EeZ1AnoROF3zdyGfCnjgB4WqBVQDTfWgzL30VojI/5E6daE8gANvr4DT8zYF/E4jJo9q MVXlk+U+G4s7SJOl3CvQRqQL6TRYlGcxWt8mmMTTSqnB3HS6puIQmV7Fyz8ksOVR1g7B X/Eg== 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=XYNHuz+K5/QOV6E6drrPhEiiHvhY5UBfPXV0U3+btPo=; b=YhIA1M8DLZtMzqTe5XstVlEB0jou3QF2WlZ5w6uW87S1Of2lqS9FPkXBVGlQ4m3+ra YuhLvvWMmEluJPmo1+TDVpiC+8IvQaYKpvtYUTl6XAm+tFdxB+fq6PIaoXIH1VvjoKbB XVguyGbw3MJFEr4usGkO6nPZlgiAkF2iUUNTmXFUmJzf5knmrDt57/Ksg+MpOqiYjFYI +I2YF1YYcpZJsTCjDQXRdCwrW6s1T9uirgAbNArg8bCCsquQ+utZqBiXe3Jey48+T9jv lIwnlkbuctUJPyvkBuf1r3WvyGmwpUIvmOrgj/4iyj8TVF/1YGH0q78IcQThuHYySKFo Tv4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=uyDJgfRb; 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 83-20020a630056000000b0040c7cbadecfsi8842571pga.692.2022.06.20.07.45.54; Mon, 20 Jun 2022 07:46:07 -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=uyDJgfRb; 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 S243329AbiFTMzg (ORCPT + 99 others); Mon, 20 Jun 2022 08:55:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243243AbiFTMzB (ORCPT ); Mon, 20 Jun 2022 08:55:01 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1942919286; Mon, 20 Jun 2022 05:54:28 -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 C85D1B811A2; Mon, 20 Jun 2022 12:54:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7E16FC3411B; Mon, 20 Jun 2022 12:54:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655729665; bh=WVB2cZoIsM8ti2+D/PLRAPxWV297NPg1wTNvLUzUnTo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uyDJgfRbDA55USfZTtuqmWKdVXxiyJkQrz3SpRNdg6f0arf6MfQiz1EeD6QkGLlOI OPCrZsw+v8KBYIkOQm44I6Hz2GRB2SDq+h2dmEYvr3vthG0Jy2BtMYm9VD/TA4MhU8 UmgoDEg3MU87kDjjj6yTUbXpaq5wdx+gA7XT0wL0= 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 5.18 036/141] nfc: nfcmrvl: Fix memory leak in nfcmrvl_play_deferred Date: Mon, 20 Jun 2022 14:49:34 +0200 Message-Id: <20220620124730.601716595@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220620124729.509745706@linuxfoundation.org> References: <20220620124729.509745706@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 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