Re: [PATCH v3 1/3] asm-generic/io.h: Implement generic {read,write}s*()

From: Sam Ravnborg
Date: Sat Jul 19 2014 - 04:54:05 EST


> > A semi related question.
> > Why do we play all these macro tricks in io.h?
> >
> > Example:
> >
> > #define writeb __raw_writeb
> >
> > The consensus these days is to use static inline to have the
> > correct prototype but this file is contains a lot of these
> > macro conversions.
> >
> > All these things are not introduced by your patch but now that
> > you show some love and care for this file maybe we could take
> > the next step and bring more order to the current semi chaos?
>
> The macros are mainly there so we can test their presence with
> #ifdef.

There are two types of macros in io.h:

#define __raw_writeb __raw_writeb
#ifndef __raw_writeb

This is the one you talk about which allows an architecture to
provide a local implementation of a function.
These are prefectly OK and are required.


Then there are the other type where one IO access function
may re-use the implementation of another IO access function:

#ifndef writeb
#define writeb __raw_writeb
#endif

This could have been implmented like this:

#ifndef writeb
#define writeb writeb
static inline void writeb(u8 b, volatile void __iomem *addr)
{
__raw_writeb(b, addr);
}
#endif

In this way the prototype of the function is easy to understand and
we avoid the macro tricks were we blindly replace one function name,
with another function name.
And we also use the same pattarn all over for the various functions.

Concerning the efficiency the compiler should be smart enough to
do the same independent on the two implmentations.

The only drawback I see is that the above is 6 lines of codes,
where the macro expansion is 3 lines of code.

And when we talk about simpler expansion like ioread8()
then we replace one line with 4 lines.

Sam
--
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/