Re: [PATCH] consolidate all within() implementations

From: Harvey Harrison
Date: Mon May 19 2008 - 16:50:50 EST


On Mon, 2008-05-19 at 10:45 +0200, Peter Oberparleiter wrote:
> From: Peter Oberparleiter <peter.oberparleiter@xxxxxxxxxx>
>
> This patch consolidates a number of different implementations of the
> within() function which checks whether an address is within a specified
> address range. Apart from parameter typing, existing implementations can
> be classified in two categories which differ in the way the range is
> specified:
>
> 1) by start and end address
> 2) by start and size
>
> These categories are covered by the within() macro (case 1) and the
> within_len() macro (case 2). Both macros can be used with any pointer
> or pointer-equivalent type as parameter.

Would it be that hard to just make them static inlines taking unsigned
longs?

>
> Signed-off-by: Peter Oberparleiter <peter.oberparleiter@xxxxxxxxxx>
> ---
>
> /**
> + * within - check whether address is within a start-and-end address range
> + * @val: address

@addr perhaps

> + * @start: start address (included in range)
> + * @end: end address (excluded from range)
> + */
> +#define within(val, start, end) ({ \

How about:
static inline int addr_within(unsigned long addr, unsigned long start,
unsigned long end)

> + unsigned long __val = (unsigned long) (val); \
> + unsigned long __start = (unsigned long) (start); \
> + unsigned long __end = (unsigned long) (end); \
> + (__val >= __start) && (__val < __end); })
> +
> +/**
> + * within_len - check whether address is within a start-and-length address range
> + * @val: address

@addr
> + * @start: start of range
> + * @len: number of bytes in range
> + */
> +#define within_len(val, start, len) ({ \
ïstatic inline int addr_within_len(unsigned long addr, unsigned long start,
unsigned long len)

Just a thought.

Harvey

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