Skip to contentSkip to conversation

module.h: allow #define strings to work with MODULE_IMPORT_NS

PATCH In review Greg Kroah-Hartman 3 participants 3 messages Jan 8, 2022 – Jan 12, 2022 Module support

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 module.h: allow #define strings to work with MODULE_IMPORT_NS

The MODULE_IMPORT_NS() macro does not allow defined strings to work properly with it, so add a layer of indirection to allow this to happen.

Cc Luis Chamberlain <[email protected]>
Cc Jessica Yu <[email protected]>
Cc Matthias Maennich <[email protected]>

---
Note, there is no in-kernel user of this, I wrote this to help deal with some module namespace issues that Android kernels were having where we wanted to put the namespace name in a build #define to make things easier over time when combined with the change at:

	https://lore.kernel.org/all/[email protected]/

I can also see this be used in ways to make namespace names up "on the fly at build time" when combined with the above-referenced change to create a different namespace for every time the kernel is built to do a poor-man's symbol mangling to make life harder for out-of-tree modules. Not that I would ever suggest such a thing :)

 include/linux/module.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
include/linux/module.h +2 -1
index c9f1200b2312..f4338235ed2c 100644
@@ -290,7 +290,8 @@ extern typeof(name) __mod_##type##__##name##_device_table		\
  * files require multiple MODULE_FIRMWARE() specifiers */
 #define MODULE_FIRMWARE(_firmware) MODULE_INFO(firmware, _firmware)
 
-#define MODULE_IMPORT_NS(ns) MODULE_INFO(import_ns, #ns)
+#define _MODULE_IMPORT_NS(ns)	MODULE_INFO(import_ns, #ns)
+#define MODULE_IMPORT_NS(ns)	_MODULE_IMPORT_NS(ns)
 
 struct notifier_block;
 
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Greg Kroah-Hartman

The MODULE_IMPORT_NS() macro does not allow defined strings to work properly with it, so add a layer of indirection to allow this to happen.

Cc Luis Chamberlain <[email protected]>
Cc Jessica Yu <[email protected]>
Cc Matthias Maennich <[email protected]>

Cheers,
Matthias

Quoted 33 lines

---
Note, there is no in-kernel user of this, I wrote this to help deal with some module namespace issues that Android kernels were having where we wanted to put the namespace name in a build #define to make things easier over time when combined with the change at:

	https://lore.kernel.org/all/[email protected]/

I can also see this be used in ways to make namespace names up "on the fly at build time" when combined with the above-referenced change to create a different namespace for every time the kernel is built to do a poor-man's symbol mangling to make life harder for out-of-tree modules. Not that I would ever suggest such a thing :)

include/linux/module.h | 3 ++-

1 file changed, 2 insertions(+), 1 deletion(-)
include/linux/module.h +2 -1
index c9f1200b2312..f4338235ed2c 100644
@@ -290,7 +290,8 @@ extern typeof(name) __mod_##type##__##name##_device_table		\
 * files require multiple MODULE_FIRMWARE() specifiers */
 #define MODULE_FIRMWARE(_firmware) MODULE_INFO(firmware, _firmware)
 
-#define MODULE_IMPORT_NS(ns) MODULE_INFO(import_ns, #ns)
+#define _MODULE_IMPORT_NS(ns)	MODULE_INFO(import_ns, #ns)
+#define MODULE_IMPORT_NS(ns)	_MODULE_IMPORT_NS(ns)
 
 struct notifier_block;
 
Signature · 1 line
2.34.1
maintainer
#2 lore raw
In reply to Greg Kroah-Hartman
Quoted 7 lines · Greg Kroah-Hartman

The MODULE_IMPORT_NS() macro does not allow defined strings to work properly with it, so add a layer of indirection to allow this to happen.

Cc Luis Chamberlain <[email protected]>
Cc Jessica Yu <[email protected]>
Cc Matthias Maennich <[email protected]>

Thanks, queued onto modulex-next [0].

[0] https://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux.git/log/?h=modules-next

Luis