Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2337268pxb; Thu, 11 Feb 2021 09:48:03 -0800 (PST) X-Google-Smtp-Source: ABdhPJz6upatUrCjNW9fCdDfLmoXTVA5BACqc0pC1uYLxmZ4l6KBPXsSo80+XO74C0t2gO6TB2dO X-Received: by 2002:a17:906:3757:: with SMTP id e23mr9718473ejc.93.1613065683055; Thu, 11 Feb 2021 09:48:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613065683; cv=none; d=google.com; s=arc-20160816; b=v1OjXMBWkHrZMQop5XnwuQOEbwcuMe8XpDY6cdLH3PX9VMdTL2MpaV/d+cypEpHBbk WdozBceM9gKmUsoh3KrlVLGSHiH8K1znnu4lqdYb3gmqOQQUpkdRuMuMckANqWZpDwQd 9EdMHLYyUy57yRnwOtlrLf+dI3wnny38AyOq9pNZLFGR8ga6259CGFF99TrXr4cjWHeC qFA2C85WNY9QMX45DDs4Pho9Wd3/9IhfUQw2ngWKBh5EQXEN0CVRy91fJ0llJVMtK6a0 Q+QwVO1EyChkx/n7eWz6gKQ7jHjloWfnhoPaL7B+NLUvbROL8fQDbee2pD8wQ0fXtlZg 6i3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:ironport-sdr :ironport-sdr; bh=N1YWvDfRY3NDpKeM6XAW3viLHbbaFzOG9ikccoZwOz8=; b=UPVCn0d4mg7GhCjkUvcatKXL+TUlBGvlEoyfuk9yVBs14Sg0t7Z/qYH6nOo+qaFASR +2+BLj2O1M9YYOSX3n66+du9KCbqgldS7Bb5Ug30UxGARYuHxECu4H5dzlRZeGuWEULi X35TWjBtovFIAEWMPztjoW9uIR9i6yLmaLEjU2tFsw4RnGSudsiAnHHqrFEgTVpS/RjZ quUta9vnXfw5AuelpcoRLS87zCyKnjF7u/3A0w7ssP6Dkw7ZDgZmFutMlDe20fGKuGhA E6yyIqAWJi0EXfVZ0RReX/k5vbT8MH/kTeqRPKuquZwSpNAFOZIjRRnvfmOSavkI81U/ DgWQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hq38si3899026ejc.21.2021.02.11.09.47.39; Thu, 11 Feb 2021 09:48:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232598AbhBKRnh (ORCPT + 99 others); Thu, 11 Feb 2021 12:43:37 -0500 Received: from mga12.intel.com ([192.55.52.136]:47864 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230374AbhBKQzA (ORCPT ); Thu, 11 Feb 2021 11:55:00 -0500 IronPort-SDR: 4PIOMny2LNWNl9rpoudWWMEQx5JwP8a9GMHguB5Le7Ppe4ILQ5Ii2qG17rBrHcZ5Cvb//NqLm8 pqMV5NBPc7sg== X-IronPort-AV: E=McAfee;i="6000,8403,9892"; a="161418670" X-IronPort-AV: E=Sophos;i="5.81,170,1610438400"; d="scan'208";a="161418670" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Feb 2021 08:54:17 -0800 IronPort-SDR: eqa7Zt7LeUeFWr07RwW6Yo3OMmzIqxQ7k3HTy++wEpIlr3FG91G5Y0vNTl0ZXVnN7aN+toi7f1 IJHL3eBkFpKw== X-IronPort-AV: E=Sophos;i="5.81,170,1610438400"; d="scan'208";a="380757905" Received: from reknight-mobl.amr.corp.intel.com (HELO intel.com) ([10.252.134.254]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Feb 2021 08:54:16 -0800 Date: Thu, 11 Feb 2021 08:54:14 -0800 From: Ben Widawsky To: Jonathan Cameron Cc: Dan Williams , linux-cxl@vger.kernel.org, Linux ACPI , Linux Kernel Mailing List , linux-nvdimm , Linux PCI , Bjorn Helgaas , "Chris Browy , Christoph Hellwig , Dan Williams , David Hildenbrand , David Rientjes" , "Jon Masters , Rafael Wysocki , Randy Dunlap" , "John Groves (jgroves)" , "Kelley, Sean V" , kernel test robot , Dan Williams Subject: Re: [PATCH v2 4/8] cxl/mem: Add basic IOCTL interface Message-ID: <20210211165414.wwsu63lhoznzrhof@intel.com> References: <20210210000259.635748-1-ben.widawsky@intel.com> <20210210000259.635748-5-ben.widawsky@intel.com> <20210210184540.00007536@Huawei.com> <20210211100646.00007dcc@Huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210211100646.00007dcc@Huawei.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 21-02-11 10:06:46, Jonathan Cameron wrote: > On Wed, 10 Feb 2021 20:40:52 -0800 > Dan Williams wrote: > > > On Wed, Feb 10, 2021 at 10:47 AM Jonathan Cameron > > 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" }, + * }; + */ +