lkml.org 
[lkml]   [2012]   [Sep]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
SubjectRe: [PATCH 3/3 v2] proc: use kzalloc instead of kmalloc and memset
On Wed,  5 Sep 2012 20:17:17 +0800
yan <clouds.yan@gmail.com> 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@linux-foundation.org>
Subject: proc-use-kzalloc-instead-of-kmalloc-and-memset-fix

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

Cc: yan <clouds.yan@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

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;
}

_


\
 
 \ /
  Last update: 2012-09-06 00:02    [W:1.241 / U:0.024 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site