From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796495383; b=3aAJNSy/a5BAP+T5e7kZXajf611fzU9dYW1gDx6N/NiFXnWQYh592q0XkMszyLhZi6FI mU7Zu444qGYVOPmy9vLVbKBatElgc5jCm3/f1nPd2k4Nlbqw15powoGQA7l3wZjPtDQhu WHdKADXRcePZvk3ZJMAYCRy6ElWP144MLGurwvAwLVujBdrN1A8TTeizPbF4cLhJPAxKi YDaUq1XdbGj2cqgODEXJJL3DP/8Ow307ZPUG51g9EF3WHRU+PUUbKR5AgNuwnjidVnRDt j0/Tpx5vBziw+EN6z8vFTIVANZhgVALzKtpnoRwrwnNYDOgaPIuK7T7zOsQFDR7T0kw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796495383; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=lffvz0KhOix4StDdAJ+3/JCXaa8hIjxQkEYdaplAWlE=; b=rq0SsbzG9WmfwjYZdHdm96bk+yQGvoT9PMzyOgNFIRGoJYEHmGliyc3QJo/Xx/+ckngt TslfWIVpqa0/FUBU98x7a3vHWoXtZ0j/rJMPk8B4YyXms9FKVC6PIXUmEOwPNj/iUR/v5 CApQYojmpVg8A4zj2WcxwyQEnhcSFn6xI4pWvIjNO2ToGel6VKJBvI+lU7CaRrKoSDv1b ZtWnnyjiT2Bucj5n5B66vATrmY8EOChRAZbjaYRPxE9iV5iE5bicj7EAgy0FHlvGbAoCv 7nm8DMULLj6zh13++D+jQRIyHM0K8P4ox09l9y3WmPi7pAiz/HGrJ5DqHKHVZQ5f6Ww== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=AeiJWpQS; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BE9DB606A332 for ; Sat, 5 Dec 2026 18:29:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=AeiJWpQS Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6932D1F00A07; Sat, 5 Dec 2026 18:29:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796495383; bh=lffvz0KhOix4StDdAJ+3/JCXaa8hIjxQkEYdaplAWlE=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=AeiJWpQSUAMXauWHbg2cQ19qzSqbEftsJQHDHCGXy6glH96gnvSnz5mHOMi2+9Wi+ 27Xeg9DeXpIFfvildAyU0gtai2HtGGHhHJcQ5icWJ4fmz7LeLEaxtWpRZSB+RnNRQF hF8uHifhKVfgd6fEKRPfhng10Ym7dfkWRYGywXFHgTxp4CpMQxLIU2AHezvRUwZIfS V1q5KpoHubdQxeX/I6Nor8q5cYJlcHEXUUwOLYTUvqYkYwvbVDvZxugljoAM6UrdrR OwKgf9NpQriKcKJMPLFdoh8KFFUtmTMYNTRF6dGNCpM0ce4vjRX9SGuPycX5dwTU8l +94BMfANUsofw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [RFC PATCH net-next 4/6] net: dsa: realtek: add support for RTL9607C switch Reply-To: sashiko-reviews@lists.linux.dev To: "Rustam Adilov" , devicetree@vger.kernel.org Cc: robh@kernel.org, conor+dt@kernel.org In-Reply-To: <20261204182553.33952-5-adilov@disroot.org> References: <20261204182553.33952-1-adilov@disroot.org> <20261204182553.33952-5-adilov@disroot.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 05 Dec 2026 18:29:43 +0000 X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 14 potential issues to consider: - [High] net: dsa: realtek: Kconfig selects nonexistent NET_DSA_TAG_RTL8_4AP - [High] net: dsa: realtek: ev_err() typo in rtl83xx_probe() breaks compilation - [High] net: dsa: tag_rtl8_4: undefined protocol macro and rcv callback break build - [Medium] net: dsa: realtek: rtl9607c_irq_setup() frees unrequested IRQ on error - [Medium] net: dsa: realtek: rtl9607c duplicates standard stats in ethtool -S - [Medium] net: dsa: realtek: wrong regmap_set_bits() for 4-bit CHIP_INFO_EN - [Medium] net: dsa: realtek: missing Clause 22 regnum check in rtl9607c PHY ops - [Medium] net: dsa: realtek: CPU port 7 lacks phylink caps in rtl9607c driver - [Medium] net: dsa: realtek: unchecked regmap_read() leaks stack val in MIB reads - [Medium] net: dsa: realtek: u64 underflow in rtl9607c_get_mac_stats() read order - [Medium] net: dsa: realtek: non-forced regmap_set_bits() in rtl9607c_port_mib_reset() - [Medium] net: dsa: realtek: unguarded 64-bit MIB reads in rtl9607c_mib_counter_read() - [Low] net: dsa: realtek: rtl9607c_irq_teardown() leaves hardware IRQs enabled - [Low] net: dsa: realtek: struct rtl9607c kernel-doc lists nonexistent page field -- commit 331bdac5ba13a62d7d2a46f0ba6f31d9309cb63f Author: Rustam Adilov net: dsa: realtek: add support for RTL9607C switch This commit adds a Realtek MMIO DSA switch driver for the embedded RTL9607C switch, supporting chip detection, internal PHY MDIO access, cascaded link interrupts, STP state, port isolation, MTU configuration, and port MIB statistics. > diff --git a/drivers/net/dsa/realtek/Kconfig b/drivers/net/dsa/realtek/Kc= onfig > index aa4955fef4aa9..d38a434ec834b 100644 > --- a/drivers/net/dsa/realtek/Kconfig > +++ b/drivers/net/dsa/realtek/Kconfig > @@ -57,4 +57,11 @@ config NET_DSA_REALTEK_RTL8366RB_LEDS > depends on NET_DSA_REALTEK_RTL8366RB > default NET_DSA_REALTEK_RTL8366RB > =20 > +config NET_DSA_REALTEK_RTL9607C > + tristate "Realtek RTL9607C embedded switch driver" > + depends on NET_DSA_REALTEK_MMIO > + select NET_DSA_TAG_RTL8_4AP > + help > + Select to enable support for Realtek RTL9607C embedded switch. [Severity: High] Should this select NET_DSA_TAG_RTL8_4 instead of NET_DSA_TAG_RTL8_4AP? NET_DSA_TAG_RTL8_4AP is not defined anywhere in the tree, while net/dsa/Kconfig defines NET_DSA_TAG_RTL8_4 to build tag_rtl8_4.o containing DSA_TAG_PROTO_RTL8_4AP. Selecting the nonexistent symbol emits a Kconfig warning and leaves the tagger unbuilt unless enabled separately, causing dsa_register_switch() to fail at runtime. > diff --git a/drivers/net/dsa/realtek/rtl9607c_main.c b/drivers/net/dsa/re= altek/rtl9607c_main.c > new file mode 100644 > index 0000000000000..5d5633c544bb4 > --- /dev/null > +++ b/drivers/net/dsa/realtek/rtl9607c_main.c [ ... ] > +static const struct rtl9607c_mib_counter rtl9607c_mib_counters[] =3D { > + MIB_DESC(RTL9607C_ETHER_STATS_TX_MULTICAST_PKTS, 1, "etherStatsTxMultic= astPkts"), > + MIB_DESC(RTL9607C_ETHER_STATS_TX_BROADCAST_PKTS, 1, "etherStatsTxBroadc= astPkts"), > + MIB_DESC(RTL9607C_ETHER_STATS_TX_UNDERSIZE_PKTS, 1, "etherStatsTxUnders= izePkts"), > + MIB_DESC(RTL9607C_ETHER_STATS_TX_OVERSIZE_PKTS, 1, "etherStatsTxOversiz= ePkts"), > + MIB_DESC(RTL9607C_ETHER_STATS_COLLISIONS, 1, "etherStatsCollisions"), > + MIB_DESC(RTL9607C_IF_OUT_DISCARDS, 1, "ifOutDiscards"), > + MIB_DESC(RTL9607C_DOT1D_TP_PORT_IN_DISCARDS, 1, "dot1dTpPortInDiscards"= ), > + MIB_DESC(RTL9607C_ETHER_STATS_DROP_EVENTS, 1, "etherStatsDropEvents"), > + MIB_DESC(RTL9607C_ETHER_STATS_CRC_ALIGN_ERRORS, 1, "etherStatsCrcAlignE= rrors"), > +}; [Severity: Medium] Should these counters be removed from ethtool -S where standard uAPI interfaces already exist? etherStatsCollisions, ifOutDiscards, and etherStatsDropEvents are already reported through rtnl_link_stats64 in rtl9607c_get_stats64(), and etherStatsCrcAlignErrors, etherStatsTxMulticastPkts, and etherStatsTxBroadcastPkts also map to standard rtnl_link_stats64 or ethtool_eth_mac_stats counters. Per Documentation/networking/statistics.rs= t, ethtool -S is reserved for driver-private statistics without a standard representation. [ ... ] > +/** > + * struct rtl9607c - driver private data > + * @priv: pointer to parent realtek_priv data > + * @irq: registered IRQ or zero > + * @chip_info: chip-specific info about the attached switch > + * @page: phy page > + * > + * Private data for this driver. > + */ > +struct rtl9607c { > + struct realtek_priv *priv; > + int irq; > + const struct rtl9607c_chip_info *chip_info; > +}; [Severity: Low] The kernel-doc comment documents a nonexistent @page member, which triggers a W=3D1 scripts/kernel-doc warning. The RTL9607C_PAGE_SELECT macro at the top of the file is also unused. [ ... ] > +static int rtl9607c_phy_read(struct realtek_priv *priv, int phy, int reg= num) > +{ > + u32 ocp_addr; > + u16 val; > + int ret; > + > + if (phy > RTL9607C_PHYADDRMAX) > + return -EINVAL; > + > + ocp_addr =3D RTL9607C_PHY_OCP_ADDR_PHYREG_BASE + regnum * 2; [ ... ] > +static int rtl9607c_phy_write(struct realtek_priv *priv, int phy, int re= gnum, > + u16 val) > +{ > + u32 ocp_addr; > + int ret; > + > + if (phy > RTL9607C_PHYADDRMAX) > + return -EINVAL; > + > + ocp_addr =3D RTL9607C_PHY_OCP_ADDR_PHYREG_BASE + regnum * 2; [Severity: Medium] Should rtl9607c_phy_read() and rtl9607c_phy_write() reject Clause 22 regnum values greater than 31? SIOCGMIIREG and SIOCSMIIREG forward an unmasked 16-bit reg_num through phy_mii_ioctl() -> mdiobus_read()/mdiobus_write() without bounding regnum. Values above 31 access internal GPHY OCP registers outside the Clause 22 bank, and values >=3D 0x2e00 overflow the 16-bit RTL9607C_INDIRECT_COMMAND_OCP_ADDR_MASK field and wrap to arbitrary even OCP addresses. [ ... ] > +static enum dsa_tag_protocol > +rtl9607c_dsa_get_tag_protocol(struct dsa_switch *ds, int port, > + enum dsa_tag_protocol mp) > +{ > + return DSA_TAG_PROTO_RTL8_4AP; > +} [Severity: High] Does the RTL8_4AP tagger introduced earlier in this series compile? In commit "net: dsa: tag_rtl8_4: add support for RTL9607C tag variant", net/dsa/tag_rtl8_4.c uses undefined macro RTL8_4_PROTOCOL_RTL9607C in rtl8_4ap_write_tag() and rtl8_4ap_read_tag(), and assigns .rcv =3D rtl8_4ap_tag_rcv in rtl8_4ap_netdev_ops even though rtl8_4ap_tag_rcv() is never defined. This breaks the build whenever CONFIG_NET_DSA_TAG_RTL8_4 is enabled. > + > +static void rtl9607c_dsa_phylink_get_caps(struct dsa_switch *ds, int por= t, > + struct phylink_config *config) > +{ > + switch (port) { > + /* Ports connected to the integrated GPHYs */ > + case 0 ... 3: > + __set_bit(PHY_INTERFACE_MODE_INTERNAL, config->supported_interfaces); > + /* > + * GMII is the default interface mode for phylib, so we have > + * to support it for ports with integrated PHY. > + */ > + __set_bit(PHY_INTERFACE_MODE_GMII, config->supported_interfaces); > + > + config->mac_capabilities =3D MAC_SYM_PAUSE | MAC_ASYM_PAUSE | > + MAC_10 | MAC_100 | MAC_1000FD; > + break; > + /* Main CPU NIC ports */ > + case 9: > + case 10: > + __set_bit(PHY_INTERFACE_MODE_INTERNAL, config->supported_interfaces); > + > + config->mac_capabilities =3D MAC_1000FD; > + break; > + /* PON and 2 HSGMII serdes are not supported yet */ > + default: > + break; > + } > +} [Severity: Medium] Does CPU port 7 fail to register because rtl9607c_dsa_phylink_get_caps() leaves config->supported_interfaces empty for it? rtl9607c_cpu_port_setup() explicitly handles port 7 as GMAC2 and port_mask includes BIT(7), but port 7 falls into the default case here. phylink_create() returns -EINVAL when supported_interfaces is empty, so switch registration will fail on any board using port 7 as a CPU port. [ ... ] > +static int rtl9607c_port_mib_reset(struct realtek_priv *priv, u32 pmask) > +{ > + u32 val; > + int ret; > + > + ret =3D regmap_set_bits(priv->map, RTL9607C_STAT_PORT_RESET_REG, pmask); > + if (ret) > + return ret; > + > + ret =3D regmap_set_bits(priv->map, RTL9607C_STAT_RESET_CONFIG_REG, > + RTL9607C_STAT_RESET_CMD_MASK); > + if (ret) > + return ret; > + > + return regmap_read_poll_timeout(priv->map, RTL9607C_STAT_RESET_REG, val, > + !FIELD_GET(RTL9607C_STAT_RESET_STATUS_MASK, val), > + 10, 1000); > +} [Severity: Medium] Can regmap_set_bits() skip the MMIO trigger write for RTL9607C_STAT_RESET_CMD_MASK? priv->map comes from syscon_node_to_regmap(), which leaves force_write_field false, and regmap_set_bits() passes force =3D false. If RTL9607C_STAT_RESET_CMD_MASK already reads back as 1, _regmap_update_bits() elides the bus write and the function returns success without clearing the MIB counters; regmap_write_bits() should be used to force the trigger write. Using regmap_set_bits() on RTL9607C_STAT_PORT_RESET_REG also preserves any stale port bits instead of writing only pmask. > + > +static void rtl9607c_mib_counter_read(struct realtek_priv *priv, int por= t, u32 offset, > + u32 length, u64 *mibvalue) > +{ > + u32 val, reg =3D RTL9607C_STAT_PORT_MIB_REG(port) + offset; > + > + regmap_read(priv->map, reg, &val); > + *mibvalue =3D val; [Severity: Medium] Can rtl9607c_mib_counter_read() leak uninitialized stack bytes into *mibvalue when regmap_read() fails? val is uninitialized and both regmap_read() return values are ignored. If a read fails (for example due to a syscon clock enable error or register bounds check in _regmap_read()), uninitialized stack data is stored in *mibvalue and copied to userspace via ethtool or rtnetlink statistics. > + > + if (length =3D=3D 2) { > + regmap_read(priv->map, reg + 4, &val); > + *mibvalue |=3D (u64)val << 32; > + } > +} [Severity: Medium] Can reading 64-bit octet counters as two separate 32-bit MMIO reads produce torn values? Without a hardware snapshot/latch or a hi-lo-hi rollover retry loop, if the low 32-bit word wraps into the high word between the two regmap_read() calls (about every 34 seconds at 1 Gbps), the combined counter will be off by 4 GiB. [ ... ] > + rtl9607c_mib_counter_read(priv, port, RTL9607C_IF_OUT_OCTETS, 2, > + &mac_stats->OctetsTransmittedOK); [ ... ] > + rtl9607c_mib_counter_read(priv, port, RTL9607C_IF_IN_OCTETS, 2, > + &mac_stats->OctetsReceivedOK); > + > + rtl9607c_mib_counter_read(priv, port, RTL9607C_IF_OUT_MULTICAST_PKTS, 1, > + &mac_stats->MulticastFramesXmittedOK); > + mac_stats->FramesTransmittedOK +=3D mac_stats->MulticastFramesXmittedOK; > + > + rtl9607c_mib_counter_read(priv, port, RTL9607C_IF_OUT_BROADCAST_PKTS, 1, > + &mac_stats->BroadcastFramesXmittedOK); > + mac_stats->FramesTransmittedOK +=3D mac_stats->BroadcastFramesXmittedOK; > + > + rtl9607c_mib_counter_read(priv, port, RTL9607C_DOT3_OUT_PAUSE_FRAMES, 1, > + &data); > + mac_stats->FramesTransmittedOK +=3D data; > + > + rtl9607c_mib_counter_read(priv, port, RTL9607C_IF_OUT_DISCARDS, 1, &dat= a); > + mac_stats->FramesTransmittedOK -=3D data; > + > + mac_stats->OctetsTransmittedOK -=3D 18 * mac_stats->FramesTransmittedOK; > + > + rtl9607c_mib_counter_read(priv, port, RTL9607C_IF_IN_MULTICAST_PKTS, 1, > + &mac_stats->MulticastFramesReceivedOK); > + mac_stats->FramesReceivedOK +=3D mac_stats->MulticastFramesReceivedOK; > + > + rtl9607c_mib_counter_read(priv, port, RTL9607C_IF_IN_BROADCAST_PKTS, 1, > + &mac_stats->BroadcastFramesReceivedOK); > + mac_stats->FramesReceivedOK +=3D mac_stats->BroadcastFramesReceivedOK; > + > + rtl9607c_mib_counter_read(priv, port, RTL9607C_DOT3_IN_PAUSE_FRAMES, 1, > + &data); > + mac_stats->FramesReceivedOK +=3D data; > + > + mac_stats->OctetsReceivedOK -=3D 18 * mac_stats->FramesReceivedOK; [Severity: Medium] Can the unchecked u64 subtractions in rtl9607c_get_mac_stats() underflow to near U64_MAX? OctetsTransmittedOK and OctetsReceivedOK are sampled before the multicast, broadcast, pause, and discard packet counters. If a frame arrives or is discarded between those live MMIO reads (especially shortly after a MIB reset), subtracting 18 * Frames{Transmitted,Received}OK or RTL9607C_IF_OUT_DISCARDS wraps around unsigned u64. Reading packet counters before octet counters (as in rtl9607c_get_stats64()) and clamping against underflow would avoid this. [ ... ] > +static void rtl9607c_irq_teardown(struct realtek_priv *priv) > +{ > + struct rtl9607c *mb =3D priv->chip_data; > + struct dsa_switch *ds =3D &priv->ds; > + struct dsa_port *dp; > + int virq; > + > + if (mb->irq) { > + free_irq(mb->irq, priv); > + mb->irq =3D 0; > + } [Severity: Low] Should rtl9607c_irq_teardown() call rtl9607c_irq_disable(priv) before free_irq()? Without masking RTL9607C_INTR_IMR_REG, switch hardware interrupt generation remains armed across driver unbind or kexec. [ ... ] > + /* Store the irq so that we know to map and free it during teardown */ > + mb->irq =3D irq; [ ... ] > + ret =3D request_threaded_irq(irq, NULL, rtl9607c_irq, IRQF_ONESHOT, > + "rtl9607c-switch", priv); > + if (ret) { > + dev_err(priv->dev, "failed to request irq: %pe\n", > + ERR_PTR(ret)); > + goto out_teardown_irq; > + } [Severity: Medium] Does rtl9607c_irq_setup() call free_irq() on an IRQ that was never requested when an error occurs before or during request_threaded_irq()? mb->irq is set before request_threaded_irq(), and every error path from irq_create_mapping() through request_threaded_irq() jumps to out_teardown_irq, where rtl9607c_irq_teardown() unconditionally calls free_irq(mb->irq, priv) and triggers WARN in __free_irq(). Only calling free_irq() after request_threaded_irq() succeeds (or using a separate unwind label) avoids this. [ ... ] > +static int rtl9607c_get_chip_id_and_ver(struct regmap *map, u32 *id, u32= *ver) > +{ > + u32 chip_info; > + int ret; > + > + /* The CHIP_INFO_EN must be set to 0xa to enable chip information */ > + ret =3D regmap_set_bits(map, RTL9607C_CHIP_INFO_REG, > + FIELD_PREP(RTL9607C_CHIP_INFO_EN_MASK, > + RTL9607C_CHIP_INFO_EN_VALUE)); > + if (ret) > + return ret; > + > + ret =3D regmap_read(map, RTL9607C_CHIP_INFO_REG, &chip_info); > + if (ret) > + return ret; [Severity: Medium] Should this use regmap_update_bits() with RTL9607C_CHIP_INFO_EN_MASK instead of regmap_set_bits()? regmap_set_bits() passes 0xa0000000 as both mask and value, so bits 30 and 28 are never cleared. If bootloader or prior state left either bit set, CHIP_INFO_EN will not become 0xa and probe will fail with -ENODEV. Also, if regmap_read() fails, CHIP_INFO_EN is left enabled instead of being cleared. [ ... ] > +static struct platform_driver rtl9607c_mmio_driver =3D { > + .driver =3D { > + .name =3D "rtl9607c-mmio", > + .of_match_table =3D rtl9607c_of_match, > + }, > + .probe =3D realtek_mmio_probe, > + .remove =3D realtek_mmio_remove, > + .shutdown =3D realtek_mmio_shutdown, > +}; [Severity: High] Does the shared realtek_dsa module compile with this series? In commit "net: dsa: realtek: add new mmio interface for drivers", rtl83xx_probe() in drivers/net/dsa/realtek/rtl83xx.c calls undeclared ev_err() instead of dev_err(), breaking compilation of realtek_dsa.o required by realtek_mmio_probe(). --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204182553.3395= 2-1-adilov@disroot.org?part=3D4