Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp269321pxu; Thu, 7 Jan 2021 04:42:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJxHUDGXgvzAWIZk6aPBP67Z6OLaDGww4J5dzNcgzEZhL4z6JeuUau+Ox1ZveFyTksBs/sCu X-Received: by 2002:a17:906:3553:: with SMTP id s19mr6017959eja.95.1610023354812; Thu, 07 Jan 2021 04:42:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610023354; cv=none; d=google.com; s=arc-20160816; b=wj57RpZhJwpB6pz89rEak/nndydfjnn0Min3YMwZI9gQSm8KTLiZT2zHpPT1CMt49o /dds+v75hk7yrWL0/GUHvuno0hIvFoNAQgQnR2GK5hf1mO++VYPfguQprSz207eXCvhO mYfX9ywVDVlM7oKBtFDGtVX9ryY3lv7CUmPrqyTE3rf6oemWFrd4pNbA13z3h6LcwxxL cGIgED2hl8ErEGKouodPFfGqiHxsU/VZN/DXJKjHzq61N1jtSac9qXQoZtYFIUWEvUOC KX7p51rLmTkWg8rRtG82UMWBVLqAo/ytOJhmJxqd7kbvWY7s1lPrJzKusJJ4mpMYoHlU hYhA== 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=e0n+VD/3OO0jWLQ9ZL92UaNQckSUxwL8h2+muNK5HgA=; b=kkASQdk1/y2MB/Zt3uC+MlC9V1ZkV8K/BJpshNbUFEz4QfXYiOMziYco72PMBsvA1P 3mp7vBZ2tbdjipLF+FCMGJsM7p/QDUab0brAahDzi2F8PugZi5bDf9zLsYZPVoAHvzrW LldiRTeuZgmUUkV3y7dMoW8V14wSIcpa6FbdbfadLeJcnoA0q//8+nhjVT/+OejJr2FB ZJljDhMe9sGrjhMGME5OKSFyXBfORVEIzyCiRzafeaB3FZdVscgfyISu1GQuatZtyFsa WqUbhJa9lAb0ZdFp64V0yX6ZFWXVjsbezBg9IlYzLLtpqY9d84Q95BO3Xce/h+xMWfOG +9Ew== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e7si2282872edq.202.2021.01.07.04.42.11; Thu, 07 Jan 2021 04:42:34 -0800 (PST) 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728374AbhAGMkD (ORCPT + 99 others); Thu, 7 Jan 2021 07:40:03 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:39838 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726436AbhAGMkB (ORCPT ); Thu, 7 Jan 2021 07:40:01 -0500 Received: from 1.general.cking.uk.vpn ([10.172.193.212] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1kxUZQ-0003On-Fm; Thu, 07 Jan 2021 12:39:16 +0000 From: Colin King To: Sunil Goutham , Linu Cherian , Geetha sowjanya , Jerin Jacob , "David S . Miller" , Jakub Kicinski , Nithya Mani , netdev@vger.kernel.org Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] octeontx2-af: fix memory leak of lmac and lmac->name Date: Thu, 7 Jan 2021 12:39:16 +0000 Message-Id: <20210107123916.189748-1-colin.king@canonical.com> X-Mailer: git-send-email 2.29.2 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: Colin Ian King Currently the error return paths don't kfree lmac and lmac->name leading to some memory leaks. Fix this by adding two error return paths that kfree these objects Addresses-Coverity: ("Resource leak") Fixes: 1463f382f58d ("octeontx2-af: Add support for CGX link management") Signed-off-by: Colin Ian King --- drivers/net/ethernet/marvell/octeontx2/af/cgx.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/marvell/octeontx2/af/cgx.c b/drivers/net/ethernet/marvell/octeontx2/af/cgx.c index 1156c61f2e02..aa5da9691a1c 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/cgx.c +++ b/drivers/net/ethernet/marvell/octeontx2/af/cgx.c @@ -871,8 +871,10 @@ static int cgx_lmac_init(struct cgx *cgx) if (!lmac) return -ENOMEM; lmac->name = kcalloc(1, sizeof("cgx_fwi_xxx_yyy"), GFP_KERNEL); - if (!lmac->name) - return -ENOMEM; + if (!lmac->name) { + err = -ENOMEM; + goto err_lmac_free; + } sprintf(lmac->name, "cgx_fwi_%d_%d", cgx->cgx_id, i); lmac->lmac_id = i; lmac->cgx = cgx; @@ -883,7 +885,7 @@ static int cgx_lmac_init(struct cgx *cgx) CGX_LMAC_FWI + i * 9), cgx_fwi_event_handler, 0, lmac->name, lmac); if (err) - return err; + goto err_irq; /* Enable interrupt */ cgx_write(cgx, lmac->lmac_id, CGXX_CMRX_INT_ENA_W1S, @@ -895,6 +897,12 @@ static int cgx_lmac_init(struct cgx *cgx) } return cgx_lmac_verify_fwi_version(cgx); + +err_irq: + kfree(lmac->name); +err_lmac_free: + kfree(lmac); + return err; } static int cgx_lmac_exit(struct cgx *cgx) -- 2.29.2