]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
resource: provide 0args DEFINE_RES variant for unset resource desc
authorChristian Marangi <ansuelsmth@gmail.com>
Sat, 13 Dec 2025 11:53:09 +0000 (12:53 +0100)
committerAndrew Morton <akpm@linux-foundation.org>
Tue, 27 Jan 2026 03:07:10 +0000 (19:07 -0800)
Provide a variant of DEFINE_RES that takes 0 arguments to initialize 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.

Link: https://lkml.kernel.org/r/20251213115314.16700-1-ansuelsmth@gmail.com
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
Suggested-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Reviewed-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
include/linux/ioport.h

index 9afa30f9346fceca06a3e7f990df9d8c926bfc97..e974fc08705997b20e08fe34f10bf6307cbde67f 100644 (file)
@@ -10,6 +10,7 @@
 #define _LINUX_IOPORT_H
 
 #ifndef __ASSEMBLY__
+#include <linux/args.h>
 #include <linux/bits.h>
 #include <linux/compiler.h>
 #include <linux/minmax.h>
@@ -165,8 +166,12 @@ 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)