Re: unsigned long ioremap()?

Jonathan Lundell
2001-05-04T14:41:28Z

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.