From: Rusty Russell <rusty@rustcorp.com.au>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: David Howells <dhowells@redhat.com>,
linux-arch@vger.kernel.org, randy.dunlap@oracle.com
Subject: Re: + expose-range-checking-functions-from-arch-specific.patch added to -mm tree
Date: Thu, 12 Apr 2007 09:41:32 +1000 [thread overview]
Message-ID: <1176334892.14322.137.camel@localhost.localdomain> (raw)
In-Reply-To: <20070411112452.6979414c.akpm@linux-foundation.org>
On Wed, 2007-04-11 at 11:24 -0700, Andrew Morton wrote:
> I suspect we would benefit from a proper suite of tools for comparing a
> single number against a range, and for comparing ranges.
How about this ambition-reduction patch, instead?
===
range_within() was too ambitious: it started inspiring people. Remove it.
val_outside() was a terrible name, too. Try range_over_limit().
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
diff -r 2f617843ce25 include/asm-generic/range.h
--- a/include/asm-generic/range.h Thu Apr 12 09:32:53 2007 +1000
+++ b/include/asm-generic/range.h Thu Apr 12 09:36:20 2007 +1000
@@ -2,18 +2,18 @@
#define _ASM_GENERIC_RANGE_H
/**
- * val_outside - is a value and length past a limit?
- * @val: the start value
+ * range_over_limit() - is a start and length past a limit?
+ * @start: the start value
* @len: the length from the start
* @limit: the first invalid value
*
- * Like val + len > limit, except with overflow checking.
+ * Like start + len > limit, except with overflow checking.
*/
-static inline bool val_outside(unsigned long val, unsigned long len,
- unsigned long limit)
+static inline bool range_over_limit(unsigned long start, unsigned long len,
+ unsigned long limit)
{
- return val + len > limit || val + len < val;
+ return start + len > limit || start + len < start;
}
#endif /* _ASM_GENERIC_RANGE_H */
diff -r 2f617843ce25 include/asm-i386/range.h
--- a/include/asm-i386/range.h Thu Apr 12 09:32:53 2007 +1000
+++ b/include/asm-i386/range.h Thu Apr 12 09:36:37 2007 +1000
@@ -1,14 +1,14 @@
#ifndef __ASM_RANGE_H
#define __ASM_RANGE_H
-/* Is val + size > limit? This needs 33-bit arithmetic. We have a carry... */
-static inline bool val_outside(unsigned long val, unsigned long len,
- unsigned long limit)
+/* Is start + size > limit? This needs 33-bit arithmetic. We have a carry... */
+static inline bool range_over_limit(unsigned long start, unsigned long len,
+ unsigned long limit)
{
unsigned long flag, roksum;
asm("addl %3,%1 ; sbbl %0,%0; cmpl %1,%4; sbbl $0,%0"
:"=&r" (flag), "=r" (roksum)
- :"1" (val), "g" (len), "rm" (limit));
+ :"1" (start), "g" (len), "rm" (limit));
return flag;
}
#endif /* __ASM_RANGE_H */
diff -r 2f617843ce25 include/asm-i386/uaccess.h
--- a/include/asm-i386/uaccess.h Thu Apr 12 09:32:53 2007 +1000
+++ b/include/asm-i386/uaccess.h Thu Apr 12 09:37:07 2007 +1000
@@ -51,10 +51,10 @@ extern struct movsl_mask {
* This is equivalent to the following test:
* (u33)addr + (u33)size > (u33)current->addr_limit.seg
*/
-#define __range_ok(addr, size) ({ \
- __chk_user_ptr(addr); \
- val_outside((int)(addr), (size), \
- current_thread_info()->addr_limit.seg); \
+#define __range_ok(addr, size) ({ \
+ __chk_user_ptr(addr); \
+ range_over_limit((int)(addr), (size), \
+ current_thread_info()->addr_limit.seg); \
})
/**
diff -r 2f617843ce25 include/linux/kernel.h
--- a/include/linux/kernel.h Thu Apr 12 09:32:53 2007 +1000
+++ b/include/linux/kernel.h Thu Apr 12 09:35:13 2007 +1000
@@ -16,7 +16,6 @@
#include <linux/log2.h>
#include <asm/byteorder.h>
#include <asm/bug.h>
-#include <asm/range.h>
extern const char linux_banner[];
extern const char linux_proc_banner[];
@@ -312,26 +311,6 @@ static inline int __attribute__ ((format
(void)__tmp; \
})
-/**
- * range_within - is one range within another?
- * @start: the start value
- * @len: the length from the start
- * @base: the first valid value
- * @limit: the first invalid value
- *
- * This is usually used for memory range testing. The common cases of
- * constant 0 start and constant 0 len cases are optimized out.
- */
-static inline bool range_within(unsigned long start, unsigned long len,
- unsigned long base, unsigned long limit)
-{
- if (start < base)
- return false;
- if (__builtin_constant_p(len) && len == 0)
- return start - base <= limit - base;
- return !val_outside(limit, start, len);
-}
-
struct sysinfo;
extern int do_sysinfo(struct sysinfo *info);
next prev parent reply other threads:[~2007-04-11 23:41 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-04-06 21:27 + expose-range-checking-functions-from-arch-specific.patch added to -mm tree akpm
2007-04-10 10:17 ` David Howells
2007-04-11 2:19 ` Rusty Russell
2007-04-11 2:48 ` Andrew Morton
2007-04-11 10:49 ` David Howells
2007-04-11 18:24 ` Andrew Morton
2007-04-11 23:28 ` Rusty Russell
2007-04-12 16:05 ` + expose-range-checking-functions-from-arch-specific.patchadded " Luck, Tony
2007-04-13 0:08 ` Rusty Russell
2007-04-11 23:41 ` Rusty Russell [this message]
2007-04-12 10:47 ` + expose-range-checking-functions-from-arch-specific.patch added " David Howells
2007-04-12 14:51 ` Randy Dunlap
2007-04-12 7:42 ` Geert Uytterhoeven
2007-04-11 13:17 ` Rusty Russell
2007-04-11 17:03 ` David Howells
2007-04-11 18:31 ` Andrew Morton
2007-04-11 19:17 ` David Howells
2007-04-11 22:52 ` Rusty Russell
2007-04-12 10:49 ` David Howells
2007-04-11 10:47 ` David Howells
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1176334892.14322.137.camel@localhost.localdomain \
--to=rusty@rustcorp.com.au \
--cc=akpm@linux-foundation.org \
--cc=dhowells@redhat.com \
--cc=linux-arch@vger.kernel.org \
--cc=randy.dunlap@oracle.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.