net: devlink: warn on setting type on unregistered port
authorJiri Pirko <jiri@mellanox.com>
Sun, 24 Mar 2019 10:14:36 +0000 (11:14 +0100)
committerDavid S. Miller <davem@davemloft.net>
Sun, 24 Mar 2019 18:55:31 +0000 (14:55 -0400)
Port needs to be registered first before the type is set. Warn and
bail-out in case it is not.

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

index d78c8cea7c3d82bbcadbc38ae22da3be5887ff3b..860ab3a721e07f3a660667c8c71ee080d972c71f 100644 (file)
@@ -5328,6 +5328,8 @@ static void __devlink_port_type_set(struct devlink_port *devlink_port,
                                    enum devlink_port_type type,
                                    void *type_dev)
 {
+       if (WARN_ON(!devlink_port->registered))
+               return;
        devlink_port->type = type;
        devlink_port->type_dev = type_dev;
        devlink_port_notify(devlink_port, DEVLINK_CMD_PORT_NEW);