diff options
author | Joe Perches <joe@perches.com> | 2013-10-11 16:11:38 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2013-10-16 21:29:07 -0400 |
commit | 64c862a839a8db2c02bbaa88b923d13e1208919d (patch) | |
tree | 0b3765aec1193c5040f8f840edd36876b7412dd5 /include | |
parent | d723a92dd465d549bf79dd481c09d59f0be02936 (diff) |
devres: add kernel standard devm_k.alloc functions
Currently, devm_ managed memory only supports kzalloc.
Convert the devm_kzalloc implementation to devm_kmalloc and remove the
complete memset to 0 but still set the initial struct devres header and
whatever padding before data to 0.
Add the other normal alloc variants as static inlines with __GFP_ZERO
added to the gfp flag where appropriate:
devm_kzalloc
devm_kcalloc
devm_kmalloc_array
Add gfp.h to device.h for the newly added static inlines.
akpm: the current API forces us to replace kmalloc() with kzalloc() when
performing devm_ conversions. This adds a relatively minor overhead.
More significantly, it will defeat kmemcheck used-uninitialized checking,
and for a particular driver, losing used-uninitialised checking for their
core controlling data structures will significantly degrade kmemcheck
usefulness.
Signed-off-by: Joe Perches <joe@perches.com>
Cc: Tejun Heo <tj@kernel.org>
Cc: Sangjung Woo <sangjung.woo@samsung.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'include')
-rw-r--r-- | include/linux/device.h | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/include/linux/device.h b/include/linux/device.h index 94638efa0bf8..5e44cff5bced 100644 --- a/include/linux/device.h +++ b/include/linux/device.h | |||
@@ -26,6 +26,7 @@ | |||
26 | #include <linux/atomic.h> | 26 | #include <linux/atomic.h> |
27 | #include <linux/ratelimit.h> | 27 | #include <linux/ratelimit.h> |
28 | #include <linux/uidgid.h> | 28 | #include <linux/uidgid.h> |
29 | #include <linux/gfp.h> | ||
29 | #include <asm/device.h> | 30 | #include <asm/device.h> |
30 | 31 | ||
31 | struct device; | 32 | struct device; |
@@ -606,8 +607,24 @@ extern void devres_close_group(struct device *dev, void *id); | |||
606 | extern void devres_remove_group(struct device *dev, void *id); | 607 | extern void devres_remove_group(struct device *dev, void *id); |
607 | extern int devres_release_group(struct device *dev, void *id); | 608 | extern int devres_release_group(struct device *dev, void *id); |
608 | 609 | ||
609 | /* managed kzalloc/kfree for device drivers, no kmalloc, always use kzalloc */ | 610 | /* managed devm_k.alloc/kfree for device drivers */ |
610 | extern void *devm_kzalloc(struct device *dev, size_t size, gfp_t gfp); | 611 | extern void *devm_kmalloc(struct device *dev, size_t size, gfp_t gfp); |
612 | static inline void *devm_kzalloc(struct device *dev, size_t size, gfp_t gfp) | ||
613 | { | ||
614 | return devm_kmalloc(dev, size, gfp | __GFP_ZERO); | ||
615 | } | ||
616 | static inline void *devm_kmalloc_array(struct device *dev, | ||
617 | size_t n, size_t size, gfp_t flags) | ||
618 | { | ||
619 | if (size != 0 && n > SIZE_MAX / size) | ||
620 | return NULL; | ||
621 | return devm_kmalloc(dev, n * size, flags); | ||
622 | } | ||
623 | static inline void *devm_kcalloc(struct device *dev, | ||
624 | size_t n, size_t size, gfp_t flags) | ||
625 | { | ||
626 | return devm_kmalloc_array(dev, n, size, flags | __GFP_ZERO); | ||
627 | } | ||
611 | extern void devm_kfree(struct device *dev, void *p); | 628 | extern void devm_kfree(struct device *dev, void *p); |
612 | 629 | ||
613 | void __iomem *devm_ioremap_resource(struct device *dev, struct resource *res); | 630 | void __iomem *devm_ioremap_resource(struct device *dev, struct resource *res); |