Commit f4f4be2b authored by Tejun Heo's avatar Tejun Heo

cgroup: use kzalloc() instead of kmalloc()

There's no point in using kmalloc() instead of the clearing variant
for trivial stuff.  We can live dangerously elsewhere.  Use kzalloc()
instead and drop 0 inits.

While at it, do trivial code reorganization in cgroup_file_open().

This patch doesn't introduce any functional changes.

v2: I was caught in the very distant past where list_del() didn't
    poison and the initial version converted list_del()s to
    list_del_init()s too.  Li and Kent took me out of the stasis
    chamber.
Signed-off-by: default avatarTejun Heo <tj@kernel.org>
Cc: Kent Overstreet <koverstreet@google.com>
Acked-by: default avatarLi Zefan <lizefan@huawei.com>
parent 69d0206c
...@@ -597,7 +597,7 @@ static int allocate_cgrp_cset_links(int count, struct list_head *tmp_links) ...@@ -597,7 +597,7 @@ static int allocate_cgrp_cset_links(int count, struct list_head *tmp_links)
INIT_LIST_HEAD(tmp_links); INIT_LIST_HEAD(tmp_links);
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
link = kmalloc(sizeof(*link), GFP_KERNEL); link = kzalloc(sizeof(*link), GFP_KERNEL);
if (!link) { if (!link) {
free_cgrp_cset_links(tmp_links); free_cgrp_cset_links(tmp_links);
return -ENOMEM; return -ENOMEM;
...@@ -658,7 +658,7 @@ static struct css_set *find_css_set(struct css_set *old_cset, ...@@ -658,7 +658,7 @@ static struct css_set *find_css_set(struct css_set *old_cset,
if (cset) if (cset)
return cset; return cset;
cset = kmalloc(sizeof(*cset), GFP_KERNEL); cset = kzalloc(sizeof(*cset), GFP_KERNEL);
if (!cset) if (!cset)
return NULL; return NULL;
...@@ -2475,10 +2475,12 @@ static int cgroup_file_open(struct inode *inode, struct file *file) ...@@ -2475,10 +2475,12 @@ static int cgroup_file_open(struct inode *inode, struct file *file)
cft = __d_cft(file->f_dentry); cft = __d_cft(file->f_dentry);
if (cft->read_map || cft->read_seq_string) { if (cft->read_map || cft->read_seq_string) {
struct cgroup_seqfile_state *state = struct cgroup_seqfile_state *state;
kzalloc(sizeof(*state), GFP_USER);
state = kzalloc(sizeof(*state), GFP_USER);
if (!state) if (!state)
return -ENOMEM; return -ENOMEM;
state->cft = cft; state->cft = cft;
state->cgroup = __d_cgrp(file->f_dentry->d_parent); state->cgroup = __d_cgrp(file->f_dentry->d_parent);
file->f_op = &cgroup_seqfile_operations; file->f_op = &cgroup_seqfile_operations;
...@@ -3511,7 +3513,7 @@ static struct cgroup_pidlist *cgroup_pidlist_find(struct cgroup *cgrp, ...@@ -3511,7 +3513,7 @@ static struct cgroup_pidlist *cgroup_pidlist_find(struct cgroup *cgrp,
} }
} }
/* entry not found; create a new one */ /* entry not found; create a new one */
l = kmalloc(sizeof(struct cgroup_pidlist), GFP_KERNEL); l = kzalloc(sizeof(struct cgroup_pidlist), GFP_KERNEL);
if (!l) { if (!l) {
mutex_unlock(&cgrp->pidlist_mutex); mutex_unlock(&cgrp->pidlist_mutex);
return l; return l;
...@@ -3520,8 +3522,6 @@ static struct cgroup_pidlist *cgroup_pidlist_find(struct cgroup *cgrp, ...@@ -3520,8 +3522,6 @@ static struct cgroup_pidlist *cgroup_pidlist_find(struct cgroup *cgrp,
down_write(&l->mutex); down_write(&l->mutex);
l->key.type = type; l->key.type = type;
l->key.ns = get_pid_ns(ns); l->key.ns = get_pid_ns(ns);
l->use_count = 0; /* don't increment here */
l->list = NULL;
l->owner = cgrp; l->owner = cgrp;
list_add(&l->links, &cgrp->pidlists); list_add(&l->links, &cgrp->pidlists);
mutex_unlock(&cgrp->pidlist_mutex); mutex_unlock(&cgrp->pidlist_mutex);
......
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