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

From: yan yan
Date: Tue Sep 04 2012 - 05:10:34 EST


2012/9/4 Ryan Mallon <rmallon@xxxxxxxxx>
>
> On 04/09/12 00:14, yan wrote:
> > Signed-off-by: yan <clouds.yan@xxxxxxxxx>
> > ---
> > 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.

Oh, I didn't notice that actually. Thank you.
--
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/