Commit cc944ead authored by Arkadi Sharshevsky's avatar Arkadi Sharshevsky Committed by David S. Miller

devlink: Move size validation to core

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: default avatarArkadi Sharshevsky <arkadis@mellanox.com>
Signed-off-by: default avatarJiri Pirko <jiri@mellanox.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent b99fe0e2
...@@ -2338,6 +2338,32 @@ devlink_resource_validate_children(struct devlink_resource *resource) ...@@ -2338,6 +2338,32 @@ devlink_resource_validate_children(struct devlink_resource *resource)
resource->size_valid = size_valid; 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, static int devlink_nl_cmd_resource_set(struct sk_buff *skb,
struct genl_info *info) struct genl_info *info)
{ {
...@@ -2356,12 +2382,8 @@ static int devlink_nl_cmd_resource_set(struct sk_buff *skb, ...@@ -2356,12 +2382,8 @@ static int devlink_nl_cmd_resource_set(struct sk_buff *skb,
if (!resource) if (!resource)
return -EINVAL; return -EINVAL;
if (!resource->resource_ops->size_validate)
return -EINVAL;
size = nla_get_u64(info->attrs[DEVLINK_ATTR_RESOURCE_SIZE]); size = nla_get_u64(info->attrs[DEVLINK_ATTR_RESOURCE_SIZE]);
err = resource->resource_ops->size_validate(devlink, size, err = devlink_resource_validate_size(resource, size, info->extack);
info->extack);
if (err) if (err)
return err; return err;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment