diff mbox series

[v7,1/5] module.h: MODULE_DEVICE_TABLE for built-in modules

Message ID 20221216221703.294683-2-allenwebb@google.com (mailing list archive)
State New, archived
Headers show
Series [v7,1/5] module.h: MODULE_DEVICE_TABLE for built-in modules | expand

Commit Message

Allen Webb Dec. 16, 2022, 10:16 p.m. UTC
Implement MODULE_DEVICE_TABLE for build-in modules to make it possible
to generate a builtin.alias file to complement modules.alias.

Signed-off-by: Allen Webb <allenwebb@google.com>
---
 include/linux/module.h | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

Comments

kernel test robot Dec. 17, 2022, 3:49 a.m. UTC | #1
Hi Allen,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on masahiroy-kbuild/fixes]
[also build test ERROR on mcgrof/modules-next westeri-thunderbolt/next linus/master v6.1 next-20221216]
[cannot apply to masahiroy-kbuild/for-next]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Allen-Webb/module-h-MODULE_DEVICE_TABLE-for-built-in-modules/20221217-071949
base:   https://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild.git fixes
patch link:    https://lore.kernel.org/r/20221216221703.294683-2-allenwebb%40google.com
patch subject: [PATCH v7 1/5] module.h: MODULE_DEVICE_TABLE for built-in modules
config: arm-randconfig-r024-20221216
compiler: clang version 16.0.0 (https://github.com/llvm/llvm-project 98b13979fb05f3ed288a900deb843e7b27589e58)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # install arm cross compiling tool for clang build
        # apt-get install binutils-arm-linux-gnueabi
        # https://github.com/intel-lab-lkp/linux/commit/403b6f73d008681a1db43482df4038dd670f1bd4
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Allen-Webb/module-h-MODULE_DEVICE_TABLE-for-built-in-modules/20221217-071949
        git checkout 403b6f73d008681a1db43482df4038dd670f1bd4
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=arm olddefconfig
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=arm SHELL=/bin/bash drivers/soc/imx/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

>> drivers/soc/imx/imx8mp-blk-ctrl.c:746:1: error: alias must point to a defined variable or function
   MODULE_DEVICE_TABLE(of, imx8m_blk_ctrl_of_match);
   ^
   include/linux/module.h:254:26: note: expanded from macro 'MODULE_DEVICE_TABLE'
           __attribute__ ((unused, alias(__stringify(name))))
                                   ^
   1 error generated.


vim +746 drivers/soc/imx/imx8mp-blk-ctrl.c

556f5cf9568af7 Lucas Stach 2022-04-06  734  
556f5cf9568af7 Lucas Stach 2022-04-06  735  static const struct of_device_id imx8mp_blk_ctrl_of_match[] = {
556f5cf9568af7 Lucas Stach 2022-04-06  736  	{
556f5cf9568af7 Lucas Stach 2022-04-06  737  		.compatible = "fsl,imx8mp-hsio-blk-ctrl",
556f5cf9568af7 Lucas Stach 2022-04-06  738  		.data = &imx8mp_hsio_blk_ctl_dev_data,
e3442022f54301 Lucas Stach 2022-04-06  739  	}, {
e3442022f54301 Lucas Stach 2022-04-06  740  		.compatible = "fsl,imx8mp-hdmi-blk-ctrl",
e3442022f54301 Lucas Stach 2022-04-06  741  		.data = &imx8mp_hdmi_blk_ctl_dev_data,
556f5cf9568af7 Lucas Stach 2022-04-06  742  	}, {
556f5cf9568af7 Lucas Stach 2022-04-06  743  		/* Sentinel */
556f5cf9568af7 Lucas Stach 2022-04-06  744  	}
556f5cf9568af7 Lucas Stach 2022-04-06  745  };
556f5cf9568af7 Lucas Stach 2022-04-06 @746  MODULE_DEVICE_TABLE(of, imx8m_blk_ctrl_of_match);
556f5cf9568af7 Lucas Stach 2022-04-06  747
kernel test robot Dec. 17, 2022, 3:59 a.m. UTC | #2
Hi Allen,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on masahiroy-kbuild/fixes]
[also build test ERROR on mcgrof/modules-next westeri-thunderbolt/next linus/master v6.1 next-20221216]
[cannot apply to masahiroy-kbuild/for-next]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Allen-Webb/module-h-MODULE_DEVICE_TABLE-for-built-in-modules/20221217-071949
base:   https://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild.git fixes
patch link:    https://lore.kernel.org/r/20221216221703.294683-2-allenwebb%40google.com
patch subject: [PATCH v7 1/5] module.h: MODULE_DEVICE_TABLE for built-in modules
config: sh-allmodconfig
compiler: sh4-linux-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/403b6f73d008681a1db43482df4038dd670f1bd4
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Allen-Webb/module-h-MODULE_DEVICE_TABLE-for-built-in-modules/20221217-071949
        git checkout 403b6f73d008681a1db43482df4038dd670f1bd4
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=sh olddefconfig
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=sh SHELL=/bin/bash drivers/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   In file included from include/linux/cpumask.h:10,
                    from include/linux/smp.h:13,
                    from include/linux/lockdep.h:14,
                    from include/linux/rcupdate.h:29,
                    from include/linux/rculist.h:11,
                    from include/linux/pid.h:5,
                    from include/linux/sched.h:14,
                    from include/linux/ratelimit.h:6,
                    from include/linux/dev_printk.h:16,
                    from include/linux/device.h:15,
                    from include/linux/spi/spi.h:10,
                    from drivers/mfd/stmpe-spi.c:10:
>> include/linux/module.h:251:21: error: '__mod_spi__stmpe_id__kmod_stmpe_spi_device_table' aliased to undefined symbol 'stmpe_id'
     251 |         CONCATENATE(__mod_##type##__##name##__,                         \
         |                     ^~~~~~
   include/linux/kernel.h:491:24: note: in definition of macro '__CONCAT'
     491 | #define __CONCAT(a, b) a ## b
         |                        ^
   include/linux/module.h:250:14: note: in expansion of macro 'CONCATENATE'
     250 | extern void *CONCATENATE(                                               \
         |              ^~~~~~~~~~~
   include/linux/kernel.h:492:27: note: in expansion of macro '__CONCAT'
     492 | #define CONCATENATE(a, b) __CONCAT(a, b)
         |                           ^~~~~~~~
   include/linux/module.h:251:9: note: in expansion of macro 'CONCATENATE'
     251 |         CONCATENATE(__mod_##type##__##name##__,                         \
         |         ^~~~~~~~~~~
   drivers/mfd/stmpe-spi.c:132:1: note: in expansion of macro 'MODULE_DEVICE_TABLE'
     132 | MODULE_DEVICE_TABLE(spi, stmpe_id);
         | ^~~~~~~~~~~~~~~~~~~
--
   In file included from include/linux/clk.h:13,
                    from drivers/mailbox/rockchip-mailbox.c:6:
>> include/linux/module.h:251:21: error: '__mod_of__rockchp_mbox_of_match__kmod_rockchip_mailbox_device_table' aliased to undefined symbol 'rockchp_mbox_of_match'
     251 |         CONCATENATE(__mod_##type##__##name##__,                         \
         |                     ^~~~~~
   include/linux/kernel.h:491:24: note: in definition of macro '__CONCAT'
     491 | #define __CONCAT(a, b) a ## b
         |                        ^
   include/linux/module.h:250:14: note: in expansion of macro 'CONCATENATE'
     250 | extern void *CONCATENATE(                                               \
         |              ^~~~~~~~~~~
   include/linux/kernel.h:492:27: note: in expansion of macro '__CONCAT'
     492 | #define CONCATENATE(a, b) __CONCAT(a, b)
         |                           ^~~~~~~~
   include/linux/module.h:251:9: note: in expansion of macro 'CONCATENATE'
     251 |         CONCATENATE(__mod_##type##__##name##__,                         \
         |         ^~~~~~~~~~~
   drivers/mailbox/rockchip-mailbox.c:162:1: note: in expansion of macro 'MODULE_DEVICE_TABLE'
     162 | MODULE_DEVICE_TABLE(of, rockchp_mbox_of_match);
         | ^~~~~~~~~~~~~~~~~~~
--
   In file included from include/linux/clk.h:13,
                    from drivers/soc/imx/imx8mp-blk-ctrl.c:7:
>> include/linux/module.h:251:21: error: '__mod_of__imx8m_blk_ctrl_of_match__kmod_imx8mp_blk_ctrl_device_table' aliased to undefined symbol 'imx8m_blk_ctrl_of_match'
     251 |         CONCATENATE(__mod_##type##__##name##__,                         \
         |                     ^~~~~~
   include/linux/kernel.h:491:24: note: in definition of macro '__CONCAT'
     491 | #define __CONCAT(a, b) a ## b
         |                        ^
   include/linux/module.h:250:14: note: in expansion of macro 'CONCATENATE'
     250 | extern void *CONCATENATE(                                               \
         |              ^~~~~~~~~~~
   include/linux/kernel.h:492:27: note: in expansion of macro '__CONCAT'
     492 | #define CONCATENATE(a, b) __CONCAT(a, b)
         |                           ^~~~~~~~
   include/linux/module.h:251:9: note: in expansion of macro 'CONCATENATE'
     251 |         CONCATENATE(__mod_##type##__##name##__,                         \
         |         ^~~~~~~~~~~
   drivers/soc/imx/imx8mp-blk-ctrl.c:746:1: note: in expansion of macro 'MODULE_DEVICE_TABLE'
     746 | MODULE_DEVICE_TABLE(of, imx8m_blk_ctrl_of_match);
         | ^~~~~~~~~~~~~~~~~~~


vim +251 include/linux/module.h

   239	
   240	#ifdef MODULE
   241	/* Creates an alias so file2alias.c can find device table. */
   242	#define MODULE_DEVICE_TABLE(type, name)					\
   243	extern typeof(name) __mod_##type##__##name##_device_table		\
   244	  __attribute__ ((unused, alias(__stringify(name))))
   245	#else  /* !MODULE */
   246	/* The names may not be unique for built-in modules, so include the module name
   247	 * to guarantee uniqueness.
   248	 */
   249	#define MODULE_DEVICE_TABLE(type, name)					\
   250	extern void *CONCATENATE(						\
 > 251		CONCATENATE(__mod_##type##__##name##__,				\
   252			__KBUILD_MODNAME),					\
   253		_device_table)							\
   254		__attribute__ ((unused, alias(__stringify(name))))
   255	#endif
   256
Christophe Leroy Dec. 17, 2022, 10:05 a.m. UTC | #3
Le 16/12/2022 à 23:16, Allen Webb a écrit :
> Implement MODULE_DEVICE_TABLE for build-in modules to make it possible
> to generate a builtin.alias file to complement modules.alias.
> 
> Signed-off-by: Allen Webb <allenwebb@google.com>
> ---
>   include/linux/module.h | 10 +++++++++-
>   1 file changed, 9 insertions(+), 1 deletion(-)
> 
> diff --git a/include/linux/module.h b/include/linux/module.h
> index ec61fb53979a9..49e4019393127 100644
> --- a/include/linux/module.h
> +++ b/include/linux/module.h
> @@ -243,7 +243,15 @@ extern void cleanup_module(void);
>   extern typeof(name) __mod_##type##__##name##_device_table		\
>     __attribute__ ((unused, alias(__stringify(name))))
>   #else  /* !MODULE */
> -#define MODULE_DEVICE_TABLE(type, name)
> +/* The names may not be unique for built-in modules, so include the module name
> + * to guarantee uniqueness.
> + */

This is network only comment style.

Other parts of kenel have different style, see 
https://docs.kernel.org/process/coding-style.html#commenting

> +#define MODULE_DEVICE_TABLE(type, name)					\
> +extern void *CONCATENATE(						\

'extern' keyword is pointless of function prototypes and deprecated. 
Don't add new occurences.

> +	CONCATENATE(__mod_##type##__##name##__,				\
> +		__KBUILD_MODNAME),					\
> +	_device_table)							\
> +	__attribute__ ((unused, alias(__stringify(name))))
>   #endif
>   
>   /* Version of form [<epoch>:]<version>[-<extra-version>].
Allen Webb Dec. 19, 2022, 3:56 p.m. UTC | #4
On Sat, Dec 17, 2022 at 4:05 AM Christophe Leroy
<christophe.leroy@csgroup.eu> wrote:
>
>
>
> Le 16/12/2022 à 23:16, Allen Webb a écrit :
> > Implement MODULE_DEVICE_TABLE for build-in modules to make it possible
> > to generate a builtin.alias file to complement modules.alias.
> >
> > Signed-off-by: Allen Webb <allenwebb@google.com>
> > ---
> >   include/linux/module.h | 10 +++++++++-
> >   1 file changed, 9 insertions(+), 1 deletion(-)
> >
> > diff --git a/include/linux/module.h b/include/linux/module.h
> > index ec61fb53979a9..49e4019393127 100644
> > --- a/include/linux/module.h
> > +++ b/include/linux/module.h
> > @@ -243,7 +243,15 @@ extern void cleanup_module(void);
> >   extern typeof(name) __mod_##type##__##name##_device_table           \
> >     __attribute__ ((unused, alias(__stringify(name))))
> >   #else  /* !MODULE */
> > -#define MODULE_DEVICE_TABLE(type, name)
> > +/* The names may not be unique for built-in modules, so include the module name
> > + * to guarantee uniqueness.
> > + */
>
> This is network only comment style.

I have fixed this in my local copy and will include it with the next upload.

>
> Other parts of kenel have different style, see
> https://docs.kernel.org/process/coding-style.html#commenting
>
> > +#define MODULE_DEVICE_TABLE(type, name)                                      \
> > +extern void *CONCATENATE(                                            \
>
> 'extern' keyword is pointless of function prototypes and deprecated.
> Don't add new occurences.


This is a weird case because these symbols are used for post
compilation processing by modpost. If I drop the extern keyword, the
build fails with a bunch of errors of the form:

/mnt/host/source/src/third_party/kernel/upstream/drivers/hid/hid-generic.c:79:1:
error: definition
'__mod_hid__hid_table__kmod_hid_generic_device_table' cannot also be
an alias
MODULE_DEVICE_TABLE(hid, hid_table);
^
/mnt/host/source/src/third_party/kernel/upstream/include/linux/module.h:255:26:
note: expanded from macro 'MODULE_DEVICE_TABLE'
        __attribute__ ((unused, alias(__stringify(name))))

>
>
> > +     CONCATENATE(__mod_##type##__##name##__,                         \
> > +             __KBUILD_MODNAME),                                      \
> > +     _device_table)                                                  \
> > +     __attribute__ ((unused, alias(__stringify(name))))
> >   #endif
> >
> >   /* Version of form [<epoch>:]<version>[-<extra-version>].
diff mbox series

Patch

diff --git a/include/linux/module.h b/include/linux/module.h
index ec61fb53979a9..49e4019393127 100644
--- a/include/linux/module.h
+++ b/include/linux/module.h
@@ -243,7 +243,15 @@  extern void cleanup_module(void);
 extern typeof(name) __mod_##type##__##name##_device_table		\
   __attribute__ ((unused, alias(__stringify(name))))
 #else  /* !MODULE */
-#define MODULE_DEVICE_TABLE(type, name)
+/* The names may not be unique for built-in modules, so include the module name
+ * to guarantee uniqueness.
+ */
+#define MODULE_DEVICE_TABLE(type, name)					\
+extern void *CONCATENATE(						\
+	CONCATENATE(__mod_##type##__##name##__,				\
+		__KBUILD_MODNAME),					\
+	_device_table)							\
+	__attribute__ ((unused, alias(__stringify(name))))
 #endif
 
 /* Version of form [<epoch>:]<version>[-<extra-version>].