mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Breno Silva" <brenosp@brasilsec.com.br>
To: "Rolf Eike Beer" <eike-kernel@sf-tec.de>, <linux-kernel@vger.kernel.org>
Subject: Re: [RFC][PATCH] kmalloc + memset(foo, 0, bar) = kmalloc0
Date: Thu, 11 Sep 2003 10:58:27 -0300	[thread overview]
Message-ID: <002101c3786c$c7857840$131215ac@poslab219> (raw)
In-Reply-To: <200309111540.58729@bilbo.math.uni-mannheim.de>

Do correct kmalloc+memset in new funcion.

Breno
----- Original Message -----
From: "Rolf Eike Beer" <eike-kernel@sf-tec.de>
To: <linux-kernel@vger.kernel.org>
Sent: Thursday, September 11, 2003 10:40 AM
Subject: [RFC][PATCH] kmalloc + memset(foo, 0, bar) = kmalloc0


> Hi,
>
> a (very) simple grep in drivers/ showed more than 300 matches of code like
> this:
>
> foo = kmalloc(bar, baz);
> if (! foo)
> return -ENOMEM;
> memset(foo, 0, sizeof(foo));
>
> Why not add a small inlined function doing the memset for us
> and reducing the code to
>
> foo = kmalloc0(bar, baz);
> if (! foo)
> return -ENOMEM;
>
> Eike
>
> --- linux-2.6.0-test5-bk1/include/linux/slab.h 2003-09-11
15:19:40.000000000 +0200
> +++ linux-2.6.0-test5-bk1-caliban/include/linux/slab.h 2003-09-11
15:22:56.000000000 +0200
> @@ -14,6 +14,7 @@
>  #include <linux/config.h> /* kmalloc_sizes.h needs CONFIG_ options */
>  #include <linux/gfp.h>
>  #include <linux/types.h>
> +#include <linux/string.h> /* for memset */
>  #include <asm/page.h> /* kmalloc_sizes.h needs PAGE_SIZE */
>  #include <asm/cache.h> /* kmalloc_sizes.h needs L1_CACHE_BYTES */
>
> @@ -97,6 +98,16 @@
>   return __kmalloc(size, flags);
>  }
>
> +static inline void *kmalloc0(size_t size, int flags)
> +{
> + void *res = kmalloc(size, flags);
> +
> + if (res != NULL)
> + memset(res, 0, size);
> +
> + return res;
> +}
> +
>  extern void kfree(const void *);
>  extern unsigned int ksize(const void *);
>
> -
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/


      parent reply	other threads:[~2003-09-11 13:58 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-09-11 13:40 Rolf Eike Beer
2003-09-11 13:45 ` viro
2003-09-11 14:11   ` Rolf Eike Beer
2003-09-11 17:09   ` Jamie Lokier
2003-09-11 21:58     ` J.A. Magallon
2003-09-11 22:12       ` Alan Cox
2003-09-11 22:25         ` J.A. Magallon
2003-09-11 13:58 ` Breno Silva [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='002101c3786c$c7857840$131215ac@poslab219' \
    --to=brenosp@brasilsec.com.br \
    --cc=eike-kernel@sf-tec.de \
    --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

all inboxes | Powered by JetHome®