Skip to content

Commit

Permalink
Issue 3: Fix double skb allocation
Browse files Browse the repository at this point in the history
Also fill msg only after skb allocation succeed
  • Loading branch information
evertonen authored and a-zaki committed Feb 2, 2019
1 parent 3756ed4 commit f3c564e
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions kernel/genl_ex.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ static void greet_group(unsigned int group)
char msg[GENL_TEST_ATTR_MSG_MAX];
struct sk_buff* skb = genlmsg_new(NLMSG_DEFAULT_SIZE, flags);

snprintf(msg, GENL_TEST_ATTR_MSG_MAX, "Hello group %s\n",
genl_test_mcgrp_names[group]);
skb = genlmsg_new(NLMSG_DEFAULT_SIZE, flags);

if (!skb) {
printk(KERN_ERR "%d: OOM!!", __LINE__);
return;
Expand All @@ -34,6 +30,9 @@ static void greet_group(unsigned int group)
goto nlmsg_fail;
}

snprintf(msg, GENL_TEST_ATTR_MSG_MAX, "Hello group %s\n",
genl_test_mcgrp_names[group]);

res = nla_put_string(skb, GENL_TEST_ATTR_MSG, msg);
if (res) {
printk(KERN_ERR "%d: err %d ", __LINE__, res);
Expand Down

0 comments on commit f3c564e

Please sign in to comment.