linux-cxl.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] cxl: Convert driver id to an enum
@ 2021-07-06 16:59 Ben Widawsky
  2021-07-06 18:38 ` Dan Williams
  0 siblings, 1 reply; 2+ messages in thread
From: Ben Widawsky @ 2021-07-06 16:59 UTC (permalink / raw)
  To: linux-cxl, Dan Williams
  Cc: Ben Widawsky, Alison Schofield, Ira Weiny, Jonathan Cameron,
	Vishal Verma

CXL drivers can be of only one type. As such, an enum is the most
logical way to represent that singleton nature. By converting to an
enum, it's easy and obvious how to add new driver types.

Signed-off-by: Ben Widawsky <ben.widawsky@intel.com>
---
 drivers/cxl/cxl.h | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h
index ec90b32d4bd8..dd005a5e296b 100644
--- a/drivers/cxl/cxl.h
+++ b/drivers/cxl/cxl.h
@@ -328,12 +328,17 @@ devm_cxl_add_passthrough_decoder(struct device *host, struct cxl_port *port)
 
 extern struct bus_type cxl_bus_type;
 
+enum cxl_driver_id {
+	CXL_DEVICE_NVDIMM_BRIDGE,
+	CXL_DEVICE_NVDIMM,
+};
+
 struct cxl_driver {
 	const char *name;
 	int (*probe)(struct device *dev);
 	void (*remove)(struct device *dev);
 	struct device_driver drv;
-	int id;
+	enum cxl_driver_id id;
 };
 
 static inline struct cxl_driver *to_cxl_drv(struct device_driver *drv)
@@ -346,9 +351,6 @@ int __cxl_driver_register(struct cxl_driver *cxl_drv, struct module *owner,
 #define cxl_driver_register(x) __cxl_driver_register(x, THIS_MODULE, KBUILD_MODNAME)
 void cxl_driver_unregister(struct cxl_driver *cxl_drv);
 
-#define CXL_DEVICE_NVDIMM_BRIDGE	1
-#define CXL_DEVICE_NVDIMM		2
-
 #define MODULE_ALIAS_CXL(type) MODULE_ALIAS("cxl:t" __stringify(type) "*")
 #define CXL_MODALIAS_FMT "cxl:t%d"
 
-- 
2.32.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] cxl: Convert driver id to an enum
  2021-07-06 16:59 [PATCH] cxl: Convert driver id to an enum Ben Widawsky
@ 2021-07-06 18:38 ` Dan Williams
  0 siblings, 0 replies; 2+ messages in thread
From: Dan Williams @ 2021-07-06 18:38 UTC (permalink / raw)
  To: Ben Widawsky
  Cc: linux-cxl, Alison Schofield, Ira Weiny, Jonathan Cameron, Vishal Verma

On Tue, Jul 6, 2021 at 9:59 AM Ben Widawsky <ben.widawsky@intel.com> wrote:
>
> CXL drivers can be of only one type. As such, an enum is the most
> logical way to represent that singleton nature. By converting to an
> enum, it's easy and obvious how to add new driver types.
>
> Signed-off-by: Ben Widawsky <ben.widawsky@intel.com>
> ---
>  drivers/cxl/cxl.h | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h
> index ec90b32d4bd8..dd005a5e296b 100644
> --- a/drivers/cxl/cxl.h
> +++ b/drivers/cxl/cxl.h
> @@ -328,12 +328,17 @@ devm_cxl_add_passthrough_decoder(struct device *host, struct cxl_port *port)
>
>  extern struct bus_type cxl_bus_type;
>
> +enum cxl_driver_id {
> +       CXL_DEVICE_NVDIMM_BRIDGE,
> +       CXL_DEVICE_NVDIMM,
> +};
> +
>  struct cxl_driver {
>         const char *name;
>         int (*probe)(struct device *dev);
>         void (*remove)(struct device *dev);
>         struct device_driver drv;
> -       int id;
> +       enum cxl_driver_id id;
>  };
>
>  static inline struct cxl_driver *to_cxl_drv(struct device_driver *drv)
> @@ -346,9 +351,6 @@ int __cxl_driver_register(struct cxl_driver *cxl_drv, struct module *owner,
>  #define cxl_driver_register(x) __cxl_driver_register(x, THIS_MODULE, KBUILD_MODNAME)
>  void cxl_driver_unregister(struct cxl_driver *cxl_drv);
>
> -#define CXL_DEVICE_NVDIMM_BRIDGE       1
> -#define CXL_DEVICE_NVDIMM              2
> -
>  #define MODULE_ALIAS_CXL(type) MODULE_ALIAS("cxl:t" __stringify(type) "*")
>  #define CXL_MODALIAS_FMT "cxl:t%d"

Doesn't this break module aliasing? I.e. __stringfy(CXL_DEVICE_NVDIMM)
changes from:

"2" to "CXL_DEVICE_NVDIMM"

?

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-07-06 18:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-06 16:59 [PATCH] cxl: Convert driver id to an enum Ben Widawsky
2021-07-06 18:38 ` Dan Williams

This is a public inbox, see mirroring instructions
on how to clone and mirror all data and code used for this inbox