Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2673478pxj; Mon, 31 May 2021 07:59:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy+GW+xfoeX5jDEEzVA0E496MCd++PQGBJdv2DOYz1wqNlmYbQkaANFpvolfx27xVLqScW1 X-Received: by 2002:a5d:8147:: with SMTP id f7mr17295923ioo.135.1622473146519; Mon, 31 May 2021 07:59:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622473146; cv=none; d=google.com; s=arc-20160816; b=0ef9KXT9hp5D3aBiL1e55V06UWghq3MOw6w9grWAVuAdzT6Wm6MXnqvkQ6KQ2dR2Ks 1wuMcEEGm0ei3GPjIwO4eKyZA8vFkiNsJDj5jkA7CtyqvSI7ZSOuqnol/XTWBzArNnTH GYvzXbY6PHhBZOfWx3dyAKcQQoyE1i/1TsAaykIvlhOQG7z05b8koSZAQ3JZqsKHwEdV xWO+a5W4OH0qjlUH1rDWHNZ67tsi1w8WoXpKvfG4lTS0f5oNO41HrGTfDt5M/8W8/8eH qJ/DeA8MPax+dovUtGsB1y4MX+JA1oleKPEGGzOhAjb/Ipnl6QQTy3n/UNX+n3UdyNV6 wSdw== 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=WsFwIbdZTLRJq28pHSawgKWVl1VabtNlLDk2YsZTcUc=; b=Wl29safSngCYc9JA6eJDlYoiijF352x/EHxLGaAbLTvHN1tMzfxs++aEkFLcaT8ItU hpgB01hy7av1s/R0ujZYfZKm4i1E9ezogmG294dKOHdEzKASFOdnmd37N7iR/s7+d+uj SYj0n34KI4AKWxHVKno+l2p4MzfLqpC6B3d/qVuZkZFHfmIAhfArS6GfFJugCGeff22K AArXCXFADqrPlieYkAB04t8j/k6tVtMywFWQaw25AbPOw9C74iLZSzRzE3GaYn5Ws1/H /wSyiYX/dLyDrQ4SslEoWni09yVORFQZTY82iUHcf+RHkzDfzMA2Yxp61bTlhYV9MjN6 HjdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ISkvwxML; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t19si12906494iog.66.2021.05.31.07.58.53; Mon, 31 May 2021 07:59:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ISkvwxML; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S234390AbhEaO7X (ORCPT + 99 others); Mon, 31 May 2021 10:59:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:36984 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232561AbhEaOFb (ORCPT ); Mon, 31 May 2021 10:05:31 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4A2D661960; Mon, 31 May 2021 13:38:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622468320; bh=ROmstazyoaFNN3theMl0eig7ltzXRdcQMLKvT3gtATw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ISkvwxMLAKdhf5XGIDJiXFV9c/0NyVS4cy5l7ca3QrZN89uBYOQd/rjK9LVF88gTs WEMAn5fFasLiNyXSgf0fV6gmpTtlcT2zEnpODUYsv3kLq2WsgQsIwDnWQ6h4YCesaw UN8SsVwFirvHH0cGNoSI2EzqImJF/5eyKsNiazAc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Fugang Duan , Joakim Zhang , "David S. Miller" , Sasha Levin Subject: [PATCH 5.10 200/252] net: fec: fix the potential memory leak in fec_enet_init() Date: Mon, 31 May 2021 15:14:25 +0200 Message-Id: <20210531130704.811954649@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130657.971257589@linuxfoundation.org> References: <20210531130657.971257589@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Fugang Duan [ Upstream commit 619fee9eb13b5d29e4267cb394645608088c28a8 ] If the memory allocated for cbd_base is failed, it should free the memory allocated for the queues, otherwise it causes memory leak. And if the memory allocated for the queues is failed, it can return error directly. Fixes: 59d0f7465644 ("net: fec: init multi queue date structure") Signed-off-by: Fugang Duan Signed-off-by: Joakim Zhang Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/ethernet/freescale/fec_main.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c index 55c28fbc5f9e..960def41cc55 100644 --- a/drivers/net/ethernet/freescale/fec_main.c +++ b/drivers/net/ethernet/freescale/fec_main.c @@ -3277,7 +3277,9 @@ static int fec_enet_init(struct net_device *ndev) return ret; } - fec_enet_alloc_queue(ndev); + ret = fec_enet_alloc_queue(ndev); + if (ret) + return ret; bd_size = (fep->total_tx_ring_size + fep->total_rx_ring_size) * dsize; @@ -3285,7 +3287,8 @@ static int fec_enet_init(struct net_device *ndev) cbd_base = dmam_alloc_coherent(&fep->pdev->dev, bd_size, &bd_dma, GFP_KERNEL); if (!cbd_base) { - return -ENOMEM; + ret = -ENOMEM; + goto free_queue_mem; } /* Get the Ethernet address */ @@ -3363,6 +3366,10 @@ static int fec_enet_init(struct net_device *ndev) fec_enet_update_ethtool_stats(ndev); return 0; + +free_queue_mem: + fec_enet_free_queue(ndev); + return ret; } #ifdef CONFIG_OF -- 2.30.2