diff options
author | Jakub Kicinski <jakub.kicinski@netronome.com> | 2019-02-25 22:34:07 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2019-02-26 11:49:05 -0500 |
commit | be6fe1d8e1023bd80e122fa5eeeaff2ce66e9247 (patch) | |
tree | 8b81f90a9de84f1842cf21285ff8a417497a2075 /net | |
parent | 1b45ff6c17f1d07c496b08dd602a4aff8fe40848 (diff) |
devlink: require non-NULL ops for devlink instances
Commit 76726ccb7f46 ("devlink: add flash update command") and
commit 2d8dc5bbf4e7 ("devlink: Add support for reload")
access devlink ops without NULL-checking. There is, however, no
driver which would pass in NULL ops, so let's just make that
a requirement. Remove the now unnecessary NULL-checking.
Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Acked-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net')
-rw-r--r-- | net/core/devlink.c | 48 |
1 files changed, 22 insertions, 26 deletions
diff --git a/net/core/devlink.c b/net/core/devlink.c index ecff6e63bc4d..a49dee67e66f 100644 --- a/net/core/devlink.c +++ b/net/core/devlink.c | |||
@@ -723,7 +723,7 @@ static int devlink_port_type_set(struct devlink *devlink, | |||
723 | { | 723 | { |
724 | int err; | 724 | int err; |
725 | 725 | ||
726 | if (devlink->ops && devlink->ops->port_type_set) { | 726 | if (devlink->ops->port_type_set) { |
727 | if (port_type == DEVLINK_PORT_TYPE_NOTSET) | 727 | if (port_type == DEVLINK_PORT_TYPE_NOTSET) |
728 | return -EINVAL; | 728 | return -EINVAL; |
729 | if (port_type == devlink_port->type) | 729 | if (port_type == devlink_port->type) |
@@ -760,7 +760,7 @@ static int devlink_port_split(struct devlink *devlink, u32 port_index, | |||
760 | u32 count, struct netlink_ext_ack *extack) | 760 | u32 count, struct netlink_ext_ack *extack) |
761 | 761 | ||
762 | { | 762 | { |
763 | if (devlink->ops && devlink->ops->port_split) | 763 | if (devlink->ops->port_split) |
764 | return devlink->ops->port_split(devlink, port_index, count, | 764 | return devlink->ops->port_split(devlink, port_index, count, |
765 | extack); | 765 | extack); |
766 | return -EOPNOTSUPP; | 766 | return -EOPNOTSUPP; |
@@ -786,7 +786,7 @@ static int devlink_port_unsplit(struct devlink *devlink, u32 port_index, | |||
786 | struct netlink_ext_ack *extack) | 786 | struct netlink_ext_ack *extack) |
787 | 787 | ||
788 | { | 788 | { |
789 | if (devlink->ops && devlink->ops->port_unsplit) | 789 | if (devlink->ops->port_unsplit) |
790 | return devlink->ops->port_unsplit(devlink, port_index, extack); | 790 | return devlink->ops->port_unsplit(devlink, port_index, extack); |
791 | return -EOPNOTSUPP; | 791 | return -EOPNOTSUPP; |
792 | } | 792 | } |
@@ -961,7 +961,7 @@ static int devlink_nl_cmd_sb_pool_get_doit(struct sk_buff *skb, | |||
961 | if (err) | 961 | if (err) |
962 | return err; | 962 | return err; |
963 | 963 | ||
964 | if (!devlink->ops || !devlink->ops->sb_pool_get) | 964 | if (!devlink->ops->sb_pool_get) |
965 | return -EOPNOTSUPP; | 965 | return -EOPNOTSUPP; |
966 | 966 | ||
967 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | 967 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
@@ -1017,7 +1017,7 @@ static int devlink_nl_cmd_sb_pool_get_dumpit(struct sk_buff *msg, | |||
1017 | mutex_lock(&devlink_mutex); | 1017 | mutex_lock(&devlink_mutex); |
1018 | list_for_each_entry(devlink, &devlink_list, list) { | 1018 | list_for_each_entry(devlink, &devlink_list, list) { |
1019 | if (!net_eq(devlink_net(devlink), sock_net(msg->sk)) || | 1019 | if (!net_eq(devlink_net(devlink), sock_net(msg->sk)) || |
1020 | !devlink->ops || !devlink->ops->sb_pool_get) | 1020 | !devlink->ops->sb_pool_get) |
1021 | continue; | 1021 | continue; |
1022 | mutex_lock(&devlink->lock); | 1022 | mutex_lock(&devlink->lock); |
1023 | list_for_each_entry(devlink_sb, &devlink->sb_list, list) { | 1023 | list_for_each_entry(devlink_sb, &devlink->sb_list, list) { |
@@ -1046,7 +1046,7 @@ static int devlink_sb_pool_set(struct devlink *devlink, unsigned int sb_index, | |||
1046 | { | 1046 | { |
1047 | const struct devlink_ops *ops = devlink->ops; | 1047 | const struct devlink_ops *ops = devlink->ops; |
1048 | 1048 | ||
1049 | if (ops && ops->sb_pool_set) | 1049 | if (ops->sb_pool_set) |
1050 | return ops->sb_pool_set(devlink, sb_index, pool_index, | 1050 | return ops->sb_pool_set(devlink, sb_index, pool_index, |
1051 | size, threshold_type); | 1051 | size, threshold_type); |
1052 | return -EOPNOTSUPP; | 1052 | return -EOPNOTSUPP; |
@@ -1151,7 +1151,7 @@ static int devlink_nl_cmd_sb_port_pool_get_doit(struct sk_buff *skb, | |||
1151 | if (err) | 1151 | if (err) |
1152 | return err; | 1152 | return err; |
1153 | 1153 | ||
1154 | if (!devlink->ops || !devlink->ops->sb_port_pool_get) | 1154 | if (!devlink->ops->sb_port_pool_get) |
1155 | return -EOPNOTSUPP; | 1155 | return -EOPNOTSUPP; |
1156 | 1156 | ||
1157 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | 1157 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
@@ -1213,7 +1213,7 @@ static int devlink_nl_cmd_sb_port_pool_get_dumpit(struct sk_buff *msg, | |||
1213 | mutex_lock(&devlink_mutex); | 1213 | mutex_lock(&devlink_mutex); |
1214 | list_for_each_entry(devlink, &devlink_list, list) { | 1214 | list_for_each_entry(devlink, &devlink_list, list) { |
1215 | if (!net_eq(devlink_net(devlink), sock_net(msg->sk)) || | 1215 | if (!net_eq(devlink_net(devlink), sock_net(msg->sk)) || |
1216 | !devlink->ops || !devlink->ops->sb_port_pool_get) | 1216 | !devlink->ops->sb_port_pool_get) |
1217 | continue; | 1217 | continue; |
1218 | mutex_lock(&devlink->lock); | 1218 | mutex_lock(&devlink->lock); |
1219 | list_for_each_entry(devlink_sb, &devlink->sb_list, list) { | 1219 | list_for_each_entry(devlink_sb, &devlink->sb_list, list) { |
@@ -1242,7 +1242,7 @@ static int devlink_sb_port_pool_set(struct devlink_port *devlink_port, | |||
1242 | { | 1242 | { |
1243 | const struct devlink_ops *ops = devlink_port->devlink->ops; | 1243 | const struct devlink_ops *ops = devlink_port->devlink->ops; |
1244 | 1244 | ||
1245 | if (ops && ops->sb_port_pool_set) | 1245 | if (ops->sb_port_pool_set) |
1246 | return ops->sb_port_pool_set(devlink_port, sb_index, | 1246 | return ops->sb_port_pool_set(devlink_port, sb_index, |
1247 | pool_index, threshold); | 1247 | pool_index, threshold); |
1248 | return -EOPNOTSUPP; | 1248 | return -EOPNOTSUPP; |
@@ -1355,7 +1355,7 @@ static int devlink_nl_cmd_sb_tc_pool_bind_get_doit(struct sk_buff *skb, | |||
1355 | if (err) | 1355 | if (err) |
1356 | return err; | 1356 | return err; |
1357 | 1357 | ||
1358 | if (!devlink->ops || !devlink->ops->sb_tc_pool_bind_get) | 1358 | if (!devlink->ops->sb_tc_pool_bind_get) |
1359 | return -EOPNOTSUPP; | 1359 | return -EOPNOTSUPP; |
1360 | 1360 | ||
1361 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | 1361 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
@@ -1439,7 +1439,7 @@ devlink_nl_cmd_sb_tc_pool_bind_get_dumpit(struct sk_buff *msg, | |||
1439 | mutex_lock(&devlink_mutex); | 1439 | mutex_lock(&devlink_mutex); |
1440 | list_for_each_entry(devlink, &devlink_list, list) { | 1440 | list_for_each_entry(devlink, &devlink_list, list) { |
1441 | if (!net_eq(devlink_net(devlink), sock_net(msg->sk)) || | 1441 | if (!net_eq(devlink_net(devlink), sock_net(msg->sk)) || |
1442 | !devlink->ops || !devlink->ops->sb_tc_pool_bind_get) | 1442 | !devlink->ops->sb_tc_pool_bind_get) |
1443 | continue; | 1443 | continue; |
1444 | 1444 | ||
1445 | mutex_lock(&devlink->lock); | 1445 | mutex_lock(&devlink->lock); |
@@ -1471,7 +1471,7 @@ static int devlink_sb_tc_pool_bind_set(struct devlink_port *devlink_port, | |||
1471 | { | 1471 | { |
1472 | const struct devlink_ops *ops = devlink_port->devlink->ops; | 1472 | const struct devlink_ops *ops = devlink_port->devlink->ops; |
1473 | 1473 | ||
1474 | if (ops && ops->sb_tc_pool_bind_set) | 1474 | if (ops->sb_tc_pool_bind_set) |
1475 | return ops->sb_tc_pool_bind_set(devlink_port, sb_index, | 1475 | return ops->sb_tc_pool_bind_set(devlink_port, sb_index, |
1476 | tc_index, pool_type, | 1476 | tc_index, pool_type, |
1477 | pool_index, threshold); | 1477 | pool_index, threshold); |
@@ -1519,7 +1519,7 @@ static int devlink_nl_cmd_sb_occ_snapshot_doit(struct sk_buff *skb, | |||
1519 | struct devlink_sb *devlink_sb = info->user_ptr[1]; | 1519 | struct devlink_sb *devlink_sb = info->user_ptr[1]; |
1520 | const struct devlink_ops *ops = devlink->ops; | 1520 | const struct devlink_ops *ops = devlink->ops; |
1521 | 1521 | ||
1522 | if (ops && ops->sb_occ_snapshot) | 1522 | if (ops->sb_occ_snapshot) |
1523 | return ops->sb_occ_snapshot(devlink, devlink_sb->index); | 1523 | return ops->sb_occ_snapshot(devlink, devlink_sb->index); |
1524 | return -EOPNOTSUPP; | 1524 | return -EOPNOTSUPP; |
1525 | } | 1525 | } |
@@ -1531,7 +1531,7 @@ static int devlink_nl_cmd_sb_occ_max_clear_doit(struct sk_buff *skb, | |||
1531 | struct devlink_sb *devlink_sb = info->user_ptr[1]; | 1531 | struct devlink_sb *devlink_sb = info->user_ptr[1]; |
1532 | const struct devlink_ops *ops = devlink->ops; | 1532 | const struct devlink_ops *ops = devlink->ops; |
1533 | 1533 | ||
1534 | if (ops && ops->sb_occ_max_clear) | 1534 | if (ops->sb_occ_max_clear) |
1535 | return ops->sb_occ_max_clear(devlink, devlink_sb->index); | 1535 | return ops->sb_occ_max_clear(devlink, devlink_sb->index); |
1536 | return -EOPNOTSUPP; | 1536 | return -EOPNOTSUPP; |
1537 | } | 1537 | } |
@@ -1594,13 +1594,9 @@ static int devlink_nl_cmd_eswitch_get_doit(struct sk_buff *skb, | |||
1594 | struct genl_info *info) | 1594 | struct genl_info *info) |
1595 | { | 1595 | { |
1596 | struct devlink *devlink = info->user_ptr[0]; | 1596 | struct devlink *devlink = info->user_ptr[0]; |
1597 | const struct devlink_ops *ops = devlink->ops; | ||
1598 | struct sk_buff *msg; | 1597 | struct sk_buff *msg; |
1599 | int err; | 1598 | int err; |
1600 | 1599 | ||
1601 | if (!ops) | ||
1602 | return -EOPNOTSUPP; | ||
1603 | |||
1604 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | 1600 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
1605 | if (!msg) | 1601 | if (!msg) |
1606 | return -ENOMEM; | 1602 | return -ENOMEM; |
@@ -1625,9 +1621,6 @@ static int devlink_nl_cmd_eswitch_set_doit(struct sk_buff *skb, | |||
1625 | int err = 0; | 1621 | int err = 0; |
1626 | u16 mode; | 1622 | u16 mode; |
1627 | 1623 | ||
1628 | if (!ops) | ||
1629 | return -EOPNOTSUPP; | ||
1630 | |||
1631 | if (info->attrs[DEVLINK_ATTR_ESWITCH_MODE]) { | 1624 | if (info->attrs[DEVLINK_ATTR_ESWITCH_MODE]) { |
1632 | if (!ops->eswitch_mode_set) | 1625 | if (!ops->eswitch_mode_set) |
1633 | return -EOPNOTSUPP; | 1626 | return -EOPNOTSUPP; |
@@ -3869,7 +3862,7 @@ static int devlink_nl_cmd_info_get_doit(struct sk_buff *skb, | |||
3869 | struct sk_buff *msg; | 3862 | struct sk_buff *msg; |
3870 | int err; | 3863 | int err; |
3871 | 3864 | ||
3872 | if (!devlink->ops || !devlink->ops->info_get) | 3865 | if (!devlink->ops->info_get) |
3873 | return -EOPNOTSUPP; | 3866 | return -EOPNOTSUPP; |
3874 | 3867 | ||
3875 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | 3868 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
@@ -5232,6 +5225,9 @@ struct devlink *devlink_alloc(const struct devlink_ops *ops, size_t priv_size) | |||
5232 | { | 5225 | { |
5233 | struct devlink *devlink; | 5226 | struct devlink *devlink; |
5234 | 5227 | ||
5228 | if (WARN_ON(!ops)) | ||
5229 | return NULL; | ||
5230 | |||
5235 | devlink = kzalloc(sizeof(*devlink) + priv_size, GFP_KERNEL); | 5231 | devlink = kzalloc(sizeof(*devlink) + priv_size, GFP_KERNEL); |
5236 | if (!devlink) | 5232 | if (!devlink) |
5237 | return NULL; | 5233 | return NULL; |
@@ -6091,7 +6087,7 @@ __devlink_param_driverinit_value_set(struct devlink *devlink, | |||
6091 | int devlink_param_driverinit_value_get(struct devlink *devlink, u32 param_id, | 6087 | int devlink_param_driverinit_value_get(struct devlink *devlink, u32 param_id, |
6092 | union devlink_param_value *init_val) | 6088 | union devlink_param_value *init_val) |
6093 | { | 6089 | { |
6094 | if (!devlink->ops || !devlink->ops->reload) | 6090 | if (!devlink->ops->reload) |
6095 | return -EOPNOTSUPP; | 6091 | return -EOPNOTSUPP; |
6096 | 6092 | ||
6097 | return __devlink_param_driverinit_value_get(&devlink->param_list, | 6093 | return __devlink_param_driverinit_value_get(&devlink->param_list, |
@@ -6138,7 +6134,7 @@ int devlink_port_param_driverinit_value_get(struct devlink_port *devlink_port, | |||
6138 | { | 6134 | { |
6139 | struct devlink *devlink = devlink_port->devlink; | 6135 | struct devlink *devlink = devlink_port->devlink; |
6140 | 6136 | ||
6141 | if (!devlink->ops || !devlink->ops->reload) | 6137 | if (!devlink->ops->reload) |
6142 | return -EOPNOTSUPP; | 6138 | return -EOPNOTSUPP; |
6143 | 6139 | ||
6144 | return __devlink_param_driverinit_value_get(&devlink_port->param_list, | 6140 | return __devlink_param_driverinit_value_get(&devlink_port->param_list, |
@@ -6435,7 +6431,7 @@ void devlink_compat_running_version(struct net_device *dev, | |||
6435 | 6431 | ||
6436 | mutex_lock(&devlink_mutex); | 6432 | mutex_lock(&devlink_mutex); |
6437 | devlink = netdev_to_devlink(dev); | 6433 | devlink = netdev_to_devlink(dev); |
6438 | if (!devlink || !devlink->ops || !devlink->ops->info_get) | 6434 | if (!devlink || !devlink->ops->info_get) |
6439 | goto unlock_list; | 6435 | goto unlock_list; |
6440 | 6436 | ||
6441 | mutex_lock(&devlink->lock); | 6437 | mutex_lock(&devlink->lock); |
@@ -6458,7 +6454,7 @@ int devlink_compat_flash_update(struct net_device *dev, const char *file_name) | |||
6458 | 6454 | ||
6459 | mutex_lock(&devlink_mutex); | 6455 | mutex_lock(&devlink_mutex); |
6460 | devlink = netdev_to_devlink(dev); | 6456 | devlink = netdev_to_devlink(dev); |
6461 | if (!devlink || !devlink->ops || !devlink->ops->flash_update) | 6457 | if (!devlink || !devlink->ops->flash_update) |
6462 | goto unlock_list; | 6458 | goto unlock_list; |
6463 | 6459 | ||
6464 | mutex_lock(&devlink->lock); | 6460 | mutex_lock(&devlink->lock); |