Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp2258134rdb; Mon, 5 Feb 2024 00:11:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IHmYdsxO+pYPCT21ml6Y1GyhAdxhmQQOMzRNOrIgfybD/4ZWyUEh5FDU2+L6WrGMzirVnb6 X-Received: by 2002:a05:620a:22b8:b0:785:554e:e973 with SMTP id p24-20020a05620a22b800b00785554ee973mr9136710qkh.65.1707120666426; Mon, 05 Feb 2024 00:11:06 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707120666; cv=pass; d=google.com; s=arc-20160816; b=k+5uCXFhUt1/ATs3nDKVcLUUiui3CzBBeGe2fLTEUo3yf21Kd4iiqO0dGy+KCrHH11 2l5UAa0HMpRDZyJ3ScNXL+TdR0lFpqdZL11rPPTDM4V3tzhY7qS1l8Ad7/R6eZu7ul9G 0gviqLn5KX9Q7aQO9necxWAjFgtN6E/eSIhcLKLXWQnVPCNXagMzq6m6nrLMgRj+OjZP z7p5tKW5zDKFWluC/94iaKvKKZNbvabyo26Q2aY2Uo3wRMSVaOlSwMZoh2NcNDDEIcJK YgjS4L3B/guFHAXZT7i6r2KLOxAH7AC0p+sadngL+Gmdxwjq53XhcZQYuncDn1tNWXBD dLwQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=WG1cETT9VcCHe/jZl6le2g7sqNkJZ5Q9kSLmAOcGHWU=; fh=1pJRNwcdEi2IsOhhc2ZhgHdwXP7nwDU9xT4Ygc5zSGU=; b=Sx6ZHojqXKIV5eDypQ4aoPxLKId6f0lHRTczMnQomUH0TRnzWDHFBy/mtdCiHfRyKX qgBRUAEKT93FMMLeK+U8VFSW3n+D/naBC0gKJljWnH+Zk6uv4ytkTo5pwgMSv1/99STW dFJyry2IvWP2K+IDBPokSsRY8ti1KCIfxXzPRb0kElk5e0iKGRoe44RNTVcAk1yhjJ9Y Zt9lcFemATzzRQzqh3ShrlIPMCZnK7EUehF/1I6w+wW2UPGUnyN6eQ/ueooNEW3RwCVT EyfYb0coYLlwMeImyjQkJzMKXKQ9JMrc+LnhFYDc/ZQTPa62SxNtQUSgdFWI02VO4NJl 4IhA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=me72vfHR; arc=pass (i=1 spf=pass spfdomain=microchip.com dkim=pass dkdomain=microchip.com dmarc=pass fromdomain=microchip.com); spf=pass (google.com: domain of linux-kernel+bounces-52190-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-52190-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=REJECT dis=NONE) header.from=microchip.com X-Forwarded-Encrypted: i=1; AJvYcCX31QxfClbtlTog01R+8tEPe6emC3NT6SDdFftiIuX8zKr93DWhXxY+bWzsRim3j1Sym1S6opKR5ipLFzMEw8K65zwQdy9lmcD6UwYCeA== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id d24-20020a05620a205800b00783aa61af29si7540399qka.526.2024.02.05.00.11.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 00:11:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-52190-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=me72vfHR; arc=pass (i=1 spf=pass spfdomain=microchip.com dkim=pass dkdomain=microchip.com dmarc=pass fromdomain=microchip.com); spf=pass (google.com: domain of linux-kernel+bounces-52190-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-52190-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=REJECT dis=NONE) header.from=microchip.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 309491C229FA for ; Mon, 5 Feb 2024 08:11:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3E4D2111AD; Mon, 5 Feb 2024 08:10:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b="me72vfHR" Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) (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 C419B11CA9; Mon, 5 Feb 2024 08:10:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.154.123 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707120652; cv=none; b=mRLnFeR1u7k9A0LPZwMT0ougQVL9HA4+kyDZm3WQS89wJdmcORqUNhZ3DX9TDqoric7jOFH6G1cK4FPAEtUdBUwY5mGPVUF8di+fe0wOv9YfR+0aB4kG/6p0XJfnLik9NFZQBzrVyjNCQru3rMFE+Oa2fhjEhJIpyeixjFwyYHc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707120652; c=relaxed/simple; bh=3ucSGTFs8one78Y6iL+BGkNxpmGL9+cLmwl64Uax07E=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=bvYe3ILkGWJcoEw8PwfAVbdJ8JtZlspa4VO/cjTK5waFkp8YEwzejOnEFwa+ublexsDJKK/4TYf8TzFsDkpID/5scK6TLkINMY7fbZF8uXdvaubXJX3X2TWwM2Mn8legB0pXb2UPK8O+H2qI3cZseVpO7joBMZfeeWZnqbN6/Qs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=microchip.com; spf=pass smtp.mailfrom=microchip.com; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b=me72vfHR; arc=none smtp.client-ip=68.232.154.123 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=microchip.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=microchip.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1707120650; x=1738656650; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=3ucSGTFs8one78Y6iL+BGkNxpmGL9+cLmwl64Uax07E=; b=me72vfHRYTxo9UtdkkseLaJHowhHB/L3p3dVK9MhyIZlvsvh5SrzjSqb uh++atguJbY7DxMvyLSLattn908pY7DRDndkKnEdyf3JWKYp4u9PU7iRZ U60bk6RfaYWetBovGPhJekpUO/w4tGFF7KYc4DwQVpvRr62YWjZ9FwklD DrzqTtWCLnvj4Wmeoo/uv2VLnVB/pkReJ2H2ohzKp79DWOVGmjjFFCzlC SBcTloNkw6epx6XSlZxSXf9cnRuUoMFPV283WXa9LFHy29T3TuB6/P60i E52PT+UnGcRsFg/ppkyQeQPUAdvrx1TEeUZ+RPmVUiE+4HlbuDjtoUs8+ Q==; X-CSE-ConnectionGUID: G0jFP2bBRLutVp1LQAF9Lw== X-CSE-MsgGUID: +XWcqZs0QeGrs5xxSawVBA== X-IronPort-AV: E=Sophos;i="6.05,242,1701154800"; d="scan'208";a="183027790" X-Amp-Result: SKIPPED(no attachment in message) Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa6.microchip.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 05 Feb 2024 01:10:49 -0700 Received: from chn-vm-ex01.mchp-main.com (10.10.85.143) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Mon, 5 Feb 2024 01:10:29 -0700 Received: from DEN-DL-M31836.microsemi.net (10.10.85.11) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server id 15.1.2507.35 via Frontend Transport; Mon, 5 Feb 2024 01:10:28 -0700 From: Horatiu Vultur To: , , , , CC: , , Horatiu Vultur Subject: [PATCH net] lan966x: Fix crash when adding interface under a lag Date: Mon, 5 Feb 2024 09:07:56 +0100 Message-ID: <20240205080756.2134143-1-horatiu.vultur@microchip.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain There is a crash when adding one of the lan966x interfaces under a lag interface. The issue can be reproduced like this: ip link add name bond0 type bond miimon 100 mode balance-xor ip link set dev eth0 master bond0 The reason is because when adding a interface under the lag it would go through all the ports and try to figure out which other ports are under that lag interface. And the issue is that lan966x can have ports that are NULL pointer as they are not probed. So then iterating over these ports it would just crash as they are NULL pointers. The fix consists in actually checking for NULL pointers before accessing something from the ports. Like we do in other places. Fixes: cabc9d49333d ("net: lan966x: Add lag support for lan966x") Signed-off-by: Horatiu Vultur --- drivers/net/ethernet/microchip/lan966x/lan966x_lag.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_lag.c b/drivers/net/ethernet/microchip/lan966x/lan966x_lag.c index 41fa2523d91d3..89a2c3176f1da 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_lag.c +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_lag.c @@ -37,19 +37,24 @@ static void lan966x_lag_set_aggr_pgids(struct lan966x *lan966x) /* Now, set PGIDs for each active LAG */ for (lag = 0; lag < lan966x->num_phys_ports; ++lag) { - struct net_device *bond = lan966x->ports[lag]->bond; + struct lan966x_port *port = lan966x->ports[lag]; int num_active_ports = 0; + struct net_device *bond; unsigned long bond_mask; u8 aggr_idx[16]; - if (!bond || (visited & BIT(lag))) + if (!port || !port->bond || (visited & BIT(lag))) continue; + bond = lan966x->ports[lag]->bond; bond_mask = lan966x_lag_get_mask(lan966x, bond); for_each_set_bit(p, &bond_mask, lan966x->num_phys_ports) { struct lan966x_port *port = lan966x->ports[p]; + if (!port) + continue; + lan_wr(ANA_PGID_PGID_SET(bond_mask), lan966x, ANA_PGID(p)); if (port->lag_tx_active) -- 2.34.1