Subject: [merged] devres-add-kernel-standard-devm_kalloc-functions.patch removed from -mm tree To: joe@xxxxxxxxxxx,gregkh@xxxxxxxxxxxxxxxxxxx,sangjung.woo@xxxxxxxxxxx,tj@xxxxxxxxxx,mm-commits@xxxxxxxxxxxxxxx From: akpm@xxxxxxxxxxxxxxxxxxxx Date: Thu, 31 Oct 2013 10:59:47 -0700 The patch titled Subject: devres: add kernel standard devm_k.alloc functions has been removed from the -mm tree. Its filename was devres-add-kernel-standard-devm_kalloc-functions.patch This patch was dropped because it was merged into mainline or a subsystem tree ------------------------------------------------------ From: Joe Perches <joe@xxxxxxxxxxx> Subject: 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@xxxxxxxxxxx> Cc: Tejun Heo <tj@xxxxxxxxxx> Cc: Greg KH <gregkh@xxxxxxxxxxxxxxxxxxx> Cc: Sangjung Woo <sangjung.woo@xxxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- drivers/base/devres.c | 27 ++++++++++++++++----------- include/linux/device.h | 21 +++++++++++++++++++-- 2 files changed, 35 insertions(+), 13 deletions(-) diff -puN drivers/base/devres.c~devres-add-kernel-standard-devm_kalloc-functions drivers/base/devres.c --- a/drivers/base/devres.c~devres-add-kernel-standard-devm_kalloc-functions +++ a/drivers/base/devres.c @@ -91,7 +91,8 @@ static __always_inline struct devres * a if (unlikely(!dr)) return NULL; - memset(dr, 0, tot_size); + memset(dr, 0, offsetof(struct devres, data)); + INIT_LIST_HEAD(&dr->node.entry); dr->node.release = release; return dr; @@ -745,58 +746,62 @@ void devm_remove_action(struct device *d EXPORT_SYMBOL_GPL(devm_remove_action); /* - * Managed kzalloc/kfree + * Managed kmalloc/kfree */ -static void devm_kzalloc_release(struct device *dev, void *res) +static void devm_kmalloc_release(struct device *dev, void *res) { /* noop */ } -static int devm_kzalloc_match(struct device *dev, void *res, void *data) +static int devm_kmalloc_match(struct device *dev, void *res, void *data) { return res == data; } /** - * devm_kzalloc - Resource-managed kzalloc + * devm_kmalloc - Resource-managed kmalloc * @dev: Device to allocate memory for * @size: Allocation size * @gfp: Allocation gfp flags * - * Managed kzalloc. Memory allocated with this function is + * Managed kmalloc. Memory allocated with this function is * automatically freed on driver detach. Like all other devres * resources, guaranteed alignment is unsigned long long. * * RETURNS: * Pointer to allocated memory on success, NULL on failure. */ -void * devm_kzalloc(struct device *dev, size_t size, gfp_t gfp) +void * devm_kmalloc(struct device *dev, size_t size, gfp_t gfp) { struct devres *dr; /* use raw alloc_dr for kmalloc caller tracing */ - dr = alloc_dr(devm_kzalloc_release, size, gfp); + dr = alloc_dr(devm_kmalloc_release, size, gfp); if (unlikely(!dr)) return NULL; + /* + * This is named devm_kzalloc_release for historical reasons + * The initial implementation did not support kmalloc, only kzalloc + */ set_node_dbginfo(&dr->node, "devm_kzalloc_release", size); devres_add(dev, dr->data); return dr->data; } -EXPORT_SYMBOL_GPL(devm_kzalloc); +EXPORT_SYMBOL_GPL(devm_kmalloc); /** * devm_kfree - Resource-managed kfree * @dev: Device this memory belongs to * @p: Memory to free * - * Free memory allocated with devm_kzalloc(). + * Free memory allocated with devm_kmalloc(). */ void devm_kfree(struct device *dev, void *p) { int rc; - rc = devres_destroy(dev, devm_kzalloc_release, devm_kzalloc_match, p); + rc = devres_destroy(dev, devm_kmalloc_release, devm_kmalloc_match, p); WARN_ON(rc); } EXPORT_SYMBOL_GPL(devm_kfree); diff -puN include/linux/device.h~devres-add-kernel-standard-devm_kalloc-functions include/linux/device.h --- a/include/linux/device.h~devres-add-kernel-standard-devm_kalloc-functions +++ a/include/linux/device.h @@ -26,6 +26,7 @@ #include <linux/atomic.h> #include <linux/ratelimit.h> #include <linux/uidgid.h> +#include <linux/gfp.h> #include <asm/device.h> struct device; @@ -602,8 +603,24 @@ extern void devres_close_group(struct de extern void devres_remove_group(struct device *dev, void *id); extern int devres_release_group(struct device *dev, void *id); -/* managed kzalloc/kfree for device drivers, no kmalloc, always use kzalloc */ -extern void *devm_kzalloc(struct device *dev, size_t size, gfp_t gfp); +/* managed devm_k.alloc/kfree for device drivers */ +extern void *devm_kmalloc(struct device *dev, size_t size, gfp_t gfp); +static inline void *devm_kzalloc(struct device *dev, size_t size, gfp_t gfp) +{ + return devm_kmalloc(dev, size, gfp | __GFP_ZERO); +} +static inline void *devm_kmalloc_array(struct device *dev, + size_t n, size_t size, gfp_t flags) +{ + if (size != 0 && n > SIZE_MAX / size) + return NULL; + return devm_kmalloc(dev, n * size, flags); +} +static inline void *devm_kcalloc(struct device *dev, + size_t n, size_t size, gfp_t flags) +{ + return devm_kmalloc_array(dev, n, size, flags | __GFP_ZERO); +} extern void devm_kfree(struct device *dev, void *p); void __iomem *devm_ioremap_resource(struct device *dev, struct resource *res); _ Patches currently in -mm which might be from joe@xxxxxxxxxxx are kernel-timerc-convert-kmalloc_nodegfp_zero-to-kzalloc_node.patch ksm-remove-redundant-__gfp_zero-from-kcalloc.patch printk-report-console-names-during-cut-over.patch kernel-printk-printkc-convert-to-pr_foo.patch vsprintf-check-real-user-group-id-for-%pk.patch get_maintainerpl-incomplete-output.patch checkpatch-report-missing-spaces-around-trigraphs-with-strict.patch checkpatch-extend-camelcase-types-and-ignore-existing-camelcase-uses-in-a-patch.patch checkpatch-update-seq_foo-tests.patch checkpatch-find-camelcase-definitions-of-struct-union-enum.patch checkpatch-add-test-for-defines-of-arch_has_foo.patch checkpatch-add-rules-to-check-init-attribute-and-const-defects.patch checkpatch-make-the-memory-barrier-test-noisier.patch checkpatchpl-check-for-the-fsf-mailing-address.patch checkpatch-add-check-for-sscanf-without-return-use.patch checkpatch-add-check-for-sscanf-without-return-use-v2.patch drivers-rtc-rtc-puv3c-use-dev_dbg-instead-of-pr_debug.patch drivers-rtc-rtc-pl030c-use-devm_kzalloc-instead-of-kmalloc.patch kernel-modulec-use-pr_foo.patch linux-next.patch seq_file-introduce-seq_setwidth-and-seq_pad.patch seq_file-remove-%n-usage-from-seq_file-users.patch vsprintf-ignore-%n-again.patch -- To unsubscribe from this list: send the line "unsubscribe mm-commits" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html