[RFC PATCH net-next 07/11] net: dsa: microchip: lan937x: update switch register

From: Rakesh Sankaranarayanan
Date: Thu Feb 02 2023 - 07:59:43 EST


Second switch in cascaded connection doesn't have port with macb
interface. dsa_switch_register returns error if macb interface is
not up. Due to this reason, second switch in cascaded connection will
not report error during dsa_switch_register and mib thread work will be
invoked even if actual switch register is not done. This will lead to
kernel warning and it can be avoided by checking device tree setup
status. This will return true only after actual switch register is done.

Signed-off-by: Rakesh Sankaranarayanan <rakesh.sankaranarayanan@xxxxxxxxxxxxx>
---
drivers/net/dsa/microchip/ksz_common.c | 10 ++++++++++
1 file changed, 10 insertions(+)

diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c
index 2160a3e61a5a..0df71156a540 100644
--- a/drivers/net/dsa/microchip/ksz_common.c
+++ b/drivers/net/dsa/microchip/ksz_common.c
@@ -3213,6 +3213,7 @@ int ksz_switch_register(struct ksz_device *dev)
{
const struct ksz_chip_data *info;
struct device_node *port, *ports;
+ struct dsa_switch_tree *dst;
phy_interface_t interface;
unsigned int port_num;
int ret;
@@ -3330,6 +3331,15 @@ int ksz_switch_register(struct ksz_device *dev)
return ret;
}

+ /* Do not proceed further if device tree setup is not done.
+ * dsa_register_switch() will not report error in case of
+ * cascaded switch. This will lead to scheduling mib read
+ * work and kernel warning.
+ */
+ dst = dev->ds->dst;
+ if (!dst->setup)
+ return 0;
+
/* Read MIB counters every 30 seconds to avoid overflow. */
dev->mib_read_interval = msecs_to_jiffies(5000);

--
2.34.1