Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp6139751iog; Thu, 23 Jun 2022 12:10:21 -0700 (PDT) X-Google-Smtp-Source: AGRyM1v+rr2RYspWnhp+SKPGh4uOYTLDfz8tSdX0xw5yYVXu7JpfrZX5PsR2+Fn/qWKNOABDL2Qd X-Received: by 2002:a05:6a00:cca:b0:51b:ed40:b08a with SMTP id b10-20020a056a000cca00b0051bed40b08amr42403039pfv.19.1656011421244; Thu, 23 Jun 2022 12:10:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656011421; cv=none; d=google.com; s=arc-20160816; b=H5Ws/P7rKcenqcg54dBttCyhTB25B7+ReDJC1KVrf4zhDB0u8P+PO4GIWqnB2J7Ah+ qEhmalfodeD58+KAta9MRkcCh124nBC2sD/QeTYFxa8fLq95lLfHo6rN+LqAQil2As80 CEeWb4b75Kd+Ty+bFK5zS2Wc0OOJlAvj7oc9/jGbFAo3tXkQ9vIVWBRqLucUL6Ej2FhH eRQM0gv7L9TOvCc57tQUGA1m1u/7lNQruZnYVuzCo3grbVp1R0kX0NahMCtHVBrw3+i/ axzjVymUJ+AwsKso3Pm8wTBfDDUc8nJFN3cMtEl177nd6G9KM62Rya2fscfuvSFuzNY9 DyHQ== 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=rnuBxypk1l8NGD+tVUMrDuTvhJvBvJDju07yrf0CpoE=; b=dxXccVyINHsoNHuf8LxB9q0G1UZigSRKBKiVEqk4HJdyAv5xTmXzVH3r7nVcXPVFDk dotWBMpN2Ktssfs07reLKR8B3HH70R5TrvMS6DDwCtYcFPff657u2pgCJ2M59tFnNn70 ARTKH82ooCtXOmG7M+QkM156C+4a00hqCeyA2LvnmoAgLp/Ov/Cm1yQqP/rZOwzQ+x+s yGvyyMmie6J6YuvJlkyBYJBZi5p8Gx4pXXDHDGAp9156X6qIe83xJ2BKS5uPnGzw1pG0 9RlshQzMOSKe6oU92E5lUgnr6UTjkbknTceOO/HowjYJJocaNqYYwQgPTiBghbsJwrHc VAjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=SIYex9kt; 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 b5-20020a1709027e0500b0016a4179aec5si335648plm.361.2022.06.23.12.10.08; Thu, 23 Jun 2022 12:10:21 -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=SIYex9kt; 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 S232067AbiFWRLT (ORCPT + 99 others); Thu, 23 Jun 2022 13:11:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33248 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234119AbiFWRIr (ORCPT ); Thu, 23 Jun 2022 13:08:47 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D079655361; Thu, 23 Jun 2022 09:57:25 -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 713C260FFA; Thu, 23 Jun 2022 16:57:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5E83AC3411B; Thu, 23 Jun 2022 16:57:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1656003424; bh=r8lvdLrTRpr0JO0BJ5yTk+PV/xkIpP+MsXfGHsZLz0I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SIYex9ktTNMzi3Wod2BTZND8kJG2Xb2rhw6/XZ+in/57ZDXZWIZp1+NokJ1fA9Sdq JN4JSYF9GQhnDSVeNHquNtY8ZdkX4oGAV/dux2OsxVEYO8lzL3Dhwr8ZYn9fqNTQvK W6zkj0PHjPIaObaTkt5m9Xy6fM2tk6zMlM8ZkcNQ= 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.9 234/264] nfc: nfcmrvl: Fix memory leak in nfcmrvl_play_deferred Date: Thu, 23 Jun 2022 18:43:47 +0200 Message-Id: <20220623164350.698303931@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220623164344.053938039@linuxfoundation.org> References: <20220623164344.053938039@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 585a0f20835b..3263e2a2bdfd 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