Skip to content

Commit

Permalink
net: tipc: allocate attrs locally instead of using genl_family_attrbu…
Browse files Browse the repository at this point in the history
…f in compat_dumpit()

As this is the last user of genl_family_attrbuf, convert to allocate
attrs locally and do it in a similar way this is done in compat_doit().

Signed-off-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Jiri Pirko authored and David S. Miller committed Oct 6, 2019
1 parent 057af70 commit c6c0861
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
12 changes: 0 additions & 12 deletions net/tipc/netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,18 +271,6 @@ struct genl_family tipc_genl_family __ro_after_init = {
.n_ops = ARRAY_SIZE(tipc_genl_v2_ops),
};

int tipc_nlmsg_parse(const struct nlmsghdr *nlh, struct nlattr ***attr)
{
u32 maxattr = tipc_genl_family.maxattr;

*attr = genl_family_attrbuf(&tipc_genl_family);
if (!*attr)
return -EOPNOTSUPP;

return nlmsg_parse_deprecated(nlh, GENL_HDRLEN, *attr, maxattr,
tipc_nl_policy, NULL);
}

int __init tipc_netlink_start(void)
{
int res;
Expand Down
1 change: 0 additions & 1 deletion net/tipc/netlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
#include <net/netlink.h>

extern struct genl_family tipc_genl_family;
int tipc_nlmsg_parse(const struct nlmsghdr *nlh, struct nlattr ***buf);

struct tipc_nl_msg {
struct sk_buff *skb;
Expand Down
19 changes: 15 additions & 4 deletions net/tipc/netlink_compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ static int __tipc_nl_compat_dumpit(struct tipc_nl_compat_cmd_dump *cmd,
struct sk_buff *buf;
struct nlmsghdr *nlmsg;
struct netlink_callback cb;
struct nlattr **attrbuf;

memset(&cb, 0, sizeof(cb));
cb.nlh = (struct nlmsghdr *)arg->data;
Expand All @@ -201,19 +202,28 @@ static int __tipc_nl_compat_dumpit(struct tipc_nl_compat_cmd_dump *cmd,
return -ENOMEM;
}

attrbuf = kmalloc_array(tipc_genl_family.maxattr + 1,
sizeof(struct nlattr *), GFP_KERNEL);
if (!attrbuf) {
err = -ENOMEM;
goto err_out;
}

do {
int rem;

len = (*cmd->dumpit)(buf, &cb);

nlmsg_for_each_msg(nlmsg, nlmsg_hdr(buf), len, rem) {
struct nlattr **attrs;

err = tipc_nlmsg_parse(nlmsg, &attrs);
err = nlmsg_parse_deprecated(nlmsg, GENL_HDRLEN,
attrbuf,
tipc_genl_family.maxattr,
tipc_genl_family.policy,
NULL);
if (err)
goto err_out;

err = (*cmd->format)(msg, attrs);
err = (*cmd->format)(msg, attrbuf);
if (err)
goto err_out;

Expand All @@ -231,6 +241,7 @@ static int __tipc_nl_compat_dumpit(struct tipc_nl_compat_cmd_dump *cmd,
err = 0;

err_out:
kfree(attrbuf);
tipc_dump_done(&cb);
kfree_skb(buf);

Expand Down

0 comments on commit c6c0861

Please sign in to comment.