From: Tim Harvey Date: Wed, 30 Nov 2022 17:42:46 +0000 (-0800) Subject: net: dsa: ensure dsa driver has proper ops X-Git-Tag: v2025.01-rc5-pxa1908~1121^2~16 X-Git-Url: http://git.dujemihanovic.xyz/img/static/git-logo.png?a=commitdiff_plain;h=43c2a00a14a7e4567b156a2345870d008485da3c;p=u-boot.git net: dsa: ensure dsa driver has proper ops Add a function to sanity check a dsa driver having proper ops. Suggested-by: Vladimir Oltean Signed-off-by: Tim Harvey Reviewed-by: Vladimir Oltean Reviewed-by: Fabio Estevam --- diff --git a/net/dsa-uclass.c b/net/dsa-uclass.c index 5759cedcbe..211a991cdd 100644 --- a/net/dsa-uclass.c +++ b/net/dsa-uclass.c @@ -342,6 +342,19 @@ U_BOOT_DRIVER(dsa_port) = { .plat_auto = sizeof(struct eth_pdata), }; +static int dsa_sanitize_ops(struct udevice *dev) +{ + struct dsa_ops *ops = dsa_get_ops(dev); + + if ((!ops->xmit || !ops->rcv) && + (!ops->port_enable && !ops->port_disable)) { + dev_err(dev, "Packets cannot be steered to ports\n"); + return -EINVAL; + } + + return 0; +} + /* * This function mostly deals with pulling information out of the device tree * into the pdata structure. @@ -358,6 +371,10 @@ static int dsa_post_bind(struct udevice *dev) if (!ofnode_valid(node)) return -ENODEV; + err = dsa_sanitize_ops(dev); + if (err) + return err; + pdata->master_node = ofnode_null(); node = ofnode_find_subnode(node, "ports");