summaryrefslogtreecommitdiff
path: root/kernel/trace/tracing_map.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/trace/tracing_map.c')
-rw-r--r--kernel/trace/tracing_map.c33
1 files changed, 21 insertions, 12 deletions
diff --git a/kernel/trace/tracing_map.c b/kernel/trace/tracing_map.c
index 1921ade45be3..0dd7927df22a 100644
--- a/kernel/trace/tracing_map.c
+++ b/kernel/trace/tracing_map.c
@@ -324,7 +324,7 @@ static struct tracing_map_array *tracing_map_array_alloc(unsigned int n_elts,
struct tracing_map_array *a;
unsigned int i;
- a = kzalloc(sizeof(*a), GFP_KERNEL);
+ a = kzalloc_obj(*a);
if (!a)
return NULL;
@@ -386,13 +386,11 @@ static void tracing_map_elt_init_fields(struct tracing_map_elt *elt)
}
}
-static void tracing_map_elt_free(struct tracing_map_elt *elt)
+static void __tracing_map_elt_free(struct tracing_map_elt *elt)
{
if (!elt)
return;
- if (elt->map->ops && elt->map->ops->elt_free)
- elt->map->ops->elt_free(elt);
kfree(elt->fields);
kfree(elt->vars);
kfree(elt->var_set);
@@ -400,12 +398,23 @@ static void tracing_map_elt_free(struct tracing_map_elt *elt)
kfree(elt);
}
+static void tracing_map_elt_free(struct tracing_map_elt *elt)
+{
+ if (!elt)
+ return;
+
+ /* Only objects initialized with alloc_elt() should be passed to free_elt().*/
+ if (elt->map->ops && elt->map->ops->elt_free)
+ elt->map->ops->elt_free(elt);
+ __tracing_map_elt_free(elt);
+}
+
static struct tracing_map_elt *tracing_map_elt_alloc(struct tracing_map *map)
{
struct tracing_map_elt *elt;
int err = 0;
- elt = kzalloc(sizeof(*elt), GFP_KERNEL);
+ elt = kzalloc_obj(*elt);
if (!elt)
return ERR_PTR(-ENOMEM);
@@ -417,19 +426,19 @@ static struct tracing_map_elt *tracing_map_elt_alloc(struct tracing_map *map)
goto free;
}
- elt->fields = kcalloc(map->n_fields, sizeof(*elt->fields), GFP_KERNEL);
+ elt->fields = kzalloc_objs(*elt->fields, map->n_fields);
if (!elt->fields) {
err = -ENOMEM;
goto free;
}
- elt->vars = kcalloc(map->n_vars, sizeof(*elt->vars), GFP_KERNEL);
+ elt->vars = kzalloc_objs(*elt->vars, map->n_vars);
if (!elt->vars) {
err = -ENOMEM;
goto free;
}
- elt->var_set = kcalloc(map->n_vars, sizeof(*elt->var_set), GFP_KERNEL);
+ elt->var_set = kzalloc_objs(*elt->var_set, map->n_vars);
if (!elt->var_set) {
err = -ENOMEM;
goto free;
@@ -444,7 +453,7 @@ static struct tracing_map_elt *tracing_map_elt_alloc(struct tracing_map *map)
}
return elt;
free:
- tracing_map_elt_free(elt);
+ __tracing_map_elt_free(elt);
return ERR_PTR(err);
}
@@ -777,7 +786,7 @@ struct tracing_map *tracing_map_create(unsigned int map_bits,
map_bits > TRACING_MAP_BITS_MAX)
return ERR_PTR(-EINVAL);
- map = kzalloc(sizeof(*map), GFP_KERNEL);
+ map = kzalloc_obj(*map);
if (!map)
return ERR_PTR(-ENOMEM);
@@ -949,7 +958,7 @@ create_sort_entry(void *key, struct tracing_map_elt *elt)
{
struct tracing_map_sort_entry *sort_entry;
- sort_entry = kzalloc(sizeof(*sort_entry), GFP_KERNEL);
+ sort_entry = kzalloc_obj(*sort_entry);
if (!sort_entry)
return NULL;
@@ -1076,7 +1085,7 @@ int tracing_map_sort_entries(struct tracing_map *map,
struct tracing_map_sort_entry *sort_entry, **entries;
int i, n_entries, ret;
- entries = vmalloc(array_size(sizeof(sort_entry), map->max_elts));
+ entries = vmalloc_array(map->max_elts, sizeof(sort_entry));
if (!entries)
return -ENOMEM;