Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp2681521lqz; Wed, 3 Apr 2024 05:51:16 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW9Nm7UUzygXUL0+CwCy69uXfuGNcszwGFCsr5/AIKPMaiPrMwTwKoma/o5PFHh4kzEeZ+BI2sQ7GdS9Z8YksExeHRoxLFhAqDqJTifrg== X-Google-Smtp-Source: AGHT+IFY9GbSP9EKM1UJ0EU91Fqep85awJ0UWjFOjdvN8NYD2vIrDatbEU4UA9ygCtcIil4uP49z X-Received: by 2002:a17:906:29c3:b0:a4e:8ac4:3c3a with SMTP id y3-20020a17090629c300b00a4e8ac43c3amr1814340eje.48.1712148676446; Wed, 03 Apr 2024 05:51:16 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712148676; cv=pass; d=google.com; s=arc-20160816; b=aVicwSVcSXgolAs4AvOwpMwUAp61WC2dZ/f06Yb143x0Af3RCFaOgaZiYppBJ4o90e iojGY9o5CMVfQfnT/cPXNB6CL012u8dKnTq1Gh73rXB6I6lM1cIgKmm9HTee4koURt5I VjKcJO+VE7XP8i1rhIDCdvY2xjTSJoSQCLW2Tv9v2LJeAFEnQrHN3b91T5K6JPzhVpj5 1rAf7MH9MZZEn3qHpBVHjUXNVhz0YOBVPNkeDWB4bFT79lVEEcHT1OJnK+cUuT/Zzb7+ 1cYFJofJgqvvwRVaaPP/M6sdeeHAEqFulPAa8BcqwTRuv0emtds0tjgfQPK7trkbjnZc 09NA== 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:references:in-reply-to:message-id :date:subject:cc:to:from; bh=PVQIE4YfvU9HRAc/+FOB9I86HdxkqiQdQ4eDzruQAyE=; fh=+wuPl0jVtcYGOKyQ4dCrYwpLO51Md4SLm1XlQV1l1VE=; b=ygTqFeDTxkkE8f5S1CyhNuzwg0LJeB6it9gJCQBYMSz0862th8mItkhYzXcSzYa/R1 bwtra/stGe3hUxdNl6g3O4WXpGJRhCdVQg1jBECIsHOQjX0lElEyq/gf68RTydhWjUJz 6uzkJp82T25Gq/gpl2p2js1eA6i/fu20r1i7zVTwLwAMWCJZnIcNnChz438Q3wJCT5V8 4kz+DMx5LeUzvlx/ydHEi9cIESC30Yboo05n8XdWNmqeDDp1UZGmiWtLdNVFbV05aM9w jFeR0YpDH7+3SMoOnJnZtVymqTymRa58KVksLeHQIXcOoe1TbsK/wj8WStwsYBxxCc5x D4bQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=pengutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-129740-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-129740-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id y17-20020a17090668d100b00a4e876843f4si1810791ejr.542.2024.04.03.05.51.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 05:51:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-129740-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=pengutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-129740-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-129740-linux.lists.archive=gmail.com@vger.kernel.org" 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 259B01F286DF for ; Wed, 3 Apr 2024 12:51:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D2F42148302; Wed, 3 Apr 2024 12:50:53 +0000 (UTC) Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (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 69624146D4A for ; Wed, 3 Apr 2024 12:50:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712148653; cv=none; b=gCZ/r45IC9OtahvUjmZPOeQpmaRQnQuNGaGgOcXyZKE1DWGSXjcIiW772aaJcM3jBqetFSA5cVjJQO8lcl9G12i2DwH4rfgOo+ILj9IvGBSRIH7Dre8P/fSX5fIdNP348/Ap6j9zgsMC4bWIzJamai9dMejeBr/98JST64iOeT0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712148653; c=relaxed/simple; bh=f1wmLifa3arJQ/tA8IkHxFJBOXYe1/TIZAQD6djffYg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=eq9cvfWtDwrTvYUlNz+v54uKD785tPAHVQiplVspKH0tqLnjpFTIvoeNEcpVeeI1rYYNZAd50TlJpwKRprFgyAqa7QXIIUYWGtHo5XgYDsYL3omQDErQeS6K7BCtBeURGm85CU0MzhcVg5cGIUMQ+JfGAESa9kcUCtYiCUSYEbU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rs04h-0005w0-0Z; Wed, 03 Apr 2024 14:50:43 +0200 Received: from [2a0a:edc0:0:1101:1d::ac] (helo=dude04.red.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rs04f-00ABEZ-1R; Wed, 03 Apr 2024 14:50:41 +0200 Received: from ore by dude04.red.stw.pengutronix.de with local (Exim 4.96) (envelope-from ) id 1rs04e-00EKXN-2l; Wed, 03 Apr 2024 14:50:40 +0200 From: Oleksij Rempel To: "David S. Miller" , Andrew Lunn , Eric Dumazet , Florian Fainelli , Jakub Kicinski , Paolo Abeni , Vladimir Oltean , Woojung Huh , Arun Ramadoss Cc: Oleksij Rempel , kernel@pengutronix.de, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, UNGLinuxDriver@microchip.com, =?UTF-8?q?S=C3=B8ren=20Andersen?= Subject: [PATCH net-next v2 3/8] net: dsa: microchip: ksz8: Refactor ksz8_fdb_dump() Date: Wed, 3 Apr 2024 14:50:34 +0200 Message-Id: <20240403125039.3414824-4-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240403125039.3414824-1-o.rempel@pengutronix.de> References: <20240403125039.3414824-1-o.rempel@pengutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Refactor ksz8_fdb_dump() to address potential issues: - Limit the number of iterations to avoid endless loops. - Handle error codes returned by ksz8_r_dyn_mac_table(), with an exception for -ENXIO when no more dynamic entries are detected. Reviewed-by: Vladimir Oltean Signed-off-by: Oleksij Rempel --- changes v2: - move variable declaration out of "for" scope - rework "if (port != src_port); continue" to to "if (port == src_port); code" --- drivers/net/dsa/microchip/ksz8795.c | 29 ++++++++++++++----------- drivers/net/dsa/microchip/ksz8795_reg.h | 1 + 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz8795.c b/drivers/net/dsa/microchip/ksz8795.c index e407111db6637..c93eb351ab3d5 100644 --- a/drivers/net/dsa/microchip/ksz8795.c +++ b/drivers/net/dsa/microchip/ksz8795.c @@ -1191,27 +1191,30 @@ void ksz8_flush_dyn_mac_table(struct ksz_device *dev, int port) int ksz8_fdb_dump(struct ksz_device *dev, int port, dsa_fdb_dump_cb_t *cb, void *data) { - int ret = 0; - u16 i = 0; - u16 entries = 0; - u8 fid; - u8 src_port; u8 mac[ETH_ALEN]; + u8 src_port, fid; + u16 entries = 0; + int ret, i; - do { + for (i = 0; i < KSZ8_DYN_MAC_ENTRIES; i++) { ret = ksz8_r_dyn_mac_table(dev, i, mac, &fid, &src_port, &entries); - if (!ret && port == src_port) { + if (ret == -ENXIO) + return 0; + if (ret) + return ret; + + if (i >= entries) + return 0; + + if (port == src_port) { ret = cb(mac, fid, false, data); if (ret) - break; + return ret; } - i++; - } while (i < entries); - if (i >= entries) - ret = 0; + } - return ret; + return 0; } static int ksz8_add_sta_mac(struct ksz_device *dev, int port, diff --git a/drivers/net/dsa/microchip/ksz8795_reg.h b/drivers/net/dsa/microchip/ksz8795_reg.h index 7c9341ef73b03..0d13a6e29b0e6 100644 --- a/drivers/net/dsa/microchip/ksz8795_reg.h +++ b/drivers/net/dsa/microchip/ksz8795_reg.h @@ -794,5 +794,6 @@ #define TAIL_TAG_LOOKUP BIT(7) #define FID_ENTRIES 128 +#define KSZ8_DYN_MAC_ENTRIES 1024 #endif -- 2.39.2