lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Sat, 19 Jul 2014 10:53:38 +0200
From:	Sam Ravnborg <sam@...nborg.org>
To:	Arnd Bergmann <arnd@...db.de>
Cc:	linux-arm-kernel@...ts.infradead.org,
	Thierry Reding <thierry.reding@...il.com>,
	linux-arch@...r.kernel.org, Russell King <linux@....linux.org.uk>,
	Catalin Marinas <catalin.marinas@....com>,
	Stephen Boyd <sboyd@...eaurora.org>,
	linux-kernel@...r.kernel.org, Will Deacon <will.deacon@....com>
Subject: Re: [PATCH v3 1/3] asm-generic/io.h: Implement generic
 {read,write}s*()

> > 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@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists