From patchwork Mon Jan 30 08:44:40 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Antipov X-Patchwork-Id: 6433 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 2BA3A23E0E for ; Mon, 30 Jan 2012 08:43:39 +0000 (UTC) Received: from mail-bk0-f52.google.com (mail-bk0-f52.google.com [209.85.214.52]) by fiordland.canonical.com (Postfix) with ESMTP id 16191A1868D for ; Mon, 30 Jan 2012 08:43:39 +0000 (UTC) Received: by bkar19 with SMTP id r19so3938561bka.11 for ; Mon, 30 Jan 2012 00:43:38 -0800 (PST) Received: by 10.204.9.198 with SMTP id m6mr1541962bkm.74.1327913018778; Mon, 30 Jan 2012 00:43:38 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.204.130.220 with SMTP id u28cs144681bks; Mon, 30 Jan 2012 00:43:38 -0800 (PST) Received: by 10.204.129.200 with SMTP id p8mr8078874bks.114.1327913018445; Mon, 30 Jan 2012 00:43:38 -0800 (PST) Received: from mail-bk0-f50.google.com (mail-bk0-f50.google.com [209.85.214.50]) by mx.google.com with ESMTPS id w9si8549609bkd.74.2012.01.30.00.43.38 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 30 Jan 2012 00:43:38 -0800 (PST) Received-SPF: neutral (google.com: 209.85.214.50 is neither permitted nor denied by best guess record for domain of dmitry.antipov@linaro.org) client-ip=209.85.214.50; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.214.50 is neither permitted nor denied by best guess record for domain of dmitry.antipov@linaro.org) smtp.mail=dmitry.antipov@linaro.org Received: by bkbzu5 with SMTP id zu5so4160404bkb.37 for ; Mon, 30 Jan 2012 00:43:38 -0800 (PST) Received: by 10.205.137.4 with SMTP id im4mr8257143bkc.136.1327913018042; Mon, 30 Jan 2012 00:43:38 -0800 (PST) Received: from localhost.localdomain ([78.153.153.8]) by mx.google.com with ESMTPS id ev5sm36113185bkb.4.2012.01.30.00.43.37 (version=SSLv3 cipher=OTHER); Mon, 30 Jan 2012 00:43:37 -0800 (PST) From: Dmitry Antipov To: Rusty Russell Cc: linux-kernel@vger.kernel.org, linaro-dev@lists.linaro.org, patches@linaro.org, Dmitry Antipov Subject: [PATCH 3/3] module: use ZERO_OR_NULL_PTR allocation pointer checking Date: Mon, 30 Jan 2012 12:44:40 +0400 Message-Id: <1327913080-8850-1-git-send-email-dmitry.antipov@linaro.org> X-Mailer: git-send-email 1.7.7.6 Use ZERO_OR_NULL_PTR allocation pointer checking where allocation function may return ZERO_SIZE_PTR. Signed-off-by: Dmitry Antipov --- 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; }