Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2627908pxj; Mon, 31 May 2021 06:55:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxS4rr8bocfaLRaBzpMMfDKfmO1/NoNPrnI4rBp1u5THKNYaY8HhUWhqJiGDUtYFW7vRTsq X-Received: by 2002:aa7:c7d3:: with SMTP id o19mr25331287eds.142.1622469349388; Mon, 31 May 2021 06:55:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622469349; cv=none; d=google.com; s=arc-20160816; b=Of+vynUl57QP3xYrOqtsgfKrkRrhvAUu/WBhsFy6uAuFJl/ALs7HNs3Wh0zps6Shrs YgsegFC1TFri8BHnMSULeA9JgprTfC4gguhp/qlsLEHXnm33S3OWnRFcugTjjgbEBPpC TcJNNdpAIr82QVXjOuu/uuYRRMmGH7P7Dfp3EcQSspDbluOXfPMU3i2cmWgMlQlFUSQ/ FX9IlC9N/ECS9A3zdGofeLyMZShVViz55YXMekqZyCTc9TB0RBNX+jnMep6mGddbTbcl jOD2R3LkrtqT0xe4cDEvfGllrsirFrmZSCtp09ZrtKu6HyYXll1HoZhOv0pdFvUmwnAZ V6Dw== 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=AkwepuixR39hDyOnaW5kJeYdtlXTIUiez+xPZg3mBNw=; b=lhzYh68Jz2oksJNe9bqH3nPDoEUplvq3doCWcHFepRXkGdLN0ittsTHpyKUYbR61+W xnAMpeKjllrO0AaMrwNftOZZdaEi7OSZeciKKPlEKlWPREHxWk3vZ0xiqqE3BmPwQAWz j7T3kYNeelnMVNdT4KhaAC9tiS1pqbJbfFjMgy99ptfGKWmvz3Km8lFaI6Ka2an1T4t+ e0HirZYkwlNiVMS9WhSHXNh9iOtFqWCuEaE1l17DF4k6UPF0xqim5Fx2M4JNS8aiJlLK /5Btipp2c5fNPNJYyisNFElLMRJVx+eAQG+1o0LRowzytx6Z2zmrGXMSPvzKORIChoYE WLhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="DEF/rKeM"; 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 o15si7814119eju.373.2021.05.31.06.55.26; Mon, 31 May 2021 06:55:49 -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="DEF/rKeM"; 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 S232158AbhEaNyL (ORCPT + 99 others); Mon, 31 May 2021 09:54:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:39186 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232065AbhEaNfs (ORCPT ); Mon, 31 May 2021 09:35:48 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 40A4861402; Mon, 31 May 2021 13:25:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622467528; bh=aHgdC1DNDuMLYTb0kZUNu6qqLmfrPL6M0Y/kheqV9Lk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DEF/rKeMVmnl+UOz9UAvrGh5oHY8/7gLvhipKFSJ2qlyaElu3G6QFN4CjaFx3WUEb WB4CeR4P/EQZx/+XrXKyjyfREEqvxOA+T8Jnq3w5lN+ddwEY9PqOQY87LqzsHLTGLW 55bUg1m2N+jOxSEg942osCizmoKYIzj45YF992pI= 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 4.19 098/116] net: fec: fix the potential memory leak in fec_enet_init() Date: Mon, 31 May 2021 15:14:34 +0200 Message-Id: <20210531130643.461976714@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130640.131924542@linuxfoundation.org> References: <20210531130640.131924542@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 7d1a669416f2..6b9eada1feb2 100644 --- a/drivers/net/ethernet/freescale/fec_main.c +++ b/drivers/net/ethernet/freescale/fec_main.c @@ -3221,7 +3221,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; @@ -3229,7 +3231,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; } memset(cbd_base, 0, bd_size); @@ -3309,6 +3312,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