Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2708475pxj; Mon, 31 May 2021 08:46:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyYncrMsxLv9ZyKBJyiwrLvIBufspcAmmBfrKAfWREmDvF818/7lWd9cyX6stPaXXK96/l3 X-Received: by 2002:a6b:ec19:: with SMTP id c25mr17190622ioh.181.1622475962878; Mon, 31 May 2021 08:46:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622475962; cv=none; d=google.com; s=arc-20160816; b=DSAV5+Q0QVAnWLCKURj31wu8iUJLV4bpiEolttZ6lr+XgM9ReaE/bkbWL47Pe5TGHp 8IK14EObfIhBAnAugxjfo4BbS1cdondZP3hslsk22wSvE+JcnY3XgJY43GyenKb9dV5r UuhhceD7OKRwmaDKdwEZ3u4KSdNM+DVrp+Yo/FPpVe5u3eVJm0Cavfu5MG0PpHiYTpUB qhSpSeOE/qibQKDtXBechkT/TXOsO/JPSzD3EZG/B6rD3aLyKrhFhg7pT9B4DB0Pogj4 zPmxApH6mAQEGUgWVVZflLXLsDe03cItkRJiC9jvcUfQWBqQ768a8fuhK4XAK4k9uDTU G96A== 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=zIcrNxo8VyycIGqW+S/WZFwhbnL+HVixVXQmWqjvmgs=; b=I+4zTlPzRyJCQgOQ9d4ZIQgyXePyRNaFMqbZmWNynyJtH2GaQDGUD/r3GnAYVmLgeF Q6g91Ab0dI2WnIIVQCWNKTnZaomST1HpGtgFBcSgDk6+3DJR3vmNjRqD/eqLgOLBLoyJ LID3bOs2wgTD/SV4HpW9hXMelLY8PcmhnOEJXRXAMbVGiR4o/4PLOxRhWbhfWFhBd6pp p5MupdrzrN7V9gu7CykL3WOVoMUFDc5V2Qufu2sxdExA91IsE8Fu78mNHOPCqYz4hKkt MeQJaM/sT/BmrrUiqHnakij6RLgp2P3PcXmLCUIZldqq9c7QHFS17PJu2b4ORpiauA6R FJNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=iX5mxmJE; 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 x9si13099872ilo.119.2021.05.31.08.45.49; Mon, 31 May 2021 08:46:02 -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=iX5mxmJE; 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 S232905AbhEaPqz (ORCPT + 99 others); Mon, 31 May 2021 11:46:55 -0400 Received: from mail.kernel.org ([198.145.29.99]:48842 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233894AbhEaOZf (ORCPT ); Mon, 31 May 2021 10:25:35 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 26CE261AC0; Mon, 31 May 2021 13:46:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622468815; bh=u6KUzoNmaj446JcGXtccmmHxdzE/YktDjb/D4QpT4/c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iX5mxmJEwyn4651fwgMtIo+OxH7AJ6sagzu2Lejh5DOx2RvWM5QkQruJ6thQpiu70 cznT8yoZGy338HTAoefSuIs8VO7YTMV8Klz2Vl5Cad/KLU7ROkOIaZDxkebed8VIQ9 l0hZOx8kN7dlezu7diVMVzm7b4sBnaY9o9TI1Dkw= 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.4 140/177] net: fec: fix the potential memory leak in fec_enet_init() Date: Mon, 31 May 2021 15:14:57 +0200 Message-Id: <20210531130652.779806420@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130647.887605866@linuxfoundation.org> References: <20210531130647.887605866@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 fd7fc6f20c9d..b1856552ab81 100644 --- a/drivers/net/ethernet/freescale/fec_main.c +++ b/drivers/net/ethernet/freescale/fec_main.c @@ -3274,7 +3274,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; @@ -3282,7 +3284,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 */ @@ -3360,6 +3363,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