Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp3284034ybb; Tue, 31 Mar 2020 02:04:32 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuc0VQFXDh5qvf0o1VJNc8Oc6McTBtKyPbTnAJLH9PFgm0pXcFV0d6U49H2+Q9StCPg0qZv X-Received: by 2002:aca:c45:: with SMTP id i5mr1277476oiy.101.1585645471922; Tue, 31 Mar 2020 02:04:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585645471; cv=none; d=google.com; s=arc-20160816; b=AQRMftrt1CDidIx6rhvYjc6szLPfvaDMv58hE/M0bhoix5ONYDcnw8xs0VTgJzlyHd APaPHvy2IS3TZvDIQWf7Ucsi6ENZNIfNXO0owWw9yGOpR6I6O33b1UnpH8L1+7NhGVnN 15ym6yge2JevNWMfkdaxVXs2NPUtZYv4uw/Hhr5LA1eZpOvjF7EF8DwmgXsCAiKGf6Yg ZgUT8aImrz6QToBLPOjE7x2sVjV6t0faCt0aa4V6yjlofRX8zUnR2Zg73lf7ayXD8cpj l9hg5pecYnSPcn0K68x40k1IkqQVatnv7K4bSMNHpdCSO2G6i0RDfNFeKlKBUsN+Ghec VC3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=T/kmJV5ztCqQWh42wT0asiLUV4VQNo1EjJXNLNZ8pGM=; b=oo5pZOSz74bQ9dXLtMg3IW+VlPe2YqxcS+d8A9AYNX1R+fxdnNBQE9afXLNNWtqbZK L210Z/F+WM1D6OfMwKNIzWL+LL9k4kJ2KApSS+gygExVN6auIBGOymv+TZMXgzzJ+H5o kNHfuHVv8Dp34kty8XPswv3AsG29F9kCrsaRBTYo0HcmMe/uKA9NVPfsimovKFWTJQZX 67dcmSg8XAYaqrYHcGHwXlXQjdpKe4zRsQOv0oC6gKfLvN2T5yucYYdJaAVyEQxwz8JS alOS7dvWpZDz3ncjqMzujQ+U3oIqrDwxmyQcfgzZRiBp/qD0iRGk2DmHLDpo/Obz3Wlw Joxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=gk+DrDXl; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b2si7150440otl.298.2020.03.31.02.04.20; Tue, 31 Mar 2020 02:04:31 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=gk+DrDXl; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730829AbgCaJDa (ORCPT + 99 others); Tue, 31 Mar 2020 05:03:30 -0400 Received: from mail.kernel.org ([198.145.29.99]:43104 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730597AbgCaJDY (ORCPT ); Tue, 31 Mar 2020 05:03:24 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DB005208E0; Tue, 31 Mar 2020 09:03:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1585645404; bh=PFJ61hZlXewm98PbidinrVr4O2dRVdQs+bRrFd1QcbI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gk+DrDXlxd3iXOvwPAD3AOGWpRvcJ3J7ipBtR1h9yvByQ6sXESMNsu7nCfBhRvvj4 o60SvuyyOFu7u3J2yRvqf+FgYOYqD8JjTHGB/qWQrB1J1KFYobiy37eiVcYRsWNTlj FYNIt8S17+JFJOPEI6kPjzZvbnerJrPDJYAgIePE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Edwin Peer , Michael Chan , "David S. Miller" Subject: [PATCH 5.5 043/170] bnxt_en: fix memory leaks in bnxt_dcbnl_ieee_getets() Date: Tue, 31 Mar 2020 10:57:37 +0200 Message-Id: <20200331085429.012819417@linuxfoundation.org> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200331085423.990189598@linuxfoundation.org> References: <20200331085423.990189598@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Edwin Peer [ Upstream commit 62d4073e86e62e316bea2c53e77db10418fd5dd7 ] The allocated ieee_ets structure goes out of scope without being freed, leaking memory. Appropriate result codes should be returned so that callers do not rely on invalid data passed by reference. Also cache the ETS config retrieved from the device so that it doesn't need to be freed. The balance of the code was clearly written with the intent of having the results of querying the hardware cached in the device structure. The commensurate store was evidently missed though. Fixes: 7df4ae9fe855 ("bnxt_en: Implement DCBNL to support host-based DCBX.") Signed-off-by: Edwin Peer Signed-off-by: Michael Chan Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- drivers/net/ethernet/broadcom/bnxt/bnxt_dcb.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) --- a/drivers/net/ethernet/broadcom/bnxt/bnxt_dcb.c +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_dcb.c @@ -479,24 +479,26 @@ static int bnxt_dcbnl_ieee_getets(struct { struct bnxt *bp = netdev_priv(dev); struct ieee_ets *my_ets = bp->ieee_ets; + int rc; ets->ets_cap = bp->max_tc; if (!my_ets) { - int rc; - if (bp->dcbx_cap & DCB_CAP_DCBX_HOST) return 0; my_ets = kzalloc(sizeof(*my_ets), GFP_KERNEL); if (!my_ets) - return 0; + return -ENOMEM; rc = bnxt_hwrm_queue_cos2bw_qcfg(bp, my_ets); if (rc) - return 0; + goto error; rc = bnxt_hwrm_queue_pri2cos_qcfg(bp, my_ets); if (rc) - return 0; + goto error; + + /* cache result */ + bp->ieee_ets = my_ets; } ets->cbs = my_ets->cbs; @@ -505,6 +507,9 @@ static int bnxt_dcbnl_ieee_getets(struct memcpy(ets->tc_tsa, my_ets->tc_tsa, sizeof(ets->tc_tsa)); memcpy(ets->prio_tc, my_ets->prio_tc, sizeof(ets->prio_tc)); return 0; +error: + kfree(my_ets); + return rc; } static int bnxt_dcbnl_ieee_setets(struct net_device *dev, struct ieee_ets *ets)