Make use of struct_size() helper instead of an open-coded calucation.
Unified · Split
| @@ -1446,7 +1446,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh) · 1445 unmodified lines | ||
| 1446 | 1446 | if (err) |
| 1447 | 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 | 1450 | if (!sig_data) { |
| 1451 | 1451 | if (audit_sig_sid) |
| 1452 | 1452 | security_release_secctx(ctx, len); |
| @@ -94,7 +94,7 @@ static struct audit_tree *alloc_tree(const char *s) · 93 unmodified lines | ||
| 94 | 94 | { |
| 95 | 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 | 98 | if (tree) { |
| 99 | 99 | refcount_set(&tree->count, 1); |
| 100 | 100 | tree->goner = 0; |
| @@ -637,7 +637,7 @@ static struct audit_rule_data *audit_krule_to_data(struct audit_krule *krule) · 636 unmodified lines | ||
| 637 | 637 | void *bufp; |
| 638 | 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 | 641 | if (unlikely(!data)) |
| 642 | 642 | return NULL; |
| 643 | 643 | memset(data, 0, sizeof(*data)); |