[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20160219211210.GV25240@wotan.suse.de>
Date: Fri, 19 Feb 2016 22:12:10 +0100
From: "Luis R. Rodriguez" <mcgrof@...e.com>
To: "H. Peter Anvin" <hpa@...or.com>
Cc: "Luis R. Rodriguez" <mcgrof@...nel.org>, tglx@...utronix.de,
mingo@...hat.com, bp@...en8.de, x86@...nel.org,
linux-kernel@...r.kernel.org, luto@...capital.net,
boris.ostrovsky@...cle.com, rusty@...tcorp.com.au,
david.vrabel@...rix.com, konrad.wilk@...cle.com, mcb30@...e.org,
jgross@...e.com, ming.lei@...onical.com,
gregkh@...uxfoundation.org, arnd@...db.de,
linux-arch@...r.kernel.org, linux@....linux.org.uk,
benh@...nel.crashing.org, jbaron@...mai.com, ananth@...ibm.com,
anil.s.keshavamurthy@...el.com, davem@...emloft.net,
masami.hiramatsu.pt@...achi.com, andriy.shevchenko@...ux.intel.com,
dwmw2@...radead.org, xen-devel@...ts.xensource.com
Subject: Re: [RFC v2 2/7] tables.h: add linker table support
On Fri, Feb 19, 2016 at 12:33:27PM -0800, H. Peter Anvin wrote:
> On 02/19/2016 05:45 AM, Luis R. Rodriguez wrote:
> > +/**
> > + * LINKTABLE_RUN_ERR - run each linker table entry func and return error if any
> > + *
> > + * @tbl: linker table
> > + * @func: structure name for the function name we want to call.
> > + * @args...: arguments to pass to func
> > + *
> > + * Example usage:
> > + *
> > + * unsigned int err = LINKTABLE_RUN_ERR(frobnicator_fns, some_run,);
> > + */
> > +#define LINKTABLE_RUN_ERR(tbl, func, args...) \
> > +({ \
> > + size_t i; \
> > + int err = 0; \
> > + for (i = 0; !err && i < LINKTABLE_SIZE(tbl); i++) \
> > + err = (tbl[i]).func (args); \
> > + err; \
> > +})
>
> This is wrong and pointless. As written it returns the error code of
> the last instance.
>
> What I suggested for this macro was that we ought to exit the loop on error.
>
> Furthermore:
>
> 1. Using an advancing pointer would make more sense than a counter.
OK I'll modify to use LINKTABLE_FOR_EACH and much cleaner and obvious
code to bail on error.
> 2. .func doesn't make any sense -- it ought to be "func"; otherwise you
> can't call into either a table containing pure function pointers,
> nor into a field of table *pointed to* by the table; which is
> likely to be quite common.
>
> So the idea is to use something like:
>
> /* Array of function pointers */
> LINKTABLE_RUN_ALL(frobnicator_fns, , arg1, arg2);
>
> /* Array of structures */
> LINKTABLE_RUN_ALL(frobnicator_fns, .some_run, arg1, arg2);
>
> /* Array of structure pointers */
> LINKTABLE_RUN_ALL(frobnicator_fns, ->some_run, arg1, arg2);
Ah that's sexy, thanks. Will amend.
Luis
Powered by blists - more mailing lists