Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp12523pxb; Fri, 15 Jan 2021 04:39:46 -0800 (PST) X-Google-Smtp-Source: ABdhPJxKor2IwVgJ2WfpbZVthssdAlChvAThHN4hHE9jbhzgSW+ccv3TweZadg6e70C9CB073w2L X-Received: by 2002:a50:c3c5:: with SMTP id i5mr9497983edf.166.1610714386557; Fri, 15 Jan 2021 04:39:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610714386; cv=none; d=google.com; s=arc-20160816; b=fBU2UYeMPhQYYNYGHIXtMOoTcqkkjEAjhg1xZYUFMCSfi2CopuTPTRtuQol7Yf8PmX TY++G4UeFvc0DaCY8geLaXQagTHiUS0trbAcOcm+NdWZ/YH2AvnNjobYuKuf5rQfSuep RiSC6vbZN92X7pfnYq/1EytYKKxci6NBWnXPgw909AbGOgudBaK4++v0xJmwY042bnB/ VskcYN/1oCq9oS0D/caC1UoV0LUT375ZGempphZeYj4xTXKAO2YGol7xhXB0pltJqCt4 ZGwIBNC9I1qTpjU6I2o5E2AcflzK7P0cnNd7TWrYl/by2rVJ/sA0iLMWBB3jKVtaOTwU mYyQ== 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=WITzDdH2CkwORq4+gstO0tjkDWlYj0TYS42ZOiLfaKU=; b=bO1DNNby5jEJMNeqcQ8rUqURZjrugZrQIBK4mP8bv2BPbAvU9T7FK9yokCeCCJqeF6 d9XizpTZ/LCteTCYSKN7kE7uGZrOjdSd9eAxT1n96/YQUR1tlxOTPwE9Q6H6B1XmZ0sx NLL8bD7C9gXh0Uk0hrtqUXKum40Gcj0AfhgQ1sWazcxq/nSf+JotlZfIcYkeqrT+uuFS eek0HOz8oYAYLBYUK71JjGVigrFV8ikT7Pm3TkMMwWkY/cy4LgZKxK6uynWw9KyKblog FUR4UjYbDaNMrVbTXz14xsoTkOeGEMudaNjkfFwdTPBtExr5ZHF7ZwSTn4QkrvymfkF2 CA4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=hFnn0kWE; 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 cq13si3631573edb.130.2021.01.15.04.39.23; Fri, 15 Jan 2021 04:39:46 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=hFnn0kWE; 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 S2387707AbhAOMff (ORCPT + 99 others); Fri, 15 Jan 2021 07:35:35 -0500 Received: from mail.kernel.org ([198.145.29.99]:42574 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726370AbhAOMfa (ORCPT ); Fri, 15 Jan 2021 07:35:30 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 972352339D; Fri, 15 Jan 2021 12:34:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1610714090; bh=6OZyMcU+zl2kq58WqMVWZUBKCu7pBODU2jmb9OsoJfw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hFnn0kWEE2xwB0kgAbIzkmJImQ4FtArCzP6k6aoqUTma7lEmgL0F/x3JzVz7ffEBz wUfebfCOmxfpehVbG6WU5b62t4yvv/b1I6yVVs9OQBBeVLoS/23YsJTFL9qXHmmGS5 CdGSf0stW183V5Mv0cz6QA93PDI0X0vWGTiFvf0Q= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Colin Ian King , Jakub Kicinski Subject: [PATCH 5.4 14/62] octeontx2-af: fix memory leak of lmac and lmac->name Date: Fri, 15 Jan 2021 13:27:36 +0100 Message-Id: <20210115121959.093997021@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210115121958.391610178@linuxfoundation.org> References: <20210115121958.391610178@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: Colin Ian King [ Upstream commit ac7996d680d8b4a51bb99bbdcee3dc838b985498 ] 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 Link: https://lore.kernel.org/r/20210107123916.189748-1-colin.king@canonical.com Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- drivers/net/ethernet/marvell/octeontx2/af/cgx.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) --- a/drivers/net/ethernet/marvell/octeontx2/af/cgx.c +++ b/drivers/net/ethernet/marvell/octeontx2/af/cgx.c @@ -725,8 +725,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; @@ -737,7 +739,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, @@ -748,6 +750,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)