netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [patch 4/5][RFC] Implement devm_kcalloc
@ 2007-08-02 22:45 Brandon Philips
  2007-08-03  9:20 ` Tejun Heo
  0 siblings, 1 reply; 2+ messages in thread
From: Brandon Philips @ 2007-08-02 22:45 UTC (permalink / raw)
  To: netdev; +Cc: teheo, Brandon Philips

[-- Attachment #1: kcalloc-devres.patch --]
[-- Type: text/plain, Size: 1711 bytes --]

devm_kcalloc is a simple wrapper around devm_kzalloc for arrays.  This is
needed because kcalloc is often used in network devices. 

Signed-off-by: Brandon Philips <bphilips@suse.de>

---
 drivers/base/devres.c  |   16 ++++++++++++++++
 include/linux/device.h |    1 +
 2 files changed, 17 insertions(+)

Index: linux-2.6/drivers/base/devres.c
===================================================================
--- linux-2.6.orig/drivers/base/devres.c
+++ linux-2.6/drivers/base/devres.c
@@ -630,6 +630,22 @@ void * devm_kzalloc(struct device *dev, 
 EXPORT_SYMBOL_GPL(devm_kzalloc);
 
 /**
+ * devm_kcalloc - resource-managed kcalloc
+ * @dev: Device to allocate memory for
+ * @n: number of elements.
+ * @size: element size.
+ * @flags: the type of memory to allocate.
+ */
+inline void * devm_kcalloc(struct device * dev, size_t n, size_t size,
+			   gfp_t flags)
+{
+        if (n != 0 && size > ULONG_MAX / n)
+                return NULL;
+        return devm_kzalloc(dev, n * size, flags);
+}
+EXPORT_SYMBOL_GPL(devm_kcalloc);
+
+/**
  * devm_kfree - Resource-managed kfree
  * @dev: Device this memory belongs to
  * @p: Memory to free
Index: linux-2.6/include/linux/device.h
===================================================================
--- linux-2.6.orig/include/linux/device.h
+++ linux-2.6/include/linux/device.h
@@ -402,6 +402,7 @@ extern int devres_release_group(struct d
 
 /* managed kzalloc/kfree for device drivers, no kmalloc, always use kzalloc */
 extern void *devm_kzalloc(struct device *dev, size_t size, gfp_t gfp);
+extern void *devm_kcalloc(struct device *dev, size_t n, size_t size, gfp_t flags);
 extern void devm_kfree(struct device *dev, void *p);
 
 struct device {

-- 

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [patch 4/5][RFC] Implement devm_kcalloc
  2007-08-02 22:45 [patch 4/5][RFC] Implement devm_kcalloc Brandon Philips
@ 2007-08-03  9:20 ` Tejun Heo
  0 siblings, 0 replies; 2+ messages in thread
From: Tejun Heo @ 2007-08-03  9:20 UTC (permalink / raw)
  To: Brandon Philips; +Cc: netdev, teheo, Brandon Philips

On Thu, Aug 02, 2007 at 03:45:45PM -0700, Brandon Philips wrote:
>  /**
> + * devm_kcalloc - resource-managed kcalloc
> + * @dev: Device to allocate memory for
> + * @n: number of elements.
> + * @size: element size.
> + * @flags: the type of memory to allocate.
> + */
> +inline void * devm_kcalloc(struct device * dev, size_t n, size_t size,
> +			   gfp_t flags)
> +{
> +        if (n != 0 && size > ULONG_MAX / n)
> +                return NULL;
> +        return devm_kzalloc(dev, n * size, flags);
> +}
> +EXPORT_SYMBOL_GPL(devm_kcalloc);

Please drop inline.  It's meaningless.

Other than that, Acked-by: Tejun Heo <htejun@gmail.com>

-- 
tejun

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-08-03  9:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-08-02 22:45 [patch 4/5][RFC] Implement devm_kcalloc Brandon Philips
2007-08-03  9:20 ` Tejun Heo

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