* [PATCH 3/3] module: use ZERO_OR_NULL_PTR allocation pointer checking
@ 2012-01-30 8:44 Dmitry Antipov
2012-01-30 23:12 ` Rusty Russell
0 siblings, 1 reply; 2+ messages in thread
From: Dmitry Antipov @ 2012-01-30 8:44 UTC (permalink / raw)
To: Rusty Russell; +Cc: linux-kernel, linaro-dev, patches, Dmitry Antipov
Use ZERO_OR_NULL_PTR allocation pointer checking where allocation
function may return ZERO_SIZE_PTR.
Signed-off-by: Dmitry Antipov <dmitry.antipov@linaro.org>
---
kernel/module.c | 12 ++++++------
1 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/kernel/module.c b/kernel/module.c
index 2c93276..5183f91 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -438,7 +438,7 @@ static int percpu_modalloc(struct module *mod,
}
mod->percpu = __alloc_reserved_percpu(size, align);
- if (!mod->percpu) {
+ if (unlikely(ZERO_OR_NULL_PTR(mod->percpu))) {
printk(KERN_WARNING
"%s: Could not allocate %lu bytes percpu data\n",
mod->name, size);
@@ -572,7 +572,7 @@ EXPORT_TRACEPOINT_SYMBOL(module_get);
static int module_unload_init(struct module *mod)
{
mod->refptr = alloc_percpu(struct module_ref);
- if (!mod->refptr)
+ if (unlikely(ZERO_OR_NULL_PTR(mod->refptr)))
return -ENOMEM;
INIT_LIST_HEAD(&mod->source_list);
@@ -2322,14 +2322,14 @@ static void dynamic_debug_remove(struct _ddebug *debug)
void * __weak module_alloc(unsigned long size)
{
- return size == 0 ? NULL : vmalloc_exec(size);
+ return vmalloc_exec(size);
}
static void *module_alloc_update_bounds(unsigned long size)
{
void *ret = module_alloc(size);
- if (ret) {
+ if (likely(!ZERO_OR_NULL_PTR(ret))) {
mutex_lock(&module_mutex);
/* Update module bounds. */
if ((unsigned long)ret < module_addr_min)
@@ -2638,7 +2638,7 @@ static int move_module(struct module *mod, struct load_info *info)
* leak.
*/
kmemleak_not_leak(ptr);
- if (!ptr)
+ if (unlikely(ZERO_OR_NULL_PTR(ptr)))
return -ENOMEM;
memset(ptr, 0, mod->core_size);
@@ -2652,7 +2652,7 @@ static int move_module(struct module *mod, struct load_info *info)
* after the module is initialized.
*/
kmemleak_ignore(ptr);
- if (!ptr && mod->init_size) {
+ if (unlikely(ZERO_OR_NULL_PTR(ptr)) && mod->init_size) {
module_free(mod, mod->module_core);
return -ENOMEM;
}
--
1.7.7.6
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH 3/3] module: use ZERO_OR_NULL_PTR allocation pointer checking
2012-01-30 8:44 [PATCH 3/3] module: use ZERO_OR_NULL_PTR allocation pointer checking Dmitry Antipov
@ 2012-01-30 23:12 ` Rusty Russell
0 siblings, 0 replies; 2+ messages in thread
From: Rusty Russell @ 2012-01-30 23:12 UTC (permalink / raw)
To: Dmitry Antipov; +Cc: linux-kernel, linaro-dev, patches, Dmitry Antipov
On Mon, 30 Jan 2012 12:44:40 +0400, Dmitry Antipov <dmitry.antipov@linaro.org> wrote:
> Use ZERO_OR_NULL_PTR allocation pointer checking where allocation
> function may return ZERO_SIZE_PTR.
>
> Signed-off-by: Dmitry Antipov <dmitry.antipov@linaro.org>
> ---
> kernel/module.c | 12 ++++++------
> 1 files changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/kernel/module.c b/kernel/module.c
> index 2c93276..5183f91 100644
> --- a/kernel/module.c
> +++ b/kernel/module.c
> @@ -438,7 +438,7 @@ static int percpu_modalloc(struct module *mod,
> }
>
> mod->percpu = __alloc_reserved_percpu(size, align);
> - if (!mod->percpu) {
> + if (unlikely(ZERO_OR_NULL_PTR(mod->percpu))) {
> printk(KERN_WARNING
> "%s: Could not allocate %lu bytes percpu data\n",
> mod->name, size);
printk() is marked __cold. You don't need unlikely() here.
> @@ -2652,7 +2652,7 @@ static int move_module(struct module *mod, struct load_info *info)
> * after the module is initialized.
> */
> kmemleak_ignore(ptr);
> - if (!ptr && mod->init_size) {
> + if (unlikely(ZERO_OR_NULL_PTR(ptr)) && mod->init_size) {
> module_free(mod, mod->module_core);
> return -ENOMEM;
> }
You want to just change this to:
if (!ptr) {
Thanks,
Rusty.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-01-31 1:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-30 8:44 [PATCH 3/3] module: use ZERO_OR_NULL_PTR allocation pointer checking Dmitry Antipov
2012-01-30 23:12 ` Rusty Russell
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).