net: devlink: disallow port_attrs_set() to be called before register
authorJiri Pirko <jiri@mellanox.com>
Sun, 24 Mar 2019 10:14:33 +0000 (11:14 +0100)
committerDavid S. Miller <davem@davemloft.net>
Sun, 24 Mar 2019 18:55:31 +0000 (14:55 -0400)
Since the port attributes are static and cannot change during the port
lifetime, WARN_ON if some driver calls it after registration. Also, no
need to call notifications as it is noop anyway due to check of
devlink_port->registered there.

Signed-off-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/core/devlink.c

index 418efeafa79bfbe818bc88640a27a7bd7eafa08b..d78c8cea7c3d82bbcadbc38ae22da3be5887ff3b 100644 (file)
@@ -5388,12 +5388,13 @@ void devlink_port_attrs_set(struct devlink_port *devlink_port,
 {
        struct devlink_port_attrs *attrs = &devlink_port->attrs;
 
+       if (WARN_ON(devlink_port->registered))
+               return;
        attrs->set = true;
        attrs->flavour = flavour;
        attrs->port_number = port_number;
        attrs->split = split;
        attrs->split_subport_number = split_subport_number;
-       devlink_port_notify(devlink_port, DEVLINK_CMD_PORT_NEW);
 }
 EXPORT_SYMBOL_GPL(devlink_port_attrs_set);