Re: [PATCH 1/6] gxfb: create DC/VP/FP-specific handlers rather thanusing readl/writel

From: Andrew Morton
Date: Mon Mar 10 2008 - 17:49:29 EST


On Mon, 10 Mar 2008 17:35:44 -0400
Andres Salomon <dilinger@xxxxxxxxxx> wrote:

> On Mon, 10 Mar 2008 14:24:05 -0700
> Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> wrote:
>
> > On Sat, 8 Mar 2008 20:48:26 -0500
> > Andres Salomon <dilinger@xxxxxxxxxx> wrote:
> >
> > > +#define read_dc(reg) readl(par->dc_regs + (reg))
> > > +#define write_dc(reg, val) writel((val), par->dc_regs + (reg))
> > > +
> > > +#define read_vp(reg) readl(par->vid_regs + (reg))
> > > +#define write_vp(reg, val) writel((uint32_t) (val), \
> > > + par->vid_regs + (reg))
> > > +
> > > +#define read_fp(reg) readl(par->vid_regs + (reg))
> > > +#define write_fp(reg, val) writel((uint32_t) (val), \
> > > + par->vid_regs + (reg))
> > > +
> >
> > Not very nice, sorry. They're macros, and macros rather suck. And they
> > implicitly rely upon the caller having some variable called "par" in scope.
> >
> > It would be much nicer to do
> >
> > /*
> > * documentation goes here
> > */
> > static inline u32 read_dc(struct geodefb_par *par, int reg)
> > {
> > return readl(par->dc_regs, reg);
> > }
> >
> > no?
>
> I can change it if you'd like (although.. sigh.)
>
> However, it's a lot of extra passing around of the 'par' without any
> good reason. Normal I prefer inline functions to macros as well, but
> I don't see the point here.
>

It'll generate the same (or similar) code in both versions.

Code is written once and is read thousands of times, so we should optimise
for readers, not writers. And I do think that being conventional here
helps readability, even if it does add a bit more source code.

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