linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ryan Mallon <rmallon@gmail.com>
To: yan <clouds.yan@gmail.com>
Cc: akpm@linux-foundation.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 3/3] proc: use kzalloc instead of kmalloc and memset
Date: Tue, 04 Sep 2012 10:44:12 +1000	[thread overview]
Message-ID: <50454EDC.7050101@gmail.com> (raw)
In-Reply-To: <1346681648-21427-4-git-send-email-clouds.yan@gmail.com>

On 04/09/12 00:14, yan wrote:
> Signed-off-by: yan <clouds.yan@gmail.com>
> ---
>  fs/proc/generic.c |    3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/fs/proc/generic.c b/fs/proc/generic.c
> index 9e8f631..38de015 100644
> --- 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;

Note that this change results in slightly different behaviour. Before
your change only sizeof(struct proc_dir_entry) is zero'ed by memset, and
then the name is filled in (the len + 1 part). After your change the
structure and the name field are both zeroed, so the name field is being
written to twice. The cost is probably negligible though.

~Ryan



  reply	other threads:[~2012-09-04  0:44 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-03 14:14 [PATCH 0/3] Trivial code clean for procfs yan
2012-09-03 14:14 ` [PATCH 1/3] proc: return -ENOMEM when inode allocation failed yan
2012-09-04  0:38   ` Ryan Mallon
2012-09-04  3:02   ` Cong Wang
2012-09-04  9:22     ` yan yan
2012-09-04 22:41       ` Andrew Morton
2012-09-05  7:15       ` Cong Wang
2012-09-05  7:57         ` yan yan
2012-09-03 14:14 ` [PATCH 2/3] proc : no need to initialize proc_inode->fd in proc_get_inode yan
2012-09-04 22:49   ` Andrew Morton
2012-09-03 14:14 ` [PATCH 3/3] proc: use kzalloc instead of kmalloc and memset yan
2012-09-04  0:44   ` Ryan Mallon [this message]
2012-09-04  9:10     ` yan yan

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=50454EDC.7050101@gmail.com \
    --to=rmallon@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=clouds.yan@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --subject='Re: [PATCH 3/3] proc: use kzalloc instead of kmalloc and memset' \
    /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

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).