Skip to content

Commit ee080e6

Browse files
eparisAl Viro
authored andcommitted
Audit: cleanup netlink mesg handling
The audit handling of netlink messages is all over the place. Clean things up, use predetermined macros, generally make it more readable. Signed-off-by: Eric Paris <eparis@redhat.com>
1 parent 038cbcf commit ee080e6

1 file changed

Lines changed: 15 additions & 15 deletions

File tree

‎kernel/audit.c‎

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -528,22 +528,20 @@ struct sk_buff *audit_make_reply(int pid, int seq, int type, int done,
528528
{
529529
struct sk_buff *skb;
530530
struct nlmsghdr *nlh;
531-
int len = NLMSG_SPACE(size);
532531
void *data;
533532
int flags = multi ? NLM_F_MULTI : 0;
534533
int t = done ? NLMSG_DONE : type;
535534

536-
skb = alloc_skb(len, GFP_KERNEL);
535+
skb = nlmsg_new(size, GFP_KERNEL);
537536
if (!skb)
538537
return NULL;
539538

540-
nlh = NLMSG_PUT(skb, pid, seq, t, size);
541-
nlh->nlmsg_flags = flags;
542-
data = NLMSG_DATA(nlh);
539+
nlh = NLMSG_NEW(skb, pid, seq, t, size, flags);
540+
data = NLMSG_DATA(nlh);
543541
memcpy(data, payload, size);
544542
return skb;
545543

546-
nlmsg_failure: /* Used by NLMSG_PUT */
544+
nlmsg_failure: /* Used by NLMSG_NEW */
547545
if (skb)
548546
kfree_skb(skb);
549547
return NULL;
@@ -1083,18 +1081,20 @@ static struct audit_buffer * audit_buffer_alloc(struct audit_context *ctx,
10831081
goto err;
10841082
}
10851083

1086-
ab->skb = alloc_skb(AUDIT_BUFSIZ, gfp_mask);
1087-
if (!ab->skb)
1088-
goto err;
1089-
10901084
ab->ctx = ctx;
10911085
ab->gfp_mask = gfp_mask;
1092-
nlh = (struct nlmsghdr *)skb_put(ab->skb, NLMSG_SPACE(0));
1093-
nlh->nlmsg_type = type;
1094-
nlh->nlmsg_flags = 0;
1095-
nlh->nlmsg_pid = 0;
1096-
nlh->nlmsg_seq = 0;
1086+
1087+
ab->skb = nlmsg_new(AUDIT_BUFSIZ, gfp_mask);
1088+
if (!ab->skb)
1089+
goto nlmsg_failure;
1090+
1091+
nlh = NLMSG_NEW(ab->skb, 0, 0, type, 0, 0);
1092+
10971093
return ab;
1094+
1095+
nlmsg_failure: /* Used by NLMSG_NEW */
1096+
kfree_skb(ab->skb);
1097+
ab->skb = NULL;
10981098
err:
10991099
audit_buffer_free(ab);
11001100
return NULL;

0 commit comments

Comments
 (0)