Commit ee85da53 authored by Jiri Pirko's avatar Jiri Pirko Committed by David S. Miller

devlink: have genetlink code to parse the attrs during dumpit

Benefit from the fact that the generic netlink code can parse the attrs
for dumpit op and avoid need to parse it in the op callback.
Signed-off-by: default avatarJiri Pirko <jiri@mellanox.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 265ecd4f
...@@ -3943,29 +3943,19 @@ static int devlink_nl_region_read_snapshot_fill(struct sk_buff *skb, ...@@ -3943,29 +3943,19 @@ static int devlink_nl_region_read_snapshot_fill(struct sk_buff *skb,
static int devlink_nl_cmd_region_read_dumpit(struct sk_buff *skb, static int devlink_nl_cmd_region_read_dumpit(struct sk_buff *skb,
struct netlink_callback *cb) struct netlink_callback *cb)
{ {
const struct genl_dumpit_info *info = genl_dumpit_info(cb);
u64 ret_offset, start_offset, end_offset = 0; u64 ret_offset, start_offset, end_offset = 0;
struct nlattr **attrs = info->attrs;
struct devlink_region *region; struct devlink_region *region;
struct nlattr *chunks_attr; struct nlattr *chunks_attr;
const char *region_name; const char *region_name;
struct devlink *devlink; struct devlink *devlink;
struct nlattr **attrs;
bool dump = true; bool dump = true;
void *hdr; void *hdr;
int err; int err;
start_offset = *((u64 *)&cb->args[0]); start_offset = *((u64 *)&cb->args[0]);
attrs = kmalloc_array(DEVLINK_ATTR_MAX + 1, sizeof(*attrs), GFP_KERNEL);
if (!attrs)
return -ENOMEM;
err = nlmsg_parse_deprecated(cb->nlh,
GENL_HDRLEN + devlink_nl_family.hdrsize,
attrs, DEVLINK_ATTR_MAX,
devlink_nl_family.policy, cb->extack);
if (err)
goto out_free;
mutex_lock(&devlink_mutex); mutex_lock(&devlink_mutex);
devlink = devlink_get_from_attrs(sock_net(cb->skb->sk), attrs); devlink = devlink_get_from_attrs(sock_net(cb->skb->sk), attrs);
if (IS_ERR(devlink)) { if (IS_ERR(devlink)) {
...@@ -4042,7 +4032,6 @@ static int devlink_nl_cmd_region_read_dumpit(struct sk_buff *skb, ...@@ -4042,7 +4032,6 @@ static int devlink_nl_cmd_region_read_dumpit(struct sk_buff *skb,
genlmsg_end(skb, hdr); genlmsg_end(skb, hdr);
mutex_unlock(&devlink->lock); mutex_unlock(&devlink->lock);
mutex_unlock(&devlink_mutex); mutex_unlock(&devlink_mutex);
kfree(attrs);
return skb->len; return skb->len;
...@@ -4052,8 +4041,6 @@ static int devlink_nl_cmd_region_read_dumpit(struct sk_buff *skb, ...@@ -4052,8 +4041,6 @@ static int devlink_nl_cmd_region_read_dumpit(struct sk_buff *skb,
mutex_unlock(&devlink->lock); mutex_unlock(&devlink->lock);
out_dev: out_dev:
mutex_unlock(&devlink_mutex); mutex_unlock(&devlink_mutex);
out_free:
kfree(attrs);
return err; return err;
} }
...@@ -4995,21 +4982,10 @@ devlink_health_reporter_get_from_info(struct devlink *devlink, ...@@ -4995,21 +4982,10 @@ devlink_health_reporter_get_from_info(struct devlink *devlink,
static struct devlink_health_reporter * static struct devlink_health_reporter *
devlink_health_reporter_get_from_cb(struct netlink_callback *cb) devlink_health_reporter_get_from_cb(struct netlink_callback *cb)
{ {
const struct genl_dumpit_info *info = genl_dumpit_info(cb);
struct devlink_health_reporter *reporter; struct devlink_health_reporter *reporter;
struct nlattr **attrs = info->attrs;
struct devlink *devlink; struct devlink *devlink;
struct nlattr **attrs;
int err;
attrs = kmalloc_array(DEVLINK_ATTR_MAX + 1, sizeof(*attrs), GFP_KERNEL);
if (!attrs)
return NULL;
err = nlmsg_parse_deprecated(cb->nlh,
GENL_HDRLEN + devlink_nl_family.hdrsize,
attrs, DEVLINK_ATTR_MAX,
devlink_nl_family.policy, cb->extack);
if (err)
goto free;
mutex_lock(&devlink_mutex); mutex_lock(&devlink_mutex);
devlink = devlink_get_from_attrs(sock_net(cb->skb->sk), attrs); devlink = devlink_get_from_attrs(sock_net(cb->skb->sk), attrs);
...@@ -5018,12 +4994,9 @@ devlink_health_reporter_get_from_cb(struct netlink_callback *cb) ...@@ -5018,12 +4994,9 @@ devlink_health_reporter_get_from_cb(struct netlink_callback *cb)
reporter = devlink_health_reporter_get_from_attrs(devlink, attrs); reporter = devlink_health_reporter_get_from_attrs(devlink, attrs);
mutex_unlock(&devlink_mutex); mutex_unlock(&devlink_mutex);
kfree(attrs);
return reporter; return reporter;
unlock: unlock:
mutex_unlock(&devlink_mutex); mutex_unlock(&devlink_mutex);
free:
kfree(attrs);
return NULL; return NULL;
} }
...@@ -6154,7 +6127,8 @@ static const struct genl_ops devlink_nl_ops[] = { ...@@ -6154,7 +6127,8 @@ static const struct genl_ops devlink_nl_ops[] = {
}, },
{ {
.cmd = DEVLINK_CMD_REGION_READ, .cmd = DEVLINK_CMD_REGION_READ,
.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, .validate = GENL_DONT_VALIDATE_STRICT |
GENL_DONT_VALIDATE_DUMP_STRICT,
.dumpit = devlink_nl_cmd_region_read_dumpit, .dumpit = devlink_nl_cmd_region_read_dumpit,
.flags = GENL_ADMIN_PERM, .flags = GENL_ADMIN_PERM,
.internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK, .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK,
......
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