From nobody Mon Feb 9 16:36:12 2026 Received: from out162-62-57-252.mail.qq.com (out162-62-57-252.mail.qq.com [162.62.57.252]) (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 4032D26FD97 for ; Thu, 25 Dec 2025 20:38:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=162.62.57.252 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766695088; cv=none; b=S663J3DoLolXXTRn8aPTZnxbuM3ZOFKjBvwJBn8uj4TR2pBcTygEmdGnQavj8iy5ltTGrcaJ9Cra54WXmaWrqhceKkpMw2NFNP1YrvCcH8MQUAbeWoEvLmwk7H7zEEiY9V1OW1Z6rbTZ5zopHuIXNxxrLH+oqlxMHYJ5Hf10OIE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766695088; c=relaxed/simple; bh=WwlEOAr1t6ductPkmsXqGNb2jZ3SbztP5QxHrDM2z9o=; h=Message-ID:From:To:Cc:Subject:Date:In-Reply-To:References: MIME-Version; b=AOJUfBlP6wFB9bVqUlGO/6i9eLHUYkx+CvdGobgcjjf2HDoeTfBdcmvARQ7UpFBX662V7wk7pCv/UFGbBDjNicn15cdGOcpumCyocDYyRGayMIUvYbM3a3ItTOujjFLeJvDkEyRdpkJCE53aIdb4+Gl2Ye40ocfdemyVDfc5N4o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=foxmail.com; spf=pass smtp.mailfrom=foxmail.com; dkim=pass (1024-bit key) header.d=foxmail.com header.i=@foxmail.com header.b=vLkAdW3m; arc=none smtp.client-ip=162.62.57.252 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=foxmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=foxmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=foxmail.com header.i=@foxmail.com header.b="vLkAdW3m" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1766695075; bh=3xKQ5QKGOtFosXXsFS4kNKY9y6GjUouDkstUkEJnWAE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=vLkAdW3mrSwFLquLP/ULGvZIK3TutaXKgWwP425nZVUdL3ofipgW9BT/DixNf2wop EydJSrq3O+vrjQa4qKXFkWr3hntCyKufuj4khrCjfpg8rdeepK6i4Ivjpjz3TCCkyy 2B+kzRZn1Ys8VhVH79iJTWKeynzH+7QPJ7V9DSUw= Received: from 7erry.customer.ask4.lan ([31.205.230.119]) by newxmesmtplogicsvrsza63-0.qq.com (NewEsmtp) with SMTP id 92399661; Fri, 26 Dec 2025 04:36:35 +0800 X-QQ-mid: xmsmtpt1766694995tzuk8mnx0 Message-ID: X-QQ-XMAILINFO: NQp/UN4soYLTTuGP/agmWdwX9ssNAYBVQ/mWH1aB2n4ElujSIood7fUZGWerUr ug8+kKgzmo/WY7NQ3o1rR7pLlQYW0k0G+OwquC6BOuWyRoh+Rdq8e4EWX5+JsQpOL6AihXw6N6nF Yfh9fOqgiajWcXzcpsxE2RuKLi+0GDQ2qgkBttjQTxpzCMhJMRfsoXxmWmwnYoQMBHfIDlVsNu+s nhSw59yvtpickN5jjMUJ68FvAPV4K12uAZl3Udg9Y0NggaewlE9XKibDGNmfba5yqoaOuiTdwhVp IxN2hCnABWY1UnBhdLwjkJheyTxW0aEYas05Ss+/TOLXsC7ukVRKnBHFnC0tnQjQ8+WipwgTJ5Sm QNMUho1qQJCmXFyYtHPjQm8LNoTXK73LkVrJKz6aRbfZ2O9y8zNnKC/sa9zmJK6O11Lz8Io1yyOe jrz1ID4udtrd1DwZv3JFcPd4fCyQ0b3B8pvifhNiP6+YbGZqXlFhzFOPCivc7z3kySrXtQaUZIwC aMjmU2eNYV4O5s77UQcd+q6wI/8knyib7SLei79LMBERlmYr7l7FDS2CjdTzDsU7/gLxESd+/pYd 14Daea5R06TCPpohkBzksFkEof3NdiBz9SExAq6HgLx6o1F1RHdOFYv4XCsI0GCJbx2geTdGqLXo DtVBNSMoo/rwr1vfahZ7rNN6KqAebjlE5QcVZqbBMq+AlhAVnkYPdp7HPMgE/NFGmYRXCMEujoKp GRFFh+Zol4iUamstXVZBKkmFUM2YRQqNOvhK11G0m1AQLc/XrqrmQp5yqo6AtQN8iACyusklSfow 0ifD+A1wk06el/NQNHTjDR8Iy7PcJy21MCV4HMmt9lG1DdF88MZIRYeyLJmK/ckxNlBLGRF2olfr RBsb/hoeVC0zYgnj377ovOKP3TJU8t+q+MxP9lOizBJi1OAowoBd6hLc/6CU7DfTnnNrsyMZC7zn ucbxz54Fe3itDi7NzJbEc37HnzuEWwZxmjhK1gFdz+cxLfxo5N0prHGm9RALqx5K0lnz8akWpDeb XFCwO4xynXaL2Ff2mQot07V65vVNmq8xBlEjVFu4rsFAMLEb0nmVBffm8gCywDdrMqToU6YA== X-QQ-XMRINFO: NI4Ajvh11aEjEMj13RCX7UuhPEoou2bs1g== From: Jerry Wu To: vladimir.oltean@nxp.com Cc: UNGLinuxDriver@microchip.com, alexandre.belloni@bootlin.com, andrew+netdev@lunn.ch, christophe.jaillet@wanadoo.fr, claudiu.manoil@nxp.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, pabeni@redhat.com, w.7erry@foxmail.com Subject: [PATCH net v3] net: mscc: ocelot: Fix crash when adding interface under a lag Date: Thu, 25 Dec 2025 20:36:17 +0000 X-OQ-MSGID: <20251225203617.13034-1-w.7erry@foxmail.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20251220210808.325isrbvmhjp3tlg@skbuf> References: <20251220210808.325isrbvmhjp3tlg@skbuf> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Commit 15faa1f67ab4 ("lan966x: Fix crash when adding interface under a lag") fixed a similar issue in the lan966x driver caused by a NULL pointer derefe= rence. The ocelot_set_aggr_pgids() function in the ocelot driver has similar logic and is susceptible to the same crash. This issue specifically affects the ocelot_vsc7514.c frontend, which leaves unused ports as NULL pointers. The felix_vsc9959.c frontend is unaffected as it uses the DSA framework which registers all ports. Fix this by checking if the port pointer is valid before accessing it. Fixes: 528d3f190c98 ("net: mscc: ocelot: drop the use of the "lags" array") Signed-off-by: Jerry Wu Reviewed-by: Vladimir Oltean --- v3: - Resending the correct version that compiles properly. - Retained the 'bond' variable as confirmed necessary in discussion with = Vladimir Oltean. - Added links to previous versions as requested. - Thanks to the reviewers for the gentle and detailed feedback and guidan= ce. v2: https://lore.kernel.org/netdev/20251220210808.325isrbvmhjp3tlg@skbuf/T/ - Addressed comments from v1 regarding variable name and null checking. - Sent by accident as a draft. v1: https://lore.kernel.org/lkml/20251220180113.724txltmrkxzyaql@skbuf/T/ - Try to fix the crash in the same way as previous patch did but failed f= or - improper variable name that is shadowing the "int port" definition. - unnecessary and incorrect hunk for null checking. - improper commit commit title. drivers/net/ethernet/mscc/ocelot.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/mscc/ocelot.c b/drivers/net/ethernet/mscc= /ocelot.c index 08bee56aea35..c345d9b17c89 100644 --- a/drivers/net/ethernet/mscc/ocelot.c +++ b/drivers/net/ethernet/mscc/ocelot.c @@ -2307,14 +2307,16 @@ static void ocelot_set_aggr_pgids(struct ocelot *oc= elot) =20 /* Now, set PGIDs for each active LAG */ for (lag =3D 0; lag < ocelot->num_phys_ports; lag++) { - struct net_device *bond =3D ocelot->ports[lag]->bond; + struct ocelot_port *ocelot_port =3D ocelot->ports[lag]; int num_active_ports =3D 0; + struct net_device *bond; unsigned long bond_mask; u8 aggr_idx[16]; =20 - if (!bond || (visited & BIT(lag))) + if (!ocelot_port || !ocelot_port->bond || (visited & BIT(lag))) continue; =20 + bond =3D ocelot_port->bond; bond_mask =3D ocelot_get_bond_mask(ocelot, bond); =20 for_each_set_bit(port, &bond_mask, ocelot->num_phys_ports) { --=20 2.52.0