From patchwork Fri Sep 13 13:15:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 13803435 X-Patchwork-Delegate: kuba@kernel.org Received: from EUR02-DB5-obe.outbound.protection.outlook.com (mail-db5eur02on2074.outbound.protection.outlook.com [40.107.249.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A70291DA60D; Fri, 13 Sep 2024 13:15:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.249.74 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726233343; cv=fail; b=RGEeK4ruRzIdm54X/W36WswvtgvUsx1hwh6erdNqIxDbvUoVNbAnJN2LbKzLUWpHPk5HWE9TXh/NqtRuIfBVKsTRua8bV1D4FeOcMq9Kz9JjzTsxqNwvBtyhv0lP/qFffBmpIr01DnpFgt6kTy4WgoTqAmYDD/uucA73Eqo1j5A= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726233343; c=relaxed/simple; bh=mBiH27qIQkNOYyjsBYwZe9gydW6vawrMe00CXCyE5AU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=kuEgn4uCa0IFr3wH9hO99s7eGIdMK7CX5hzw1Iaybs9TGk7oU3RxUKK1gyFQM4TZInH62p6kamgTwYmDSOw8e6buN14hxYZ2wyYSp5DtloJx5zgn4g0TeFFAurM/Fm2gGbjgaxZIN4uZyWhPm7ic2GMWaKYn3nnQEcCA181C/zg= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b=DOfPYcWu; arc=fail smtp.client-ip=40.107.249.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b="DOfPYcWu" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=myDiU47NZnfstoNOZaOBwOh34t99tXqRNwKWm4C+6zqXFVW62xonE4Wux/QNRhD3yDlvRAvN0r6SsgYj4Odn6gxzIQ+9iu21LPSU4rmg9yKbnXeugcfZJJeQMoeXhTxnCMQg7wnZ15TagnFaO8CB5s7ZL7m3gGmvEWyaenebN9zCG14guM+FHQbKn64I35NpPG4wruOtDheleZLPvx97WSoi9Tm271Dy7vCFdatoqy/53sBjxXxw/09RFB+CkLS0nyZtZO8guF0pCq4oEqtkTfYddyA+0i560JHNW44rWvirp6AZ8RxyOB7FbxX0AdkguOFg1L5JN6SFiRwWXBJ7DQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=LfxJ4Xpgjd1PLn398qFkkTVpKPX7SCSSEO+Cb3FY3xY=; b=hI8He/ns12od3ck6eQx3SaxJyu/CwZaAk1PvCiJ6uj1DSDbP7o9QIH6L6udxLYGrqwFMwyDiW1acT5ABDQILBwuCrcx34k7DnCEazssYkvL0fZmhvPytj9NPgtKSrPiBsHgpRXvue3m6sNTEiE45wnfvvLtM7+kqMGnSFGcP18fcoj2yL3g47DAxq9Wz6ZcSHpdj9vnqNhRoVe1AHMUiWlks30bYOfw8XpDOkbrmHl9aout/V48qIQChmrgIFvfin5gD/V/57pMqkzNXy97dnNkxgklaMHmz12+tDzolr1SkzbJ8BG54kRIgmkuWlCPx1rig66Ara6QTVolsJed+Dg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=LfxJ4Xpgjd1PLn398qFkkTVpKPX7SCSSEO+Cb3FY3xY=; b=DOfPYcWuw3smIXUeT1ILOi9gSE4gF/VB/j/E1gzDeLZ43Lx4fSZ1fJM9vQRnbnLHarB0inYAafFgtXc3jDtDftJl4J0qZMxRuSEswlnPEaRgYZ3WD7KxSc8myMOxNOGmKyMNDvEJrHETRioIJBNdWbhOP3RbYN7VYZ9tfAhNh9xKLuVl9rqlGYSQ0H70dtrkv8LFsVX8q64yKqDS99sc0nnx5eVdgc7NXgMsBP2GLA2+lPjxccTaZTKI39nh5GCWD9wYc9Wk0bpQ5rjuxOUoP6HA4uewqJh+wf2SkGx3RjZ9zcBJIT0gZagkfW+NnlBS61v5Hq0rvBu/1FaOpq30MQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM8PR04MB7779.eurprd04.prod.outlook.com (2603:10a6:20b:24b::14) by PA4PR04MB7519.eurprd04.prod.outlook.com (2603:10a6:102:f3::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7962.17; Fri, 13 Sep 2024 13:15:37 +0000 Received: from AM8PR04MB7779.eurprd04.prod.outlook.com ([fe80::7417:d17f:8d97:44d2]) by AM8PR04MB7779.eurprd04.prod.outlook.com ([fe80::7417:d17f:8d97:44d2%3]) with mapi id 15.20.7962.017; Fri, 13 Sep 2024 13:15:37 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andrew Lunn , Florian Fainelli , Rob Herring , Krzysztof Kozlowski , Conor Dooley , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next 1/4] net: dsa: free routing table on probe failure Date: Fri, 13 Sep 2024 16:15:04 +0300 Message-Id: <20240913131507.2760966-2-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240913131507.2760966-1-vladimir.oltean@nxp.com> References: <20240913131507.2760966-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: BE1P281CA0119.DEUP281.PROD.OUTLOOK.COM (2603:10a6:b10:7b::12) To AM8PR04MB7779.eurprd04.prod.outlook.com (2603:10a6:20b:24b::14) Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM8PR04MB7779:EE_|PA4PR04MB7519:EE_ X-MS-Office365-Filtering-Correlation-Id: 2ec2d3e5-b48e-4302-925a-08dcd3f6284b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|52116014|1800799024|376014|366016|38350700014; X-Microsoft-Antispam-Message-Info: 4Zc2P7wXr8bQ6CAGwm7sxQm1ahYCyhrWuCAuqYypJKIQiowACSMAr3GoNkoWz1R6ImoLypoQ71LjT1ppb8S0KIM2aY30Dl+6yT4p8EGesW7Kquh8vG+lcDyzEXTlCplfjF9MAJ/GNxvH00dPPn7uNkRTZrEcXTDgQkX8s4FrscBo6Dib+U50pIgnW8rqISDIsfMtMySVTpZLEbZzkVZkoo7MB/TwOa1sLGnA6YNtqgIXEkMwylX0c8nes1Ewu67w4F3QoPP5WxRV48hObNoAZvqiEHKtgACpsYlcykUn/Qnt/5pLj53gGFs4PEBXo4REAOYJ8RKuE1/r+9FnrNbPTGSF+n8KJljqfJuDsO07oniM3/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report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM8PR04MB7779.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(7416014)(52116014)(1800799024)(376014)(366016)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: mp1/9iFW9F+Wr+EWUcmVyhEvIPGZKobKDqSFJQXfK3eZHmks96x8Btrpeofl85ccIO2Ri2qO9xdhkh4gWGWBCJ2YbfADEpKMCyoiO+72RqpGKb+y80IgTKznzOq5eMHqjHVgni88UTZQMUSjdwF3ANV0H+T4Wkr+9px7Sl0KL1pw9Bg6Rp8EfcwLGLcmMbuEY1EHXO5b0+nKb9iN1dXcAzOvvt82ar5lS/MhbHUIFH5uW+5AXE2qVOS+YxymyaOvfYyZmeD+Lf9nsE2cfM4LQ+1xezbgVi4f1U9pEyYjZ7K/Lg3yqpbCfcBFrPkr2KSYpHyGjiU+0Q/OtcVlBNiUVryXkI3onxrdTrgYWDpBmkzCVFQWxL2ujYN0HXs52z/ypzhPB37pxHPHVZHJefRIj6nOPs0VhTR6djwR5v+ZZcFZoFLtkcK0XCBlQ4ougdWt+ABH5Kck16EWUb53iih6uazznB9osquDV+W1A8+OeTPNm/d13BMd5w1je9UW7kU+5QFpaO6NJ7twrTW3b7UDap4W1u064jb1Txln/Mwck4hFKyLez81YjYdNiVYCaoAsPMwzeLB6AhwGXAAK6jpKIpVrn6WkeqFg+JvqBk3yfzoP/p+H5bAitMogUqyGySFJZKmWFS9AiSzoaIfT099LYcVsdlFwDX9F7YSMf0nt89FsYu5Coe+5MlEmtWUWKJ6sv1xFIQIW+YPzakznWyjftNkozlTKNZFz6FMntrm4zhYhG0JzKu7EU6ZqSDPcKT4GhlP9e4AoQKbmK1f/MLQs1NJ5D/VeVQ5W+PdfFwygAaUT+TCtGHBFaIY9SWP3usoZJL5L2x2ShL9voBLghau4vI6Yh4buixW/L2GFayy9LnMC9WGOUzfx47sAK9ZOPOX1lqyY22jOHj0u/TDAAk1Jd6OCPorGIpfzQj2ePklvvoJ2HnkjH3Z1hVQbvIEN84ehUAvi1ySJcZJpxdIGFuPSAFXSZWt+1ogmNuyi6ubcEjh5lpHIb1TikIW1YkUhP+ViqIgQ+QXWto+E/IK3Nl8VBVnXEZeuZTryQG5ZwDE2+lt10g5Tk+zyW81fnqgJDL0qn/A9lL+zBKx3ETgfYtMeUjSKh6Dw/68rLSvIYZXC4B5SGlQf83f9TuxktaLLm+c0k0Sgjv98LtVvRKyav4wdva4jRdTpn8ufukwmXi+QghYo+Hp3mrOqHSGD7fbQY3iZ1etWWDXfYltqXCCaB2/olS+Dx48TrYM/nvwSX53nnkpd07tzveysE+JqC7Gf/TBDA3jZW1/L+5VMZKF4KyoG4TLZmj8pVquWt/J+cyxW7/UpdN7krxUUGcmuZYZCrhOf5SjkA45sqdVukUSIhXDQsATWWoyV37EU+p3khi3IvvX5+Wu5tb1253ij11gpVa+l+7KlP3C5OxrnRXfOXjjYK22SI5Tr+q2yCuvzW8GJXDbhi48xvFudRqxTJ7MebTBU8kTOBfSuTsB1+OtfSnFsKupxySP4JHyza+C9HaXYTUE5bCQD9+AfR4SYs56LU0NPVg6dZ3ArAwk/WpQboaP4Z1CtLPlIX88b91EwwMQRbjKqkvFSRRpJf4hBf4XeAm591a2AONQHmYU95dyqTIo6bA== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2ec2d3e5-b48e-4302-925a-08dcd3f6284b X-MS-Exchange-CrossTenant-AuthSource: AM8PR04MB7779.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Sep 2024 13:15:37.4198 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: YkXy0GJbQfTsiIqt2TAmYJwd8jVGDxl1LTqTGYgM2/nICu/PVO+96EsAj9G5xHZwuwUQT09tZVBTW1ctPtFP4w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR04MB7519 X-Patchwork-Delegate: kuba@kernel.org If complete = true, it means that we are the last switch of the tree which is successfully probing, and we should be setting up all switches from our probe path. After "complete" becomes true, dsa_tree_setup_cpu_ports() or any subsequent function may fail. If that happens, the entire tree setup is in limbo: the first N-1 switches have successfully finished probing (doing nothing), and switch N failed to probe, ending the tree setup process before anything is tangible from the user's PoV. Because the dsa_switch_tree is still technically referenced by the N-1 switches which succeeded in probing but are practically useless, the memory pointing to "dst" and to the dst->rtable is not actually "leaked", it is more like "blocked". However, we could just as well free the dst->rtable, since a subsequent attempt of switch N to probe, for whatever reason, _will_ trigger issues. First, dsa_link_touch() left behind references to ports owned by a now deallocated struct dsa_switch - the one which failed to probe. Second, the dst->rtable will be regenerated anyway by a subsequent probe attempt of switch N. There was no practical problem observed, this is only a result of code analysis. Signed-off-by: Vladimir Oltean --- net/dsa/dsa.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c index 668c729946ea..a543ddaefdd8 100644 --- a/net/dsa/dsa.c +++ b/net/dsa/dsa.c @@ -862,6 +862,16 @@ static void dsa_tree_teardown_lags(struct dsa_switch_tree *dst) kfree(dst->lags); } +static void dsa_tree_teardown_routing_table(struct dsa_switch_tree *dst) +{ + struct dsa_link *dl, *next; + + list_for_each_entry_safe(dl, next, &dst->rtable, list) { + list_del(&dl->list); + kfree(dl); + } +} + static int dsa_tree_setup(struct dsa_switch_tree *dst) { bool complete; @@ -879,7 +889,7 @@ static int dsa_tree_setup(struct dsa_switch_tree *dst) err = dsa_tree_setup_cpu_ports(dst); if (err) - return err; + goto teardown_rtable; err = dsa_tree_setup_switches(dst); if (err) @@ -911,14 +921,14 @@ static int dsa_tree_setup(struct dsa_switch_tree *dst) dsa_tree_teardown_switches(dst); teardown_cpu_ports: dsa_tree_teardown_cpu_ports(dst); +teardown_rtable: + dsa_tree_teardown_routing_table(dst); return err; } static void dsa_tree_teardown(struct dsa_switch_tree *dst) { - struct dsa_link *dl, *next; - if (!dst->setup) return; @@ -932,10 +942,7 @@ static void dsa_tree_teardown(struct dsa_switch_tree *dst) dsa_tree_teardown_cpu_ports(dst); - list_for_each_entry_safe(dl, next, &dst->rtable, list) { - list_del(&dl->list); - kfree(dl); - } + dsa_tree_teardown_routing_table(dst); pr_info("DSA: tree %d torn down\n", dst->index);