Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2969788pxj; Sun, 20 Jun 2021 06:31:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwm4Gub9exezPpsgpaZR3+AjKsgP3gbG+TKuPZ814doLSneQHxRSDXKuaNhrATMol/McSkg X-Received: by 2002:a17:906:a28e:: with SMTP id i14mr4975711ejz.395.1624195912375; Sun, 20 Jun 2021 06:31:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624195912; cv=none; d=google.com; s=arc-20160816; b=etTug3C9s0HbQS+zf/D4e5vQ3wkPmDBePAl3qedzs8RfDutmRI0l6y50hSY1ksXIG2 sLmLPNH9NnLcU2sgy/UfC3rrjCKUBkEjQqPkeIBNddpU/sdckI5xjKWFpDf5r8WfAb5m ARjAr7j7Gm4meSRcMYY9tI++HEgBHlnoBC6GhgdQOSztODcDwixcz1bLZqqEl/j/DXr/ igpSK9EitOLNyGFYOc6JjA5l30cgXCc7/3sRHlPJ9+C695J70xYDBvIr0MDUmtgBLt+H V8lkTDFSFYyCMrdiCVvLt0FRPXnNih4Sw/1+7j4/1Vq2uil1NDBL6YYoeFDxVx+P+wZM yWXg== 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 :message-id:date:subject:cc:to:from; bh=SINIqCEgDvnxO2/LzSUD7Fw1yxp/TwD//BqdRCIDVfI=; b=Kj0Umc8u75bwY42LfowTuWQuvn9N7yBB1rH6Q9JfevUpEckwBuACSlSCC0ocKeTPtn wHvgrgGbSIK01js5KhaHfSGiux3M9hOoFLMRZZQwbS/wsufwbTOGce7iGWkn2OsTmUJh 5//6cJyk/3qNpbGPi+qXbfBO6owqe9//VtqU9Ou6rHcWIt45WcjoEGddqJV5mSXQD2Yz U6qwgQavM8p3t8O3JSP1sURQP96HZQJGOQ1oYlviNt+0+cKmD0D+hwSe8YDLEEgRRoJt pi3v+XDR/cgmlsQTczNurpCriJ5GTAmLFpOxEZthqlw180Zedi3fuLmtvNa9MFDM9pwx p5Ww== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k13si6711067edq.390.2021.06.20.06.31.00; Sun, 20 Jun 2021 06:31:52 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229684AbhFTNab (ORCPT + 99 others); Sun, 20 Jun 2021 09:30:31 -0400 Received: from smtp03.smtpout.orange.fr ([80.12.242.125]:49413 "EHLO smtp.smtpout.orange.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229662AbhFTNa0 (ORCPT ); Sun, 20 Jun 2021 09:30:26 -0400 Received: from localhost.localdomain ([86.243.172.93]) by mwinf5d33 with ME id KRU82500G21Fzsu03RU97r; Sun, 20 Jun 2021 15:28:13 +0200 X-ME-Helo: localhost.localdomain X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Sun, 20 Jun 2021 15:28:13 +0200 X-ME-IP: 86.243.172.93 From: Christophe JAILLET To: jesse.brandeburg@intel.com, anthony.l.nguyen@intel.com, davem@davemloft.net, kuba@kernel.org, david.m.ertman@intel.com, shiraz.saleem@intel.com Cc: intel-wired-lan@lists.osuosl.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET Subject: [PATCH] ice: Fix a memory leak in an error handling path in 'ice_pf_dcb_cfg()' Date: Sun, 20 Jun 2021 15:28:06 +0200 Message-Id: <0302ff0ced7f38b0076c08ce351477d338bbe548.1624195601.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If this 'kzalloc()' fails we must free some resources as in all the other error handling paths of this function. Fixes: 348048e724a0 ("ice: Implement iidc operations") Signed-off-by: Christophe JAILLET --- 'event' is allocated and freed just a few lines below. It looks like a small structure, so maybe a better fix would be to avoid the kzalloc/kfree and use a local variable instead. Another solution --- drivers/net/ethernet/intel/ice/ice_dcb_lib.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/intel/ice/ice_dcb_lib.c b/drivers/net/ethernet/intel/ice/ice_dcb_lib.c index 857dc62da7a8..926cf748c5ec 100644 --- a/drivers/net/ethernet/intel/ice/ice_dcb_lib.c +++ b/drivers/net/ethernet/intel/ice/ice_dcb_lib.c @@ -316,8 +316,10 @@ int ice_pf_dcb_cfg(struct ice_pf *pf, struct ice_dcbx_cfg *new_cfg, bool locked) /* Notify AUX drivers about impending change to TCs */ event = kzalloc(sizeof(*event), GFP_KERNEL); - if (!event) - return -ENOMEM; + if (!event) { + ret = -ENOMEM; + goto free_cfg; + } set_bit(IIDC_EVENT_BEFORE_TC_CHANGE, event->type); ice_send_event_to_aux(pf, event); -- 2.30.2