From patchwork Fri May 17 04:27:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 164384 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp1685932ili; Thu, 16 May 2019 21:29:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqy/N4gMh4ayNJ1xH1mLaX7X2EdQlvyZeX0xQew8oXDUKs8SRJLomdtni5IqTBV8QS1NhmIy X-Received: by 2002:a63:88c7:: with SMTP id l190mr54540834pgd.244.1558067397658; Thu, 16 May 2019 21:29:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558067397; cv=none; d=google.com; s=arc-20160816; b=VVOIv20al3vXuVoNkRhrECTA2G48TrpwKg2L5jCeaGe3Nq09la2fEyWXdUOVSV2TUa bYQ9HA5tEOV4nxD/RJjiXjr+RCs4nWGevj1JDJGXe60RTOsy+wQL2I862RugNq99EYIF FpxsDTDs8lsJN/GbAETLwTieSdXOMmtPeuYIP7FLlfbxatZ5fEsE6ctuKbfeqpnmCuQC ndFhlIIFi0jFgkNEWgEQugEceJOeFoHWHw71XuG/HTLQRlXUHOsy4acaD2f2uHRbCcYy VbEUCYd5B/vXsQbUyOtyo1/TdGeNhI2fsYLia8vRbwVZc8DV7KFI4mPPuNwxXNVzHqPB nMdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=S6lUG5wzELNkLDTIQ5q0KxmZoKYRPjFzFvxypw0i15o=; b=jgwHunwy8fFW3u6iy0+R/Kj2Sfck1mMO8ZdxRL4U6v8A2Rj+WRJ/xObBZpRnyv0m7r x0jjx+iAbXTYk4mIqcFFLTIm/27rFXKoGnleJpYCC1Hw/SEft9W4fEtUtJTDMLbmhLCH MQZh75QvqVGMsXU4RmOwrJirq8VzyLd12rt9gGsX98sD8wrXbHPDb0KYMHd/BVND67Pj 2E2jxbSFugYFEZPFPzy9thoFEPRGyfWfC3ihmDUFXIagMJO/UCkk7ZhCynWMx+OFzQ/U iWl0dAzQwJAewJ0Yp/urQsCq5qwGj7L9IaW8IfVzah3W49eUI5rUMngrAaXPuxR9Tiqm VJrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=lmJWY92e; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x4si6921139plv.329.2019.05.16.21.29.57; Thu, 16 May 2019 21:29:57 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=lmJWY92e; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727500AbfEQE34 (ORCPT + 30 others); Fri, 17 May 2019 00:29:56 -0400 Received: from conuserg-12.nifty.com ([210.131.2.79]:40507 "EHLO conuserg-12.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726078AbfEQE3z (ORCPT ); Fri, 17 May 2019 00:29:55 -0400 Received: from localhost.localdomain (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-12.nifty.com with ESMTP id x4H4S6m7020760; Fri, 17 May 2019 13:28:06 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-12.nifty.com x4H4S6m7020760 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1558067287; bh=S6lUG5wzELNkLDTIQ5q0KxmZoKYRPjFzFvxypw0i15o=; h=From:To:Cc:Subject:Date:From; b=lmJWY92eISyiUDky3rMD3ZyuryoVjAMcuTit/WmqwC8NXp7LrdSs9SUFwZoRYBjqa M4wRPzpxa5JJIArOLFzLBGxR7XDpwmowRFKd7Y6f4JEhGls/6PQPSRmEGKf4onuKCk qiOdjy4a7x6wQyB3FZzdu2Um5sHJpjgmHYVhgLH0W38UROX5QUvbW5QqZZaO3PpsZD vM+R6PSpD3geAyxQxInyiolXsrDb/XLRCAd2d2QC/4Caz3cSmnWbb6KsYg4xVx8rVH pgfFkg1ZnlqXNNy7s7c5oVD6EaY6U+D5nuYJtD+cYMm7HP8GSF3UfXDP/pnUfYP3uH ckE6paHnX6XpA== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Sam Ravnborg , Arnd Bergmann , Greg KH , Jessica Yu , Lucas De Marchi , Stephen Rothwell , Michael Schmitz , Linus Torvalds , Rusty Russell , Kees Cook , Masahiro Yamada , Michal Marek , linux-kernel@vger.kernel.org Subject: [PATCH v2] kbuild: check uniqueness of module names Date: Fri, 17 May 2019 13:27:53 +0900 Message-Id: <20190517042753.25857-1-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In the recent build test of linux-next, Stephen saw a build error caused by a broken .tmp_versions/*.mod file: https://lkml.org/lkml/2019/5/13/991 drivers/net/phy/asix.ko and drivers/net/usb/asix.ko have the same basename, and there is a race in generating .tmp_versions/asix.mod Kbuild has not checked this before, and it suddenly shows up with obscure error message when this kind of race occurs. Non-unique module names cause various sort of problems, but it is not trivial to catch them by eyes. Hence, this script. It checks not only real modules, but also built-in modules (i.e. controlled by tristate CONFIG option, but currently compiled with =y). Non-unique names for built-in modules also cause problems because /sys/modules/ would fall over. I tested allmodconfig on the latest kernel, and it detected the following: warning: same basename if the following are built as modules: drivers/regulator/88pm800.ko drivers/mfd/88pm800.ko warning: same basename if the following are built as modules: drivers/gpu/drm/bridge/adv7511/adv7511.ko drivers/media/i2c/adv7511.ko warning: same basename if the following are built as modules: drivers/net/phy/asix.ko drivers/net/usb/asix.ko warning: same basename if the following are built as modules: fs/coda/coda.ko drivers/media/platform/coda/coda.ko warning: same basename if the following are built as modules: drivers/net/phy/realtek.ko drivers/net/dsa/realtek.ko Reported-by: Stephen Rothwell Signed-off-by: Masahiro Yamada Reviewed-by: Kees Cook --- Changes in v2: - redirect messages to stderr - use '--' after 'basename -a' - use '-r' for xargs to cope with empty modules.order/modules.builtin Makefile | 1 + scripts/modules-check.sh | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100755 scripts/modules-check.sh -- 2.17.1 Reviewed-by: Stephen ROthwell Reviewed-by: Lucas De Marchi diff --git a/Makefile b/Makefile index a61a95b6b38f..30792fec7a12 100644 --- a/Makefile +++ b/Makefile @@ -1290,6 +1290,7 @@ modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order @$(kecho) ' Building modules, stage 2.'; $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost + $(Q)$(CONFIG_SHELL) $(srctree)/scripts/modules-check.sh modules.builtin: $(vmlinux-dirs:%=%/modules.builtin) $(Q)$(AWK) '!x[$$0]++' $^ > $(objtree)/modules.builtin diff --git a/scripts/modules-check.sh b/scripts/modules-check.sh new file mode 100755 index 000000000000..c875f6eab01e --- /dev/null +++ b/scripts/modules-check.sh @@ -0,0 +1,20 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0 + +set -e + +# Check uniqueness of module names +check_same_name_modules() +{ + same_name_modules=$(cat modules.order modules.builtin | \ + xargs -r basename -a -- | sort | uniq -d) + + for m in $same_name_modules + do + echo "warning: same basename if the following are built as modules:" >&2 + grep -h -e "/$m" modules.order modules.builtin | \ + sed 's:^kernel/: :' >&2 + done +} + +check_same_name_modules