lkml.org 
[lkml]   [2021]   [Feb]   [10]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [PATCH v2 4/8] cxl/mem: Add basic IOCTL interface
On Wed, Feb 10, 2021 at 10:47 AM Jonathan Cameron
<Jonathan.Cameron@huawei.com> wrote:
[..]
> > +#define CXL_CMDS \
> > + ___C(INVALID, "Invalid Command"), \
> > + ___C(IDENTIFY, "Identify Command"), \
> > + ___C(MAX, "Last command")
> > +
> > +#define ___C(a, b) CXL_MEM_COMMAND_ID_##a
> > +enum { CXL_CMDS };
> > +
> > +#undef ___C
> > +#define ___C(a, b) { b }
> > +static const struct {
> > + const char *name;
> > +} cxl_command_names[] = { CXL_CMDS };
> > +#undef ___C
>
> Unless there are going to be a lot of these, I'd just write them out long hand
> as much more readable than the macro magic.

This macro magic isn't new to Linux it was introduced with ftrace:

See "cpp tricks and treats": https://lwn.net/Articles/383362/

>
> enum {
> CXL_MEM_COMMAND_ID_INVALID,
> CXL_MEM_COMMAND_ID_IDENTIFY,
> CXL_MEM_COMMAND_ID_MAX
> };
>
> static const struct {
> const char *name;
> } cxl_command_names[] = {
> [CXL_MEM_COMMAND_ID_INVALID] = { "Invalid Command" },
> [CXL_MEM_COMMAND_ID_IDENTIFY] = { "Identify Comamnd" },
> /* I hope you never need the Last command to exist in here as that sounds like a bug */
> };
>
> That's assuming I actually figured the macro fun out correctly.
> To my mind it's worth doing this stuff for 'lots' no so much for 3.

The list will continue to expand, and it eliminates the "did you
remember to update cxl_command_names" review burden permanently.

\
 
 \ /
  Last update: 2021-02-11 05:43    [W:0.995 / U:0.012 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site