lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-Id: <d2b6fffe5164f15a9cd7e3b814c4ba21aaf281de.1254242153.git.ext-phil.2.carmody@nokia.com>
Date:	Tue, 29 Sep 2009 19:40:26 +0300
From:	Phil Carmody <ext-phil.2.carmody@...ia.com>
To:	akpm@...ux-foundation.org
Cc:	linux-kernel@...r.kernel.org,
	Phil Carmody <ext-phil.2.carmody@...ia.com>
Subject: [PATCH 1/1] err.h: Additional helper function to simplify pointer error checking.

From: Phil Carmody <ext-phil.2.carmody@...ia.com>

There are quite a few instances in the kernel of checks of pointers
both against NULL and against the errno range, handling both cases
identically. This additional helper function would simplify such
code.

Signed-off-by: Phil Carmody <ext-phil.2.carmody@...ia.com>

---
Should apply cleanly to latest 2.6 tree.

The reason I noticed the lack of a helper like this was because I
was chasing down some issues where error returns were being handled
incorrectly. I concluded that a catch-all doesn't-point-to-an-object
test would be useful for pointers, so that such errors would be
harder to make.

There are possibly 50 instances in the code already of a verbatim
combined check, such as:
drivers/base/core.c:    if (class == NULL || IS_ERR(class))
most from a few architecture-specific trees. I would be prepared
to create a broader-reaching patchset which migrates more verbose
checks to this simpler one if that would be desirable.

Aside - the test used isn't computationally optimal. Comparing
unlikely((unsigned long)-x <= MAX_ERRNO) may be quicker on some
archs. I have favoured the more self-explanatory and portable
approach in this patch.
---
 include/linux/err.h |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/include/linux/err.h b/include/linux/err.h
index ec87f31..fcc836c 100644
--- a/include/linux/err.h
+++ b/include/linux/err.h
@@ -34,6 +34,11 @@ static inline long IS_ERR(const void *ptr)
 	return IS_ERR_VALUE((unsigned long)ptr);
 }
 
+static inline long IS_ERR_OR_NULL(const void *ptr)
+{
+	return (ptr == NULL) || IS_ERR_VALUE((unsigned long)ptr);
+}
+
 /**
  * ERR_CAST - Explicitly cast an error-valued pointer to another pointer type
  * @ptr: The pointer to cast.
-- 
1.5.4.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ