Skip to contentSkip to conversation

resource: provide 0args DEFINE_RES variant for unset resource desc

PATCH Superseded Christian Marangi 3 participants 3 messages Dec 10, 2025

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 resource: provide 0args DEFINE_RES variant for unset resource desc

Provide a variant of DEFINE_RES that takes 0 arguments to inizialize an "unset" resource descriptor.

This should be used for the improper case of

	struct resource res = {};

where DEFINE_RES() should be used.

With this new helper variant, it would result in:

	struct resource res = DEFINE_RES();

instead of having to define the full 3 arguments:

	struct resource res = DEFINE_RES(0, 0, IORESOURCE_UNSET);

DEFINE_RES() with no args, will set the flags to IORESOURCE_UNSET signaling the resource descriptor is UNSET and doesn't reflect an actual resource currently.

---
 include/linux/ioport.h | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
include/linux/ioport.h +6 -1
index d3e837eb8760..ebdbaaf7a520 100644
@@ -168,8 +168,13 @@ enum {
 
 #define DEFINE_RES_NAMED(_start, _size, _name, _flags)			\
 	DEFINE_RES_NAMED_DESC(_start, _size, _name, _flags, IORES_DESC_NONE)
-#define DEFINE_RES(_start, _size, _flags)				\
+#define __DEFINE_RES0()							\
+	DEFINE_RES_NAMED(0, 0, NULL, IORESOURCE_UNSET)
+#define __DEFINE_RES3(_start, _size, _flags)				\
 	DEFINE_RES_NAMED(_start, _size, NULL, _flags)
+#define DEFINE_RES(...)							\
+	CONCATENATE(__DEFINE_RES, COUNT_ARGS(__VA_ARGS__))		\
+		    (__VA_ARGS__)
 
 #define DEFINE_RES_IO_NAMED(_start, _size, _name)			\
 	DEFINE_RES_NAMED((_start), (_size), (_name), IORESOURCE_IO)
Signature · 1 line
2.51.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 2 lines · Christian Marangi

Provide a variant of DEFINE_RES that takes 0 arguments to inizialize an "unset" resource descriptor.

s/inizialize/initialize/

Quoted 12 lines

This should be used for the improper case of

	struct resource res = {};

where DEFINE_RES() should be used.

With this new helper variant, it would result in:

	struct resource res = DEFINE_RES();

instead of having to define the full 3 arguments:

Quoted 8 lines
	struct resource res = DEFINE_RES(0, 0, IORESOURCE_UNSET);

DEFINE_RES() with no args, will set the flags to IORESOURCE_UNSET signaling the resource descriptor is UNSET and doesn't reflect an actual resource currently.

Looks good to me, thanks for doing this!

Quoted 26 lines
---
 include/linux/ioport.h | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
include/linux/ioport.h +6 -1
index d3e837eb8760..ebdbaaf7a520 100644
@@ -168,8 +168,13 @@ enum {
 
 #define DEFINE_RES_NAMED(_start, _size, _name, _flags)			\
 	DEFINE_RES_NAMED_DESC(_start, _size, _name, _flags, IORES_DESC_NONE)
-#define DEFINE_RES(_start, _size, _flags)				\
+#define __DEFINE_RES0()							\
+	DEFINE_RES_NAMED(0, 0, NULL, IORESOURCE_UNSET)
+#define __DEFINE_RES3(_start, _size, _flags)				\
 	DEFINE_RES_NAMED(_start, _size, NULL, _flags)
+#define DEFINE_RES(...)							\
+	CONCATENATE(__DEFINE_RES, COUNT_ARGS(__VA_ARGS__))		\
+		    (__VA_ARGS__)
 
 #define DEFINE_RES_IO_NAMED(_start, _size, _name)			\
 	DEFINE_RES_NAMED((_start), (_size), (_name), IORESOURCE_IO)
Signature · 1 line
2.51.0
#2 lore raw
In reply to Christian Marangi
Quoted 20 lines · Christian Marangi

Provide a variant of DEFINE_RES that takes 0 arguments to inizialize an "unset" resource descriptor.

This should be used for the improper case of

	struct resource res = {};

where DEFINE_RES() should be used.

With this new helper variant, it would result in:

	struct resource res = DEFINE_RES();

instead of having to define the full 3 arguments:

	struct resource res = DEFINE_RES(0, 0, IORESOURCE_UNSET);

DEFINE_RES() with no args, will set the flags to IORESOURCE_UNSET signaling the resource descriptor is UNSET and doesn't reflect an actual resource currently.

...

include/linux/ioport.h enum { · line 177

Quoted 3 lines
include/linux/ioport.h +3 -0
+#define DEFINE_RES(...)							\
+	CONCATENATE(__DEFINE_RES, COUNT_ARGS(__VA_ARGS__))		\
+		    (__VA_ARGS__)
	CONCATENATE(__DEFINE_RES, COUNT_ARGS(__VA_ARGS__))(__VA_ARGS__)

Can be one line. Moreover, it will be even better to show that we imply a function call here.

And this requires including args.h.

Signature · 2 lines
With Best Regards,
Andy Shevchenko