All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pekka Enberg <penberg@cs.helsinki.fi>
To: Chris Wright <chrisw@osdl.org>
Cc: arjanv@redhat.com, linux-kernel@vger.kernel.org, tiwai@suse.de
Subject: Re: [PATCH] ALSA: Remove subsystem-specific malloc (1/8)
Date: Thu, 10 Jun 2004 00:18:13 +0300	[thread overview]
Message-ID: <1086815893.13026.79.camel@cherry> (raw)
In-Reply-To: <20040609140056.E21045@build.pdx.osdl.net>

On Thu, 2004-06-10 at 00:00, Chris Wright wrote:
> > +	void *ret = kmalloc(n * size, flags);
> 
> This is only C99, and will make some compilers spit up warning.

Indeed, I'd better fix that as well then ;)

		Pekka

diff -urN linux-2.6.6/include/linux/slab.h kcalloc-2.6.6/include/linux/slab.h
--- linux-2.6.6/include/linux/slab.h	2004-06-09 22:56:11.874249056 +0300
+++ kcalloc-2.6.6/include/linux/slab.h	2004-06-09 23:03:10.597593432 +0300
@@ -95,6 +95,7 @@
 	return __kmalloc(size, flags);
 }
 
+extern void *kcalloc(size_t, size_t, int);
 extern void kfree(const void *);
 extern unsigned int ksize(const void *);
 
diff -urN linux-2.6.6/mm/slab.c kcalloc-2.6.6/mm/slab.c
--- linux-2.6.6/mm/slab.c	2004-06-09 22:59:13.081701336 +0300
+++ kcalloc-2.6.6/mm/slab.c	2004-06-10 00:08:44.004624672 +0300
@@ -2332,6 +2332,27 @@
 EXPORT_SYMBOL(kmem_cache_free);
 
 /**
+ * kcalloc - allocate memory for an array. The memory is set to zero.
+ * @n: number of elements.
+ * @size: element size.
+ * @flags: the type of memory to allocate.
+ */
+void *kcalloc(size_t n, size_t size, int flags)
+{
+	void *ret = NULL;
+
+	if (n != 0 && size > INT_MAX / n)
+		return ret;
+
+	ret = kmalloc(n * size, flags);
+	if (ret)
+		memset(ret, 0, n * size);
+	return ret;
+}
+
+EXPORT_SYMBOL(kcalloc);
+
+/**
  * kfree - free previously allocated memory
  * @objp: pointer returned by kmalloc.
  *



  reply	other threads:[~2004-06-09 21:15 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-06-08 21:24 [PATCH] ALSA: Remove subsystem-specific malloc (1/8) Pekka J Enberg
2004-06-09 18:34 ` Chris Wright
2004-06-09 20:13   ` Pekka Enberg
2004-06-09 20:21     ` Arjan van de Ven
2004-06-09 20:40       ` Valdis.Kletnieks
2004-06-09 20:57       ` Chris Wright
2004-06-09 20:57       ` Pekka Enberg
2004-06-09 20:59         ` Arjan van de Ven
2004-06-09 21:07           ` Pekka Enberg
2004-06-11 10:09             ` Takashi Iwai
2004-06-11 10:43               ` Pekka J Enberg
2004-06-11 10:53               ` Pekka J Enberg
2004-06-09 21:00         ` [PATCH] " Chris Wright
2004-06-09 21:18           ` Pekka Enberg [this message]
2004-06-10  5:08         ` dean gaudet
2004-06-10 12:32           ` Dave Jones

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=1086815893.13026.79.camel@cherry \
    --to=penberg@cs.helsinki.fi \
    --cc=arjanv@redhat.com \
    --cc=chrisw@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tiwai@suse.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.