[PATCH] kbuild: detect module name collisions between '-' and '_'

From: Hamdy Abou El Anein

Date: Tue Nov 03 2026 - 08:00:14 EST


From: Hamdy Abou El Anein <hamdy.aea@xxxxxxxxxxxxxx>

Kbuild converts hyphens to underscores in KBUILD_MODNAME, and the module
loader treats both characters as equivalent. However, modules-check.sh
compares module basenames without normalization. Consequently, modules
named foo-bar.o and foo_bar.o pass the conflict check even though they
have the same effective module name.

Normalize basenames before checking for duplicates, and use awk to show
the original module paths in diagnostics. Preserve detection of exact
duplicates and leave distinct names unaffected.

Signed-off-by: Hamdy Abou El Anein <hamdy.aea@xxxxxxxxxxxxxx>
---
scripts/modules-check.sh | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/scripts/modules-check.sh b/scripts/modules-check.sh
index 4c8da90..3d12dc5 100755
--- a/scripts/modules-check.sh
+++ b/scripts/modules-check.sh
@@ -13,10 +13,19 @@ exit_code=0
# Check uniqueness of module names
check_same_name_modules()
{
- for m in $(sed 's:.*/::' "$1" | sort | uniq -d)
+ for m in $(sed 's:.*/::; s/-/_/g' "$1" | sort | uniq -d)
do
echo "error: the following would cause module name conflict:" >&2
- sed -n "/\/$m/s:^\(.*\)\.o\$: \1.ko:p" "$1" >&2
+ awk -v name="$m" '
+ {
+ basename = $0
+ sub(/^.*\//, "", basename)
+ gsub(/-/, "_", basename)
+ if (basename == name) {
+ sub(/\.o$/, ".ko")
+ print " " $0
+ }
+ }' "$1" >&2
exit_code=1
done
}

base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
--
2.56.0