Re: [PATCH 3/3 v2] proc: use kzalloc instead of kmalloc and memset

From: Andrew Morton
Date: Wed Sep 05 2012 - 17:36:56 EST


On Wed, 5 Sep 2012 20:17:17 +0800
yan <clouds.yan@xxxxxxxxx> wrote:

> Part of the memory will be written twice after this change, but that
> should be negligible.
>
> ...
>
> --- a/fs/proc/generic.c
> +++ b/fs/proc/generic.c
> @@ -616,10 +616,9 @@ static struct proc_dir_entry *__proc_create(struct proc_dir_entry **parent,
>
> len = strlen(fn);
>
> - ent = kmalloc(sizeof(struct proc_dir_entry) + len + 1, GFP_KERNEL);
> + ent = kzalloc(sizeof(struct proc_dir_entry) + len + 1, GFP_KERNEL);
> if (!ent) goto out;
>
> - memset(ent, 0, sizeof(struct proc_dir_entry));
> memcpy(ent->name, fn, len + 1);
> ent->namelen = len;
> ent->mode = mode;

I'm not sure that I really like the idea of adding this additional
overhead. But sure, it won't matter to anyone at all.

While we're digging around in __proc_create(), how about we fix a few
other things?


From: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
Subject: proc-use-kzalloc-instead-of-kmalloc-and-memset-fix

fix __proc_create() coding-style issues, remove unneeded zero-initialisations

Cc: yan <clouds.yan@xxxxxxxxx>
Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
---

fs/proc/generic.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)

diff -puN fs/proc/generic.c~proc-use-kzalloc-instead-of-kmalloc-and-memset-fix fs/proc/generic.c
--- a/fs/proc/generic.c~proc-use-kzalloc-instead-of-kmalloc-and-memset-fix
+++ a/fs/proc/generic.c
@@ -605,7 +605,8 @@ static struct proc_dir_entry *__proc_cre
unsigned int len;

/* make sure name is valid */
- if (!name || !strlen(name)) goto out;
+ if (!name || !strlen(name))
+ goto out;

if (xlate_proc_name(name, parent, &fn) != 0)
goto out;
@@ -617,18 +618,17 @@ static struct proc_dir_entry *__proc_cre
len = strlen(fn);

ent = kzalloc(sizeof(struct proc_dir_entry) + len + 1, GFP_KERNEL);
- if (!ent) goto out;
+ if (!ent)
+ goto out;

memcpy(ent->name, fn, len + 1);
ent->namelen = len;
ent->mode = mode;
ent->nlink = nlink;
atomic_set(&ent->count, 1);
- ent->pde_users = 0;
spin_lock_init(&ent->pde_unload_lock);
- ent->pde_unload_completion = NULL;
INIT_LIST_HEAD(&ent->pde_openers);
- out:
+out:
return ent;
}

_

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/