[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <56C77C17.7030208@zytor.com>
Date: Fri, 19 Feb 2016 12:33:27 -0800
From: "H. Peter Anvin" <hpa@...or.com>
To: "Luis R. Rodriguez" <mcgrof@...nel.org>, tglx@...utronix.de,
mingo@...hat.com, bp@...en8.de
Cc: 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 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.
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);
Powered by blists - more mailing lists