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  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Thu, 11 Feb 2021 08:54:14 -0800
From:   Ben Widawsky <ben.widawsky@...el.com>
To:     Jonathan Cameron <Jonathan.Cameron@...wei.com>
Cc:     Dan Williams <dan.j.williams@...el.com>, linux-cxl@...r.kernel.org,
        Linux ACPI <linux-acpi@...r.kernel.org>,
        Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
        linux-nvdimm <linux-nvdimm@...ts.01.org>,
        Linux PCI <linux-pci@...r.kernel.org>,
        Bjorn Helgaas <helgaas@...nel.org>,
        "Chris Browy <cbrowy@...ry-design.com>, Christoph Hellwig
        <hch@...radead.org>, Dan Williams <dan.j.williams@...el.com>, David
        Hildenbrand <david@...hat.com>, David Rientjes" <rientjes@...gle.com>,
        "Jon Masters <jcm@...masters.org>, Rafael Wysocki
        <rafael.j.wysocki@...el.com>, Randy Dunlap" <rdunlap@...radead.org>,
        "John Groves (jgroves)" <jgroves@...ron.com>,
        "Kelley, Sean V" <sean.v.kelley@...el.com>,
        kernel test robot <lkp@...el.com>,
        Dan Williams <dan.j.willams@...el.com>
Subject: Re: [PATCH v2 4/8] cxl/mem: Add basic IOCTL interface

On 21-02-11 10:06:46, Jonathan Cameron wrote:
> On Wed, 10 Feb 2021 20:40:52 -0800
> Dan Williams <dan.j.williams@...el.com> wrote:
> 
> > On Wed, Feb 10, 2021 at 10:47 AM Jonathan Cameron
> > <Jonathan.Cameron@...wei.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/
> 
> Yeah. I've dealt with that one a few times. It's very cleaver and compact
> but a PITA to debug build errors related to it.
> 
> > 
> > >
> > > 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.
> 
> How about a compromise.  Add a comment giving how the first entry expands to
> avoid people (me at least :) having to think their way through it every time?
> 
> Jonathan
> 

A minor tweak while here...

diff --git a/include/uapi/linux/cxl_mem.h b/include/uapi/linux/cxl_mem.h
index 655fbfde97fd..dac0adb879ec 100644
--- a/include/uapi/linux/cxl_mem.h
+++ b/include/uapi/linux/cxl_mem.h
@@ -22,7 +22,7 @@
 #define CXL_CMDS                                                          \
        ___C(INVALID, "Invalid Command"),                                 \
        ___C(IDENTIFY, "Identify Command"),                               \
-       ___C(MAX, "Last command")
+       ___C(MAX, "invalid / last command")

 #define ___C(a, b) CXL_MEM_COMMAND_ID_##a
 enum { CXL_CMDS };
@@ -32,6 +32,17 @@ enum { CXL_CMDS };
 static const struct {
        const char *name;
 } cxl_command_names[] = { CXL_CMDS };
+
+/*
+ * Here's how this actually breaks out:
+ * cxl_command_names[] = {
+ *     [CXL_MEM_COMMAND_ID_INVALID] = { "Invalid Command" },
+ *     [CXL_MEM_COMMAND_ID_IDENTIFY] = { "Identify Comamnd" },
+ *     ...
+ *     [CXL_MEM_COMMAND_ID_MAX] = { "invalid / last command" },
+ * };
+ */
+

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ