From: Masahiro Yamada <masahiroy@kernel.org>
To: linux-kbuild@vger.kernel.org
Cc: Masahiro Yamada <masahiroy@kernel.org>,
Nathan Chancellor <nathan@kernel.org>,
Nicolas Schier <nicolas@fjasle.eu>,
linux-kernel@vger.kernel.org
Subject: [PATCH 04/15] modpost: deduplicate MODULE_ALIAS() for all drivers
Date: Wed, 20 Nov 2024 08:56:42 +0900 [thread overview]
Message-ID: <20241119235705.1576946-4-masahiroy@kernel.org> (raw)
In-Reply-To: <20241119235705.1576946-1-masahiroy@kernel.org>
MODULE_DEVICE_TABLE(pnp_card, ...) may have duplicated IDs. For
instance, snd_ad1816a_pnpids[] in sound/isa/ad1816a/ad1816a.c includes
multiple occurrences of the "ADS7180" string within its .devs fields.
Currently, do_pnp_card_entries() handles deduplication on its own, but
this logic should be moved to a common helper function, as drivers in
other subsystems might also have similar duplication issues.
For example, drivers/media/i2c/s5c73m3/s5c73m3.mod.c contains duplicated
MODULE_ALIAS() entries because both s5c73m3-core.c and s5c73m3-spi.c
define the same compatible string.
This commit eliminates redundant MODULE_ALIAS() entries across all
drivers.
[Before]
$ grep MODULE_ALIAS drivers/media/i2c/s5c73m3/s5c73m3.mod.c
MODULE_ALIAS("i2c:S5C73M3");
MODULE_ALIAS("of:N*T*Csamsung,s5c73m3");
MODULE_ALIAS("of:N*T*Csamsung,s5c73m3C*");
MODULE_ALIAS("of:N*T*Csamsung,s5c73m3");
MODULE_ALIAS("of:N*T*Csamsung,s5c73m3C*");
[After]
$ grep MODULE_ALIAS drivers/media/i2c/s5c73m3/s5c73m3.mod.c
MODULE_ALIAS("i2c:S5C73M3");
MODULE_ALIAS("of:N*T*Csamsung,s5c73m3");
MODULE_ALIAS("of:N*T*Csamsung,s5c73m3C*");
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---
scripts/mod/file2alias.c | 48 +++++++++++++---------------------------
1 file changed, 15 insertions(+), 33 deletions(-)
diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
index e31619cee05e..57bd4e8da8d5 100644
--- a/scripts/mod/file2alias.c
+++ b/scripts/mod/file2alias.c
@@ -48,7 +48,7 @@ static void __attribute__((format (printf, 3, 4)))
module_alias_printf(struct module *mod, bool append_wildcard,
const char *fmt, ...)
{
- struct module_alias *new;
+ struct module_alias *new, *als;
size_t len, n;
va_list ap;
@@ -84,6 +84,14 @@ module_alias_printf(struct module *mod, bool append_wildcard,
new->str[n + 1] = '\0';
}
+ /* avoid duplication */
+ list_for_each_entry(als, &mod->aliases, node) {
+ if (!strcmp(als->str, new->str)) {
+ free(new);
+ return;
+ }
+ }
+
list_add_tail(&new->node, &mod->aliases);
}
@@ -685,44 +693,18 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
for (j = 0; j < PNP_MAX_DEVICES; j++) {
const char *id = (char *)(*devs)[j].id;
- int i2, j2;
- int dup = 0;
+ char acpi_id[PNP_ID_LEN];
if (!id[0])
break;
- /* find duplicate, already added value */
- for (i2 = 0; i2 < i && !dup; i2++) {
- DEF_FIELD_ADDR_VAR(symval + i2 * id_size,
- pnp_card_device_id,
- devs, devs_dup);
-
- for (j2 = 0; j2 < PNP_MAX_DEVICES; j2++) {
- const char *id2 =
- (char *)(*devs_dup)[j2].id;
-
- if (!id2[0])
- break;
-
- if (!strcmp(id, id2)) {
- dup = 1;
- break;
- }
- }
- }
-
/* add an individual alias for every device entry */
- if (!dup) {
- char acpi_id[PNP_ID_LEN];
- int k;
+ module_alias_printf(mod, false, "pnp:d%s*", id);
- module_alias_printf(mod, false, "pnp:d%s*", id);
-
- /* fix broken pnp bus lowercasing */
- for (k = 0; k < sizeof(acpi_id); k++)
- acpi_id[k] = toupper(id[k]);
- module_alias_printf(mod, false, "acpi*:%s:*", acpi_id);
- }
+ /* fix broken pnp bus lowercasing */
+ for (int k = 0; k < sizeof(acpi_id); k++)
+ acpi_id[k] = toupper(id[k]);
+ module_alias_printf(mod, false, "acpi*:%s:*", acpi_id);
}
}
}
--
2.43.0
next prev parent reply other threads:[~2024-11-19 23:57 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-19 23:56 [PATCH 01/15] modpost: remove incorrect code in do_eisa_entry() Masahiro Yamada
2024-11-19 23:56 ` [PATCH 02/15] modpost: remove unnecessary check in do_acpi_entry() Masahiro Yamada
2024-11-19 23:56 ` [PATCH 03/15] modpost: introduce module_alias_printf() helper Masahiro Yamada
2024-11-20 2:37 ` Masahiro Yamada
2024-11-19 23:56 ` Masahiro Yamada [this message]
2024-11-19 23:56 ` [PATCH 05/15] modpost: remove DEF_FIELD_ADDR_VAR() macro Masahiro Yamada
2024-11-19 23:56 ` [PATCH 06/15] modpost: pass (struct module *) to do_*_entry() functions Masahiro Yamada
2024-11-19 23:56 ` [PATCH 07/15] modpost: call module_alias_printf() from all " Masahiro Yamada
2024-11-19 23:56 ` [PATCH 08/15] modpost: convert do_pnp_card_entries() to a generic handler Masahiro Yamada
2024-11-19 23:56 ` [PATCH 09/15] modpost: convert do_pnp_device_entry() " Masahiro Yamada
2024-11-19 23:56 ` [PATCH 10/15] modpost: convert do_of_table() " Masahiro Yamada
2024-11-19 23:56 ` [PATCH 11/15] modpost: convert do_usb_table() " Masahiro Yamada
2024-11-19 23:56 ` [PATCH 12/15] modpost: move strstarts() to modpost.h Masahiro Yamada
2024-11-19 23:56 ` [PATCH 13/15] modpost: rename variables in handle_moddevtable() Masahiro Yamada
2024-11-19 23:56 ` [PATCH 14/15] modpost: rename alias symbol for MODULE_DEVICE_TABLE() Masahiro Yamada
2024-11-19 23:56 ` [PATCH 15/15] modpost: improve error messages in device_id_check() Masahiro Yamada
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241119235705.1576946-4-masahiroy@kernel.org \
--to=masahiroy@kernel.org \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nathan@kernel.org \
--cc=nicolas@fjasle.eu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox