net: dsa: microchip: provide a list of valid protocols for xmit handler
authorSean Nyekjaer <sean@geanix.com>
Wed, 6 Dec 2023 07:16:54 +0000 (08:16 +0100)
committerJakub Kicinski <kuba@kernel.org>
Thu, 7 Dec 2023 18:03:17 +0000 (10:03 -0800)
Provide a list of valid protocols for which the driver will provide
it's deferred xmit handler.

When using DSA_TAG_PROTO_KSZ8795 protocol, it does not provide a
"connect" method, therefor ksz_connect() is not allocating ksz_tagger_data.

This avoids the following null pointer dereference:
 ksz_connect_tag_protocol from dsa_register_switch+0x9ac/0xee0
 dsa_register_switch from ksz_switch_register+0x65c/0x828
 ksz_switch_register from ksz_spi_probe+0x11c/0x168
 ksz_spi_probe from spi_probe+0x84/0xa8
 spi_probe from really_probe+0xc8/0x2d8

Fixes: ab32f56a4100 ("net: dsa: microchip: ptp: add packet transmission timestamping")
Signed-off-by: Sean Nyekjaer <sean@geanix.com>
Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com>
Reviewed-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Link: https://lore.kernel.org/r/20231206071655.1626479-1-sean@geanix.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/dsa/microchip/ksz_common.c

index 3fed406..ff4b396 100644 (file)
@@ -2713,10 +2713,18 @@ static int ksz_connect_tag_protocol(struct dsa_switch *ds,
 {
        struct ksz_tagger_data *tagger_data;
 
-       tagger_data = ksz_tagger_data(ds);
-       tagger_data->xmit_work_fn = ksz_port_deferred_xmit;
-
-       return 0;
+       switch (proto) {
+       case DSA_TAG_PROTO_KSZ8795:
+               return 0;
+       case DSA_TAG_PROTO_KSZ9893:
+       case DSA_TAG_PROTO_KSZ9477:
+       case DSA_TAG_PROTO_LAN937X:
+               tagger_data = ksz_tagger_data(ds);
+               tagger_data->xmit_work_fn = ksz_port_deferred_xmit;
+               return 0;
+       default:
+               return -EPROTONOSUPPORT;
+       }
 }
 
 static int ksz_port_vlan_filtering(struct dsa_switch *ds, int port,