Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp2932609iog; Mon, 20 Jun 2022 07:46:01 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sP7icNa01hcDVDFmVGcbgkaqP6mGRoOja1ataH4yf/vvyNytyuwYRvo58+oqKyFypCjvY2 X-Received: by 2002:a17:90b:17cb:b0:1ec:9d52:46f7 with SMTP id me11-20020a17090b17cb00b001ec9d5246f7mr8808490pjb.221.1655736361192; Mon, 20 Jun 2022 07:46:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655736361; cv=none; d=google.com; s=arc-20160816; b=gkft8cd1Zexr61qaIxsY7BhpDOpUtz+o8YAszBqeLzOI72Yoann3EO68BqkdzSM5Ak r38/JcYBaAaHSOhq5astiPnxj7LT+E+/jHk4m7VWRJMPrstTHAU90xlgrwUfA2nShN1H Dzkm0kK9urSDO0s5qC0irvwrYnerCqz4aJltgBOb24Zr6t+Ojh65Hu1ZQan8nczpu/tS aTkPRZwONnOkfkqStIH4h+Vj7H/Oi74uA8/xm1/NkG4Nw8pLQykR1h9+ml/aqg30q5YD 8WfVt4Y4/gpdSo5whA9j28eut/ksFay0QDJAWic18grdMK3oPF8OauM99jLj5h6+epog 9SlQ== 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=Gk74fizpzqCiyTh2y45Wd3cwSUIlPKVzxpwopED9uWvUbrvbbuw2GzRXW9OnkOay40 n0/kMa4/10vUUASvC9plc7aGH2jkpNaHgCM0aG9751C+TJ+YrLumWDCgOK+YV6rubK4d 58pBcUuYKpufNfyxc7XUKIvtuYcciXGnfzAB09zueOHZUhIrIyVD8aZgYla0TupxtAfE AswdxcnGFa2wADeSewNzW6EXl6a2bOgPKWQ5tR9vDrfDGQivwsfNPylckmhGzL73yPiT btzsCJfBEnLN+7GDratwUEi3ZP6LBYkmeycbTb23zcTDO2eWuefQg2EzUt898ZVLxAhG bGiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=wMTIbS8g; 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 r26-20020a635d1a000000b003fb238f91besi15495623pgb.738.2022.06.20.07.45.47; Mon, 20 Jun 2022 07:46:01 -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=wMTIbS8g; 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 S1350671AbiFTOH0 (ORCPT + 99 others); Mon, 20 Jun 2022 10:07:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45288 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352969AbiFTN5V (ORCPT ); Mon, 20 Jun 2022 09:57:21 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 482C137A13; Mon, 20 Jun 2022 06:23:11 -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 DC12960C8B; Mon, 20 Jun 2022 13:22:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CF1C7C3411B; Mon, 20 Jun 2022 13:22:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655731371; bh=2aLdP/aNbtKqn9jTpTpT0xifj7OJXFEgTqbU/YlfGfc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wMTIbS8giqVEOtTYn5SKlthbeYIGMAROoMQPZMZVufA8FLzs4w69MZKIcZPRytOek x9UEfa5I6EP9q0tPZ1cIr/4PwfDt4+3E16qtXvPqZXQ/AW4cPiM+7eCEZYZdzEHUno ROp+SCzU+3HzXeWqU/3AlN8tcmMhEhH+Tna8bvwA= 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.4 200/240] nfc: nfcmrvl: Fix memory leak in nfcmrvl_play_deferred Date: Mon, 20 Jun 2022 14:51:41 +0200 Message-Id: <20220620124744.778755083@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220620124737.799371052@linuxfoundation.org> References: <20220620124737.799371052@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