Re: unsigned long ioremap()?

From: Jonathan Lundell (jlundell@pobox.com)
Date: Fri May 04 2001 - 08:53:26 EST


At 12:30 AM -0700 2001-05-04, David S. Miller wrote:
>Abramo Bagnara writes:
> > it's perfectly fine to have:
> >
> > regs = (struct reg *) ioremap(addr, size);
> > foo = readl((unsigned long)&regs->bar);
> >
>
>I don't see how one can find this valid compared to my preference of
>just plain readl(&regs->bar); You're telling me it's nicer to have the
>butt ugly cast there which serves no purpose?
>
>One could argue btw that structure offsets are less error prone to
>code than register offset defines out the wazoo.
>
>I think your argument here is bogus.

The proposed API change serves to avoid the worse-than-butt-ugly:

        foo = regs->bar;

which on the evidence of the current kernel source is in fact a real problem.

One could imagine a pointer-type-modifier in C that says "this
pointer can't be dereferenced, but pointer arithmetic is OK, and any
derived pointers inherit the property", with syntax similar to
volatile, or some kind of C++ dereference overloading, but absent
that, a correct API offsets the marginal burden of having to cast in
order to treat non-pointers as pointers.

As Abramo points out, if you can't abide the above cast, you can
create a relatively trivial macro to hide the dirty work.

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



This archive was generated by hypermail 2b29 : Mon May 07 2001 - 21:00:20 EST