Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp2269311rdb; Mon, 5 Feb 2024 00:44:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IG7fotk5+87IY+nTBFiKz3mVy9Ktl3yaOkFj1UcavonJaif7Lr6y8Xx8XEEpkItUxofjsCM X-Received: by 2002:a05:6a21:594:b0:19e:9143:28f3 with SMTP id lw20-20020a056a21059400b0019e914328f3mr1903493pzb.29.1707122679084; Mon, 05 Feb 2024 00:44:39 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707122679; cv=pass; d=google.com; s=arc-20160816; b=K+K4mVQgcm001FiS10U+m0qFLjwBGHQzHm2L6HsLUxpUX8PU9hE6dW0+HEv5aLyvZ8 MLnWiZkEJcpijMwUZ9J3/VlWaGR4rCFcXrONTP8Uu9iaN2joUCXWgmNE+Q5ZYCv8Fuq+ gQNnbWtVxSpvOCRY0AoitxigUlzAJnbZ1SqWmH0dPHyQBD1WmHE1W/22spnVwhad0CU+ r+aMfHjPIPTlD1ts5FdsP/hwm3DVMfvv4bhCo3w4Uq448KmX+KrINqcPipX4UxwxMl7S cEsnlixuRGlYJTJ8aN+ZRcynA8Ehe7kFe7jdQV5Y4JMoMqYjQUOyVWnIgTFncJkJviTX jA5Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=Iy+VphH0iGqy9PDo1m/MbLfZbulXpbRTq8SjaG2pi3s=; fh=5mn/nzB07spTgKdxzhVZC2v0H1BAFddhNePyMYkpRg4=; b=hWRCZQByrFwKZnRflCXYnaH9k5pnuBaaKe9DCumhxGa2IKHUyDL2W0mK//sdryfuqK LLAj7aCFx0LwLfWUe5XOLgLaRN+RlQzjRL172nRmkBXH6RPZoUr2ta7qq1sPBnZ236BI tdtUW6hdcIoo2vzAopHaF2Du06D5O8vcjRNTXvCnVhqUCh/wMqpxHdZ9gI2iMIjUtDCs 2CmOjHdQM662YQOrZe+NT9/5wBRGAoKQ0ljy2dmU9BLLfr1HdSqYf5Xfqn2uyJp1gbWK qa8oeJ5+hEFUCSEva9NT86CZLpXoneYyAyq9n1hq+1f5RZnoK5IbkNFd7w1B2tXMbbxJ yH7w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=iZx2xTHj; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-52221-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-52221-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=1; AJvYcCVImgxDM5+RNowZW5KIdVrVCvkPNL0ydBsG+zOPksoNBkd9R6rMUFFQLqSamMUFe4wVYk7siO95Dm+H355zupEs0pTHW/rfyNWAjSDWuw== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id k68-20020a632447000000b005d8d56cd646si2954153pgk.130.2024.02.05.00.44.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 00:44:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-52221-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=iZx2xTHj; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-52221-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-52221-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.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 sv.mirrors.kernel.org (Postfix) with ESMTPS id B8866281C13 for ; Mon, 5 Feb 2024 08:44:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9EDA011C89; Mon, 5 Feb 2024 08:44:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="iZx2xTHj" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) (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 521BC11705; Mon, 5 Feb 2024 08:44:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.12 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707122669; cv=none; b=PJeom14mH1f6pZKtUlzH16gNNAprFuXAc8mciqZsL8QyciM2Jxmcsr3XHh9bRdl2kh5QVAY+QFGpElSDaCZQJC1EAAznFfSB6GXf51PyXF4WN0qls4wmOZpIwTGun6LV65Ao0VJOX9g4nPe7r0P8L/wrIxT317tlKmSOP8ohZwU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707122669; c=relaxed/simple; bh=GUgIX7042RtSBJu7+ePH48NnTwLvSOMarn6Vwpzc2Wo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=oveUBUrSsSWrdX5ExDXspsbxQL9di2ZYF44M/dG2dMgvpCGGpNTCVoOlUwH+m/m3Ou8crzDi94oShs1tzDRzH65i1vqn6tuUDDQv31x9oJwUEnNfqszPwhtNA0hFHS7mR4zaEuxoYn/BvETofaScDujqGUdbud6WS/CAZL1w7Aw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=iZx2xTHj; arc=none smtp.client-ip=198.175.65.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1707122668; x=1738658668; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=GUgIX7042RtSBJu7+ePH48NnTwLvSOMarn6Vwpzc2Wo=; b=iZx2xTHjS0T2FwOHw/6KDWBJjSPnEeQLDoy2CM7etanZIbF9Blsag/CI p2vGpLXt9AijWjMu41tHFfAh7h8yrnZMquv489sBIiMKTeXeWQJcqbKFE wfCfEK1GyqRuFkAi225Fm3z9FpRduIn+6TsFq55zOImu40Liqh2Vq6tdR i8eCVILdmo4LFaSMnHntFGpTD0NPY2CoHXLWHAEmlLa9UzQctbDkSDjUK HSDFtyKlyUVnNBakZHur4ETdlwdA2PFMSjjVTtQTnfIBym+F7zUWmYpBN vZzw32JQtR3xz+cFzU4zdIevCXKrDoZQzp74OmFUJ0cwen4hultrFNrwc g==; X-IronPort-AV: E=McAfee;i="6600,9927,10974"; a="11833702" X-IronPort-AV: E=Sophos;i="6.05,242,1701158400"; d="scan'208";a="11833702" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Feb 2024 00:44:27 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10974"; a="823808641" X-IronPort-AV: E=Sophos;i="6.05,242,1701158400"; d="scan'208";a="823808641" Received: from unknown (HELO mev-dev) ([10.237.112.144]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Feb 2024 00:44:24 -0800 Date: Mon, 5 Feb 2024 09:44:16 +0100 From: Michal Swiatkowski To: Horatiu Vultur Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, UNGLinuxDriver@microchip.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH net] lan966x: Fix crash when adding interface under a lag Message-ID: References: <20240205080756.2134143-1-horatiu.vultur@microchip.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240205080756.2134143-1-horatiu.vultur@microchip.com> On Mon, Feb 05, 2024 at 09:07:56AM +0100, Horatiu Vultur wrote: > 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; Why not bond = port->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 > Only nit, otherwise: Reviewed-by: Michal Swiatkowski Thanks, Michal