Re: Linux 2.5.8-pre2

Andrew Morton
2002-04-07T10:50:47Z

Russell King wrote:
>
> (Oh, and a bugbear - people go running around adding checks for the
> return value of request_region and friends on embedded devices where
> there can't be the possibility of a clash waste memory needlessly.)

If you do:

#define request_region(start, n, name)
({
__request_region(start, n, name);
(struct resource *)1;
})
#define release_region(start, n) do { } while (0)

then the compiler will remove all those error checks for you,
as well as the release_region calls.

Of course if you actually want to use the innards of the
returned resource * then that's not so good.

However, you can make it:

#define request_region() \
({ \
struct resource *r; \
r = __request_region(); \
(struct resource *)((long)r | 1); \
})

and, amazingly, the compiler still knows that the value
is non-zero, and still will elide those tests. You'll
need to mask that bit off again to use the pointer.

Whether you'll stoop this low depends upon how much you
want those bytes back :)

-