diff mbox series

[v7,4/5] file2alias.c: Implement builtin.alias generation

Message ID 20221216221703.294683-5-allenwebb@google.com
State Superseded
Headers show
Series Generate modules.builtin.alias from match ids | expand

Commit Message

Allen Webb Dec. 16, 2022, 10:17 p.m. UTC
This populates the mod->modalias_buf with aliases for built-in modules
when modpost is run against vmlinuz.o.

Signed-off-by: Allen Webb <allenwebb@google.com>
---
 scripts/mod/file2alias.c | 55 +++++++++++++++++++++++++++-------------
 1 file changed, 38 insertions(+), 17 deletions(-)

Comments

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

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on masahiroy-kbuild/fixes]
[also build test WARNING 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-5-allenwebb%40google.com
patch subject: [PATCH v7 4/5] file2alias.c: Implement builtin.alias generation
config: x86_64-randconfig-a001
compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project f28c006a5895fc0e329fe15fead81e37457cb1d1)
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/e65dd221062ee2430d083c7a65400fe1b1fc771f
        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 e65dd221062ee2430d083c7a65400fe1b1fc771f
        # 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=x86_64 olddefconfig
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=x86_64 prepare

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

All warnings (new ones prefixed by >>):

>> scripts/mod/file2alias.c:679:9: warning: mixing declarations and code is incompatible with standards before C99 [-Wdeclaration-after-statement]
                           char acpi_id[PNP_ID_LEN];
                                ^
   1 warning generated.
--
>> scripts/mod/file2alias.c:679:9: warning: mixing declarations and code is incompatible with standards before C99 [-Wdeclaration-after-statement]
                           char acpi_id[PNP_ID_LEN];
                                ^
   1 warning generated.


vim +679 scripts/mod/file2alias.c

^1da177e4c3f41 Linus Torvalds 2005-04-16  633  
0c81eed4b9d627 Kay Sievers    2008-02-21  634  /* looks like: "pnp:dD" for every device of the card */
0c81eed4b9d627 Kay Sievers    2008-02-21  635  static void do_pnp_card_entries(void *symval, unsigned long size,
0c81eed4b9d627 Kay Sievers    2008-02-21  636  				struct module *mod)
^1da177e4c3f41 Linus Torvalds 2005-04-16  637  {
6543becf26fff6 Andreas Schwab 2013-01-20  638  	const unsigned long id_size = SIZE_pnp_card_device_id;
0c81eed4b9d627 Kay Sievers    2008-02-21  639  	const unsigned int count = (size / id_size)-1;
0c81eed4b9d627 Kay Sievers    2008-02-21  640  	unsigned int i;
0c81eed4b9d627 Kay Sievers    2008-02-21  641  
0c81eed4b9d627 Kay Sievers    2008-02-21  642  	device_id_check(mod->name, "pnp", size, id_size, symval);
0c81eed4b9d627 Kay Sievers    2008-02-21  643  
0c81eed4b9d627 Kay Sievers    2008-02-21  644  	for (i = 0; i < count; i++) {
0c81eed4b9d627 Kay Sievers    2008-02-21  645  		unsigned int j;
6543becf26fff6 Andreas Schwab 2013-01-20  646  		DEF_FIELD_ADDR(symval + i * id_size, pnp_card_device_id, devs);
0c81eed4b9d627 Kay Sievers    2008-02-21  647  
0c81eed4b9d627 Kay Sievers    2008-02-21  648  		for (j = 0; j < PNP_MAX_DEVICES; j++) {
6543becf26fff6 Andreas Schwab 2013-01-20  649  			const char *id = (char *)(*devs)[j].id;
0c81eed4b9d627 Kay Sievers    2008-02-21  650  			int i2, j2;
0c81eed4b9d627 Kay Sievers    2008-02-21  651  			int dup = 0;
0c81eed4b9d627 Kay Sievers    2008-02-21  652  
0c81eed4b9d627 Kay Sievers    2008-02-21  653  			if (!id[0])
0c81eed4b9d627 Kay Sievers    2008-02-21  654  				break;
0c81eed4b9d627 Kay Sievers    2008-02-21  655  
0c81eed4b9d627 Kay Sievers    2008-02-21  656  			/* find duplicate, already added value */
0c81eed4b9d627 Kay Sievers    2008-02-21  657  			for (i2 = 0; i2 < i && !dup; i2++) {
c2b1a9226fe7c1 Leonardo Bras  2018-10-24  658  				DEF_FIELD_ADDR_VAR(symval + i2 * id_size,
c2b1a9226fe7c1 Leonardo Bras  2018-10-24  659  						   pnp_card_device_id,
c2b1a9226fe7c1 Leonardo Bras  2018-10-24  660  						   devs, devs_dup);
0c81eed4b9d627 Kay Sievers    2008-02-21  661  
0c81eed4b9d627 Kay Sievers    2008-02-21  662  				for (j2 = 0; j2 < PNP_MAX_DEVICES; j2++) {
c2b1a9226fe7c1 Leonardo Bras  2018-10-24  663  					const char *id2 =
c2b1a9226fe7c1 Leonardo Bras  2018-10-24  664  						(char *)(*devs_dup)[j2].id;
^1da177e4c3f41 Linus Torvalds 2005-04-16  665  
0c81eed4b9d627 Kay Sievers    2008-02-21  666  					if (!id2[0])
0c81eed4b9d627 Kay Sievers    2008-02-21  667  						break;
0c81eed4b9d627 Kay Sievers    2008-02-21  668  
0c81eed4b9d627 Kay Sievers    2008-02-21  669  					if (!strcmp(id, id2)) {
0c81eed4b9d627 Kay Sievers    2008-02-21  670  						dup = 1;
^1da177e4c3f41 Linus Torvalds 2005-04-16  671  						break;
^1da177e4c3f41 Linus Torvalds 2005-04-16  672  					}
0c81eed4b9d627 Kay Sievers    2008-02-21  673  				}
0c81eed4b9d627 Kay Sievers    2008-02-21  674  			}
0c81eed4b9d627 Kay Sievers    2008-02-21  675  
0c81eed4b9d627 Kay Sievers    2008-02-21  676  			/* add an individual alias for every device entry */
e65dd221062ee2 Allen Webb     2022-12-16  677  			if (dup)
e65dd221062ee2 Allen Webb     2022-12-16  678  				continue;
6543becf26fff6 Andreas Schwab 2013-01-20 @679  			char acpi_id[PNP_ID_LEN];
72638f598ec9f0 Kay Sievers    2009-01-08  680  			int k;
72638f598ec9f0 Kay Sievers    2009-01-08  681  
0c81eed4b9d627 Kay Sievers    2008-02-21  682  			buf_printf(&mod->dev_table_buf,
0c81eed4b9d627 Kay Sievers    2008-02-21  683  				   "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
e65dd221062ee2 Allen Webb     2022-12-16  684  			if (mod->builtin_name)
e65dd221062ee2 Allen Webb     2022-12-16  685  				buf_printf(&mod->modalias_buf, "alias pnp:d%s* %s\n",
e65dd221062ee2 Allen Webb     2022-12-16  686  					   id, mod->builtin_name);
72638f598ec9f0 Kay Sievers    2009-01-08  687  
72638f598ec9f0 Kay Sievers    2009-01-08  688  			/* fix broken pnp bus lowercasing */
72638f598ec9f0 Kay Sievers    2009-01-08  689  			for (k = 0; k < sizeof(acpi_id); k++)
72638f598ec9f0 Kay Sievers    2009-01-08  690  				acpi_id[k] = toupper(id[k]);
22454cb99fc39f Kay Sievers    2008-05-28  691  			buf_printf(&mod->dev_table_buf,
72638f598ec9f0 Kay Sievers    2009-01-08  692  				   "MODULE_ALIAS(\"acpi*:%s:*\");\n", acpi_id);
e65dd221062ee2 Allen Webb     2022-12-16  693  			if (mod->builtin_name)
e65dd221062ee2 Allen Webb     2022-12-16  694  				buf_printf(&mod->modalias_buf, "alias acpi*:%s:* %s\n",
e65dd221062ee2 Allen Webb     2022-12-16  695  					   acpi_id, mod->builtin_name);
0c81eed4b9d627 Kay Sievers    2008-02-21  696  		}
0c81eed4b9d627 Kay Sievers    2008-02-21  697  	}
^1da177e4c3f41 Linus Torvalds 2005-04-16  698  }
^1da177e4c3f41 Linus Torvalds 2005-04-16  699
Christophe Leroy Dec. 17, 2022, 10:13 a.m. UTC | #2
Le 16/12/2022 à 23:17, Allen Webb a écrit :
> This populates the mod->modalias_buf with aliases for built-in modules
> when modpost is run against vmlinuz.o.
> 
> Signed-off-by: Allen Webb <allenwebb@google.com>
> ---
>   scripts/mod/file2alias.c | 55 +++++++++++++++++++++++++++-------------
>   1 file changed, 38 insertions(+), 17 deletions(-)
> 
> diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
> index 458e41ae0f5f1..8ed08154b3d81 100644
> --- a/scripts/mod/file2alias.c
> +++ b/scripts/mod/file2alias.c
> @@ -232,6 +232,8 @@ static void do_usb_entry(void *symval,
>   	add_wildcard(alias);
>   	buf_printf(&mod->dev_table_buf,
>   		   "MODULE_ALIAS(\"%s\");\n", alias);
> +	if (mod->builtin_name)
> +		buf_printf(&mod->modalias_buf, "alias %s %s\n", alias, mod->builtin_name);
>   }
>   
>   /* Handles increment/decrement of BCD formatted integers */
> @@ -376,9 +378,13 @@ static void do_of_entry_multi(void *symval, struct module *mod)
>   			*tmp = '_';
>   
>   	buf_printf(&mod->dev_table_buf, "MODULE_ALIAS(\"%s\");\n", alias);
> +	if (mod->builtin_name)
> +		buf_printf(&mod->modalias_buf, "alias %s %s\n", alias, mod->builtin_name);
>   	strcat(alias, "C");
>   	add_wildcard(alias);
>   	buf_printf(&mod->dev_table_buf, "MODULE_ALIAS(\"%s\");\n", alias);
> +	if (mod->builtin_name)
> +		buf_printf(&mod->modalias_buf, "alias %s %s\n", alias, mod->builtin_name);
>   }
>   
>   static void do_of_table(void *symval, unsigned long size,
> @@ -610,12 +616,18 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
>   
>   		buf_printf(&mod->dev_table_buf,
>   			   "MODULE_ALIAS(\"pnp:d%s*\");\n", *id);
> +		if (mod->builtin_name)
> +			buf_printf(&mod->modalias_buf, "alias pnp:d%s* %s\n",
> +				   *id, mod->builtin_name);
>   
>   		/* fix broken pnp bus lowercasing */
>   		for (j = 0; j < sizeof(acpi_id); j++)
>   			acpi_id[j] = toupper((*id)[j]);
>   		buf_printf(&mod->dev_table_buf,
>   			   "MODULE_ALIAS(\"acpi*:%s:*\");\n", acpi_id);
> +		if (mod->builtin_name)
> +			buf_printf(&mod->modalias_buf, "alias acpi*:%s:* %s\n",
> +				   acpi_id, mod->builtin_name);
>   	}
>   }
>   
> @@ -662,19 +674,25 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
>   			}
>   
>   			/* add an individual alias for every device entry */
> -			if (!dup) {
> -				char acpi_id[PNP_ID_LEN];
> -				int k;
> -
> -				buf_printf(&mod->dev_table_buf,
> -					   "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
> -
> -				/* fix broken pnp bus lowercasing */
> -				for (k = 0; k < sizeof(acpi_id); k++)
> -					acpi_id[k] = toupper(id[k]);
> -				buf_printf(&mod->dev_table_buf,
> -					   "MODULE_ALIAS(\"acpi*:%s:*\");\n", acpi_id);
> -			}
> +			if (dup)
> +				continue;
> +			char acpi_id[PNP_ID_LEN];
> +			int k;

No declarations in the middle of a block. Put declarations before code.

> +
> +			buf_printf(&mod->dev_table_buf,
> +				   "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
> +			if (mod->builtin_name)
> +				buf_printf(&mod->modalias_buf, "alias pnp:d%s* %s\n",
> +					   id, mod->builtin_name);
> +
> +			/* fix broken pnp bus lowercasing */
> +			for (k = 0; k < sizeof(acpi_id); k++)
> +				acpi_id[k] = toupper(id[k]);
> +			buf_printf(&mod->dev_table_buf,
> +				   "MODULE_ALIAS(\"acpi*:%s:*\");\n", acpi_id);
> +			if (mod->builtin_name)
> +				buf_printf(&mod->modalias_buf, "alias acpi*:%s:* %s\n",
> +					   acpi_id, mod->builtin_name);
>   		}
>   	}
>   }
> @@ -1476,10 +1494,13 @@ static void do_table(void *symval, unsigned long size,
>   	size -= id_size;
>   
>   	for (i = 0; i < size; i += id_size) {
> -		if (do_entry(mod->name, symval+i, alias)) {
> -			buf_printf(&mod->dev_table_buf,
> -				   "MODULE_ALIAS(\"%s\");\n", alias);
> -		}
> +		if (!do_entry(mod->name, symval + i, alias))
> +			continue;
> +		buf_printf(&mod->dev_table_buf, "MODULE_ALIAS(\"%s\");\n", alias);
> +		if (!mod->builtin_name)
> +			continue;
> +		buf_printf(&mod->modalias_buf, "alias %s %s\n", alias,
> +			   mod->builtin_name);
>   	}
>   }
>
diff mbox series

Patch

diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
index 458e41ae0f5f1..8ed08154b3d81 100644
--- a/scripts/mod/file2alias.c
+++ b/scripts/mod/file2alias.c
@@ -232,6 +232,8 @@  static void do_usb_entry(void *symval,
 	add_wildcard(alias);
 	buf_printf(&mod->dev_table_buf,
 		   "MODULE_ALIAS(\"%s\");\n", alias);
+	if (mod->builtin_name)
+		buf_printf(&mod->modalias_buf, "alias %s %s\n", alias, mod->builtin_name);
 }
 
 /* Handles increment/decrement of BCD formatted integers */
@@ -376,9 +378,13 @@  static void do_of_entry_multi(void *symval, struct module *mod)
 			*tmp = '_';
 
 	buf_printf(&mod->dev_table_buf, "MODULE_ALIAS(\"%s\");\n", alias);
+	if (mod->builtin_name)
+		buf_printf(&mod->modalias_buf, "alias %s %s\n", alias, mod->builtin_name);
 	strcat(alias, "C");
 	add_wildcard(alias);
 	buf_printf(&mod->dev_table_buf, "MODULE_ALIAS(\"%s\");\n", alias);
+	if (mod->builtin_name)
+		buf_printf(&mod->modalias_buf, "alias %s %s\n", alias, mod->builtin_name);
 }
 
 static void do_of_table(void *symval, unsigned long size,
@@ -610,12 +616,18 @@  static void do_pnp_device_entry(void *symval, unsigned long size,
 
 		buf_printf(&mod->dev_table_buf,
 			   "MODULE_ALIAS(\"pnp:d%s*\");\n", *id);
+		if (mod->builtin_name)
+			buf_printf(&mod->modalias_buf, "alias pnp:d%s* %s\n",
+				   *id, mod->builtin_name);
 
 		/* fix broken pnp bus lowercasing */
 		for (j = 0; j < sizeof(acpi_id); j++)
 			acpi_id[j] = toupper((*id)[j]);
 		buf_printf(&mod->dev_table_buf,
 			   "MODULE_ALIAS(\"acpi*:%s:*\");\n", acpi_id);
+		if (mod->builtin_name)
+			buf_printf(&mod->modalias_buf, "alias acpi*:%s:* %s\n",
+				   acpi_id, mod->builtin_name);
 	}
 }
 
@@ -662,19 +674,25 @@  static void do_pnp_card_entries(void *symval, unsigned long size,
 			}
 
 			/* add an individual alias for every device entry */
-			if (!dup) {
-				char acpi_id[PNP_ID_LEN];
-				int k;
-
-				buf_printf(&mod->dev_table_buf,
-					   "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
-
-				/* fix broken pnp bus lowercasing */
-				for (k = 0; k < sizeof(acpi_id); k++)
-					acpi_id[k] = toupper(id[k]);
-				buf_printf(&mod->dev_table_buf,
-					   "MODULE_ALIAS(\"acpi*:%s:*\");\n", acpi_id);
-			}
+			if (dup)
+				continue;
+			char acpi_id[PNP_ID_LEN];
+			int k;
+
+			buf_printf(&mod->dev_table_buf,
+				   "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
+			if (mod->builtin_name)
+				buf_printf(&mod->modalias_buf, "alias pnp:d%s* %s\n",
+					   id, mod->builtin_name);
+
+			/* fix broken pnp bus lowercasing */
+			for (k = 0; k < sizeof(acpi_id); k++)
+				acpi_id[k] = toupper(id[k]);
+			buf_printf(&mod->dev_table_buf,
+				   "MODULE_ALIAS(\"acpi*:%s:*\");\n", acpi_id);
+			if (mod->builtin_name)
+				buf_printf(&mod->modalias_buf, "alias acpi*:%s:* %s\n",
+					   acpi_id, mod->builtin_name);
 		}
 	}
 }
@@ -1476,10 +1494,13 @@  static void do_table(void *symval, unsigned long size,
 	size -= id_size;
 
 	for (i = 0; i < size; i += id_size) {
-		if (do_entry(mod->name, symval+i, alias)) {
-			buf_printf(&mod->dev_table_buf,
-				   "MODULE_ALIAS(\"%s\");\n", alias);
-		}
+		if (!do_entry(mod->name, symval + i, alias))
+			continue;
+		buf_printf(&mod->dev_table_buf, "MODULE_ALIAS(\"%s\");\n", alias);
+		if (!mod->builtin_name)
+			continue;
+		buf_printf(&mod->modalias_buf, "alias %s %s\n", alias,
+			   mod->builtin_name);
 	}
 }