From patchwork Wed Jun 14 07:32:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 13280114 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4071BEB64D8 for ; Wed, 14 Jun 2023 14:17:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=dBWuYT/pW7TL1Jm6K5pLTYsZbm3faeH8KXljG1h1Evs=; b=i9cDRM/jshFF9I 5YFMwIx+KWdXnePkpNShiRcgC4iRpT3YX0VwERtwMPWreyA5OBm3tNO9iNC21dsfa96Tkxk1+ik1Q InxulH1dVafWWamBNaGYGJOq5aOtuyZSBWK7DJrVnHBGJY2b22lFxln77vKMq3x3VLBd0ypNExczJ ocIAEh6qJwFC5WtAHj6bWYX7RCBcUX3fXX9AFosTXmQJXBltEF3fnOaz9XLP6WbdVwbx4GS4Hc6Du 3bzHO5cDTtWq4gq2kp0kBDsIZqr7zJBWXCFXFBv4ovNCR+fGFrWWxCCTHIfyyRPF72JaSkX8tKaFH 18PZ9FI7Zvn1uJsbma8w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q9RIq-00Bsbm-2I; Wed, 14 Jun 2023 14:16:52 +0000 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1q9RIn-00BsbO-1T for linux-arm-kernel@lists.infradead.org; Wed, 14 Jun 2023 14:16:50 +0000 Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-30c4775d05bso4893006f8f.2 for ; Wed, 14 Jun 2023 07:16:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686752208; x=1689344208; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=zXrtZVNtigeKgJSwA8SW/6hEN8pGZI7BArpmacufnTg=; b=ZvlIhWO+UbdEXvtjkfHV7Na2P16yHMVjdBcJ4rDysGC7/aPhxMv4zaZSiGm/ZhK2td UwCJg/2ARuYuOw3iMAbcyZ+es5K4mrPdWEah974xwoTL51Jj7Z5nu0QlR23j2ZuQDsUJ e8P/44csh3nSZRI+/nZBtYpVh3jCekSF28BWITcHCUTcFvMJJSWpgyZul8+XTPZepgSl zXZZ5vAg+ylHT6Mgpke+nVaAOQuRqhkQwrT458KV0vM0lTORfTeVnTu7HM77N/lJOnVR 3ws8iybDCDLn/yh6cBw11r+FD2XeoxcT9eFPbqlmki5v9CsHchOL4bk7498MqGGoD62s GbcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686752208; x=1689344208; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=zXrtZVNtigeKgJSwA8SW/6hEN8pGZI7BArpmacufnTg=; b=ONWYf/tU2z9qhI1X+93rc9WUhqBd2UT0plLXJd6RvLUSeorwjfc65AdPgNQ7tkRq6p BhjDL1inBqcCjF5LNm5DvsguhL0IzyNcYvibslkbe6HM9S1Uj7r5HsVBobGt27HS4T2e yk/hvASSefDpSQcVKJcCOz6Zjs1VIexYM3gPrwjHIwMWVvS/ETa+5+doafa9K/C7PJau ueAAll4I7YtgeZOdsR1kOu+kmNw1MdXOCjrsUC18XK7iE0y2Lm3uYvvLafTjAZEy+HtP 89e7TdUwtaOsVh4gPX9OSoMEQDX7iS9TTWoQAApZrjCdYLBOYdju/sBqPgiz6SZMIRC8 eejA== X-Gm-Message-State: AC+VfDznHZFeltoj2nCR/6yYafZjmDzw6z/Hmb8cT1cG9ufLOJD/l0bn YZrr2+3Ro6P7mXoociAoHcg= X-Google-Smtp-Source: ACHHUZ7u0M9cZqByWtISOn1h1jPvoZT7oi+IfoTVD0JOaPtyqavnoW4rP3x4WqugXE0GnbkR+7oAuw== X-Received: by 2002:a5d:480f:0:b0:30f:ca3f:64d4 with SMTP id l15-20020a5d480f000000b0030fca3f64d4mr4131734wrq.47.1686752207571; Wed, 14 Jun 2023 07:16:47 -0700 (PDT) Received: from localhost.localdomain (93-34-93-173.ip49.fastwebnet.it. [93.34.93.173]) by smtp.googlemail.com with ESMTPSA id v13-20020adfebcd000000b00309382eb047sm18509045wrn.112.2023.06.14.07.16.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jun 2023 07:16:46 -0700 (PDT) From: Christian Marangi To: Giuseppe Cavallaro , Alexandre Torgue , Jose Abreu , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Maxime Coquelin , Russell King , Christian Marangi , netdev@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Jose Abreu , stable@vger.kernel.org Subject: [net PATCH] net: ethernet: stmicro: stmmac: fix possible memory leak in __stmmac_open Date: Wed, 14 Jun 2023 09:32:41 +0200 Message-Id: <20230614073241.6382-1-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230614_071649_496542_E902A51B X-CRM114-Status: GOOD ( 13.15 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Fix a possible memory leak in __stmmac_open when stmmac_init_phy fails. It's also needed to free everything allocated by stmmac_setup_dma_desc and not just the dma_conf struct. Correctly call free_dma_desc_resources on the new dma_conf passed to __stmmac_open on error. Reported-by: Jose Abreu Fixes: ba39b344e924 ("net: ethernet: stmicro: stmmac: generate stmmac dma conf before open") Signed-off-by: Christian Marangi Cc: stable@vger.kernel.org --- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index fa07b0d50b46..0966ab86fde2 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -3877,10 +3877,10 @@ static int __stmmac_open(struct net_device *dev, stmmac_hw_teardown(dev); init_error: - free_dma_desc_resources(priv, &priv->dma_conf); phylink_disconnect_phy(priv->phylink); init_phy_error: pm_runtime_put(priv->device); + free_dma_desc_resources(priv, dma_conf); return ret; }