History

audit: use struct_size() helper in kmalloc()

Make use of struct_size() helper instead of an open-coded calucation.

Xiu Jianfeng committed 4 years ago

Commit bc6e60a1 parent fa55b7d3 files · +3 −3Browse files

Showing the changes to kernel (3 of 3 files). Show all

Unified · Split

3 files
  1. kernel/audit.c +1 −1
  2. kernel/audit_tree.c +1 −1
  3. kernel/auditfilter.c +1 −1
kernel/audit.c+1−1
@@ -1446,7 +1446,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh) · 1445 unmodified lines
1446 if (err)1446 if (err)
1447 return err;1447 return err;
1448 }1448 }
1449 sig_data = kmalloc(sizeof(*sig_data) + len, GFP_KERNEL);1449 sig_data = kmalloc(struct_size(sig_data, ctx, len), GFP_KERNEL);
1450 if (!sig_data) {1450 if (!sig_data) {
1451 if (audit_sig_sid)1451 if (audit_sig_sid)
1452 security_release_secctx(ctx, len);1452 security_release_secctx(ctx, len);
kernel/audit_tree.c+1−1
@@ -94,7 +94,7 @@ static struct audit_tree *alloc_tree(const char *s) · 93 unmodified lines
94{94{
95 struct audit_tree *tree;95 struct audit_tree *tree;
96 96
97 tree = kmalloc(sizeof(struct audit_tree) + strlen(s) + 1, GFP_KERNEL);97 tree = kmalloc(struct_size(tree, pathname, strlen(s) + 1), GFP_KERNEL);
98 if (tree) {98 if (tree) {
99 refcount_set(&tree->count, 1);99 refcount_set(&tree->count, 1);
100 tree->goner = 0;100 tree->goner = 0;
kernel/auditfilter.c+1−1
@@ -637,7 +637,7 @@ static struct audit_rule_data *audit_krule_to_data(struct audit_krule *krule) · 636 unmodified lines
637 void *bufp;637 void *bufp;
638 int i;638 int i;
639 639
640 data = kmalloc(sizeof(*data) + krule->buflen, GFP_KERNEL);640 data = kmalloc(struct_size(data, buf, krule->buflen), GFP_KERNEL);
641 if (unlikely(!data))641 if (unlikely(!data))
642 return NULL;642 return NULL;
643 memset(data, 0, sizeof(*data));643 memset(data, 0, sizeof(*data));

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t