Make use of struct_size() helper instead of an open-coded calucation.
Showing the changes to kernel (3 of 3 files). Show all
Unified · Split
| @@ -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); |
| @@ -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; |
| @@ -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)); |