Commit 47b0edcb authored by Thomas Meyer's avatar Thomas Meyer Committed by Steven Rostedt

tracing/trivial: Use kcalloc instead of kzalloc to allocate array

The advantage of kcalloc is, that will prevent integer overflows which could
result from the multiplication of number of elements and size and it is also
a bit nicer to read.

The semantic patch that makes this change is available
in https://lkml.org/lkml/2011/11/25/107

Link: http://lkml.kernel.org/r/1322600880.1534.347.camel@localhost.localdomainSigned-off-by: default avatarThomas Meyer <thomas@m3y3r.de>
Signed-off-by: default avatarSteven Rostedt <rostedt@goodmis.org>
parent 95100358
...@@ -1129,7 +1129,7 @@ static struct ftrace_hash *alloc_ftrace_hash(int size_bits) ...@@ -1129,7 +1129,7 @@ static struct ftrace_hash *alloc_ftrace_hash(int size_bits)
return NULL; return NULL;
size = 1 << size_bits; size = 1 << size_bits;
hash->buckets = kzalloc(sizeof(*hash->buckets) * size, GFP_KERNEL); hash->buckets = kcalloc(size, sizeof(*hash->buckets), GFP_KERNEL);
if (!hash->buckets) { if (!hash->buckets) {
kfree(hash); kfree(hash);
......
...@@ -685,7 +685,7 @@ find_event_field(struct ftrace_event_call *call, char *name) ...@@ -685,7 +685,7 @@ find_event_field(struct ftrace_event_call *call, char *name)
static int __alloc_pred_stack(struct pred_stack *stack, int n_preds) static int __alloc_pred_stack(struct pred_stack *stack, int n_preds)
{ {
stack->preds = kzalloc(sizeof(*stack->preds)*(n_preds + 1), GFP_KERNEL); stack->preds = kcalloc(n_preds + 1, sizeof(*stack->preds), GFP_KERNEL);
if (!stack->preds) if (!stack->preds)
return -ENOMEM; return -ENOMEM;
stack->index = n_preds; stack->index = n_preds;
...@@ -826,8 +826,7 @@ static int __alloc_preds(struct event_filter *filter, int n_preds) ...@@ -826,8 +826,7 @@ static int __alloc_preds(struct event_filter *filter, int n_preds)
if (filter->preds) if (filter->preds)
__free_preds(filter); __free_preds(filter);
filter->preds = filter->preds = kcalloc(n_preds, sizeof(*filter->preds), GFP_KERNEL);
kzalloc(sizeof(*filter->preds) * n_preds, GFP_KERNEL);
if (!filter->preds) if (!filter->preds)
return -ENOMEM; return -ENOMEM;
...@@ -1486,7 +1485,7 @@ static int fold_pred(struct filter_pred *preds, struct filter_pred *root) ...@@ -1486,7 +1485,7 @@ static int fold_pred(struct filter_pred *preds, struct filter_pred *root)
children = count_leafs(preds, &preds[root->left]); children = count_leafs(preds, &preds[root->left]);
children += count_leafs(preds, &preds[root->right]); children += count_leafs(preds, &preds[root->right]);
root->ops = kzalloc(sizeof(*root->ops) * children, GFP_KERNEL); root->ops = kcalloc(children, sizeof(*root->ops), GFP_KERNEL);
if (!root->ops) if (!root->ops)
return -ENOMEM; return -ENOMEM;
......
...@@ -468,8 +468,8 @@ int __init init_ftrace_syscalls(void) ...@@ -468,8 +468,8 @@ int __init init_ftrace_syscalls(void)
unsigned long addr; unsigned long addr;
int i; int i;
syscalls_metadata = kzalloc(sizeof(*syscalls_metadata) * syscalls_metadata = kcalloc(NR_syscalls, sizeof(*syscalls_metadata),
NR_syscalls, GFP_KERNEL); GFP_KERNEL);
if (!syscalls_metadata) { if (!syscalls_metadata) {
WARN_ON(1); WARN_ON(1);
return -ENOMEM; return -ENOMEM;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment