From: Andrew Morton <akpm@linux-foundation.org>
To: yan <clouds.yan@gmail.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH 3/3 v2] proc: use kzalloc instead of kmalloc and memset
Date: Wed, 5 Sep 2012 14:37:00 -0700 [thread overview]
Message-ID: <20120905143700.7bfc3b1e.akpm@linux-foundation.org> (raw)
In-Reply-To: <1346847437-3308-4-git-send-email-clouds.yan@gmail.com>
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;
}
_
prev parent reply other threads:[~2012-09-05 21:37 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-05 12:17 [PATCH 0/3 v2] Trivial code clean for procfs yan
2012-09-05 12:17 ` [PATCH 1/3 v2] proc: return -ENOMEM when inode allocation failed yan
2012-09-05 12:17 ` [PATCH 2/3 v2] proc : no need to initialize proc_inode->fd in proc_get_inode yan
2012-09-05 12:17 ` [PATCH 3/3 v2] proc: use kzalloc instead of kmalloc and memset yan
2012-09-05 21:37 ` Andrew Morton [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20120905143700.7bfc3b1e.akpm@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=clouds.yan@gmail.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).