Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp5545183rwb; Mon, 5 Dec 2022 00:06:38 -0800 (PST) X-Google-Smtp-Source: AA0mqf5odQNuEcBeNvz9hfJKZOvlzjNbdQfS7Qnr5O/W+akMJuVnfdYbw+IWuTypzNNzcgunjxWG X-Received: by 2002:a17:906:a084:b0:7bd:f57f:76a4 with SMTP id q4-20020a170906a08400b007bdf57f76a4mr32978420ejy.413.1670227597984; Mon, 05 Dec 2022 00:06:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670227597; cv=none; d=google.com; s=arc-20160816; b=S0zp7cC+vKIatcoJZFxkGZI/7L6nBDRYOrvYnGXSvKAQ7LZtt772hp5EnHvirfcxdE gABhM3nNVeukrDCdqmI128PZWiBcxNeMJy7hopDkqDUjeiD3YnKRG2/mZwzfU5Q4K28x ZoVU/x+UTKjUKAfqzMZpvzFQo6/ON5/PXnkO22v3y4hvqFUVXRpawYXv7Sukof8whRfB w2Q4kWZQg+kdHcAyBZ20auzBLGEZgLl/1zYYk4lx6wUO0+Hryp1e76BgXaMKWOYNXD+I 2XT6hYm2kGp2XtSntDAy3rbo4au/z11b9vl/qoN9n6vonDFyqnNYeLVAUuvfXVXfhnVx 6vAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=ZxQbqev2kXiCkI60eAEPAqBOwdbsoAZiD9/geXrQ0Uo=; b=TJyvHRPabAPidpuPsAZfzjP9F1tEBmlR1f0S6baFrAnAE8/2XhSORpOLkUuDVrhdNx gP91Tgk+R1ZkYZgRrdJYdOLCqitXW0UKeURKbIFg8JNUN3Y5PqfsDIicG3tiMuKtkvgj HZJOh5vC8gOdUG62EGYfqYYTOsW/z6MkiGY084XVvwS5O3ASEBOYccslW1ToRRotSvy5 UuwcFDYOJq2WxvbAq6dGe19qJfPFcYBsGqymvJ5GCh210sIscGoJTlcHJ4kTkdmATZ3u XQWksYCJ8bGo4NEvPAWr0iVeiLOjIzfH/0hmxZ6Vi76vk8QDWANOvkbiVOyYwRQBmU03 uWfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=JeDvaHhn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a20-20020a17090680d400b007c0a516af79si8399563ejx.313.2022.12.05.00.06.18; Mon, 05 Dec 2022 00:06:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=JeDvaHhn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231830AbiLEH7M (ORCPT + 82 others); Mon, 5 Dec 2022 02:59:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52282 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231819AbiLEH7J (ORCPT ); Mon, 5 Dec 2022 02:59:09 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9BD941144B; Sun, 4 Dec 2022 23:59:08 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 2ED8860FA1; Mon, 5 Dec 2022 07:59:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BF277C433C1; Mon, 5 Dec 2022 07:59:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1670227147; bh=A/HNLNucTgPNacp68QdzI0RTg4NuTQugxg0nvBA0coE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=JeDvaHhnklF+bJzbxCEoxbj9pq4nQRC3l4ik90CtTLny8hJhtHMXxgEGuzqf5oQmS lEfZn4xHNIAC8ffDXtTJoOyPv82zqt9Hkweumkc/vgtoutmOKm/U1aJklZwc9LTten Io6UEcMXLMkQ+p9yLDoXi4f27exFA8CzQLWiGSmDbHq5HP7zwRoRiOLRshzXGvkXnP 5o5hUFWWb9mxyVWy8sqbEySH02D7DsbUrATjTfMVqJcVGJ2oRBclNU9pSMPZT9JQBi mbq42I2VjUAQl09mMBZPTrge38MX6TN5wXOFPEDh8izfrmKk3AQYgedQqqpxQRzsWb PD87jzcZhbl+w== Date: Mon, 5 Dec 2022 09:59:02 +0200 From: Leon Romanovsky To: "Ziyang Xuan (William)" Cc: sgoutham@marvell.com, gakula@marvell.com, sbhatta@marvell.com, hkelam@marvell.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH net v2] octeontx2-pf: Fix potential memory leak in otx2_init_tc() Message-ID: References: <20221202110430.1472991-1-william.xuanziyang@huawei.com> <206c4fdc-bba2-32e3-8e44-82cad81e0436@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <206c4fdc-bba2-32e3-8e44-82cad81e0436@huawei.com> X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Dec 05, 2022 at 10:31:02AM +0800, Ziyang Xuan (William) wrote: > > On Fri, Dec 02, 2022 at 07:04:30PM +0800, Ziyang Xuan wrote: > >> In otx2_init_tc(), if rhashtable_init() failed, it does not free > >> tc->tc_entries_bitmap which is allocated in otx2_tc_alloc_ent_bitmap(). > >> > >> Fixes: 2e2a8126ffac ("octeontx2-pf: Unify flow management variables") > >> Signed-off-by: Ziyang Xuan > >> --- > >> v2: > >> - Remove patch 2 which is not a problem, see the following link: > >> https://www.spinics.net/lists/netdev/msg864159.html > >> --- > >> drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c | 7 ++++++- > >> 1 file changed, 6 insertions(+), 1 deletion(-) > >> > >> diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c > >> index e64318c110fd..6a01ab1a6e6f 100644 > >> --- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c > >> +++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c > >> @@ -1134,7 +1134,12 @@ int otx2_init_tc(struct otx2_nic *nic) > >> return err; > >> > >> tc->flow_ht_params = tc_flow_ht_params; > >> - return rhashtable_init(&tc->flow_table, &tc->flow_ht_params); > >> + err = rhashtable_init(&tc->flow_table, &tc->flow_ht_params); > >> + if (err) { > >> + kfree(tc->tc_entries_bitmap); > >> + tc->tc_entries_bitmap = NULL; > > > > Why do you set NULL here? All callers of otx2_init_tc() unwind error > > properly. > > See the implementation of otx2_tc_alloc_ent_bitmap() as following: > > int otx2_tc_alloc_ent_bitmap(struct otx2_nic *nic) > { > struct otx2_tc_info *tc = &nic->tc_info; > > if (!nic->flow_cfg->max_flows) > return 0; > > /* Max flows changed, free the existing bitmap */ > kfree(tc->tc_entries_bitmap); It is worthless call for probe() calls as tc->tc_entries_bitmap is always NULL at this point for them. The kfree(tc->tc_entries_bitmap); needs to be moved into otx2_dl_mcam_count_set() as it is the one place which can change bitmap. But ok, it is probably too much to request. Thanks, Reviewed-by: Leon Romanovsky