Skip to content

Commit

Permalink
devlink: Move size validation to core
Browse files Browse the repository at this point in the history
Currently the size validation is done via a cb, which is unneeded. The
size validation can be moved to core. The next patch will perform cleanup.

Signed-off-by: Arkadi Sharshevsky <arkadis@mellanox.com>
Signed-off-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Arkadi Sharshevsky authored and David S. Miller committed Feb 20, 2018
1 parent b99fe0e commit cc944ea
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions net/core/devlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -2338,6 +2338,32 @@ devlink_resource_validate_children(struct devlink_resource *resource)
resource->size_valid = size_valid;
}

static int
devlink_resource_validate_size(struct devlink_resource *resource, u64 size,
struct netlink_ext_ack *extack)
{
u64 reminder;
int err = 0;

if (size > resource->size_params->size_max) {
NL_SET_ERR_MSG_MOD(extack, "Size larger than maximum");
err = -EINVAL;
}

if (size < resource->size_params->size_min) {
NL_SET_ERR_MSG_MOD(extack, "Size smaller than minimum");
err = -EINVAL;
}

div64_u64_rem(size, resource->size_params->size_granularity, &reminder);
if (reminder) {
NL_SET_ERR_MSG_MOD(extack, "Wrong granularity");
err = -EINVAL;
}

return err;
}

static int devlink_nl_cmd_resource_set(struct sk_buff *skb,
struct genl_info *info)
{
Expand All @@ -2356,12 +2382,8 @@ static int devlink_nl_cmd_resource_set(struct sk_buff *skb,
if (!resource)
return -EINVAL;

if (!resource->resource_ops->size_validate)
return -EINVAL;

size = nla_get_u64(info->attrs[DEVLINK_ATTR_RESOURCE_SIZE]);
err = resource->resource_ops->size_validate(devlink, size,
info->extack);
err = devlink_resource_validate_size(resource, size, info->extack);
if (err)
return err;

Expand Down

0 comments on commit cc944ea

Please sign in to comment.