From: Johan Hovold <johan@kernel.org>
To: linux-kernel@vger.kernel.org
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
Rob Herring <robh+dt@kernel.org>,
Frank Rowand <frowand.list@gmail.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Jessica Yu <jeyu@kernel.org>,
Nick Desaulniers <ndesaulniers@gooogle.com>,
Arnd Bergmann <arnd@arndb.de>,
Geert Uytterhoeven <geert@linux-m68k.org>,
Dmitry Torokhov <dmitry.torokhov@gmail.com>,
David Miller <davem@davemloft.net>,
Jakub Jelinek <jakub@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
Thomas Gleixner <tglx@linutronix.de>,
Steven Rostedt <rostedt@goodmis.org>,
Daniel Kurtz <djkurtz@chromium.org>,
linux-arch@vger.kernel.org, linux-m68k@lists.linux-m68k.org,
Johan Hovold <johan@kernel.org>
Subject: [PATCH 4/8] module: simplify version-attribute handling
Date: Tue, 3 Nov 2020 18:57:07 +0100 [thread overview]
Message-ID: <20201103175711.10731-5-johan@kernel.org> (raw)
In-Reply-To: <20201103175711.10731-1-johan@kernel.org>
Instead of using the array-of-pointers trick to avoid having gcc mess up
the built-in module-version array stride, specify type alignment when
declaring entries to prevent gcc from increasing alignment.
This is essentially an alternative (one-line) fix to the problem
addressed by commit b4bc842802db ("module: deal with alignment issues in
built-in module versions").
Note that we have been relying on this gcc behaviour for kernel
parameters for 16 years and it indeed hasn't changed since the
introduction of the aligned attribute in gcc-3.1.
Signed-off-by: Johan Hovold <johan@kernel.org>
---
include/linux/module.h | 26 +++++++++++++-------------
kernel/params.c | 10 ++++------
2 files changed, 17 insertions(+), 19 deletions(-)
diff --git a/include/linux/module.h b/include/linux/module.h
index 293250958512..5958075ea3f4 100644
--- a/include/linux/module.h
+++ b/include/linux/module.h
@@ -266,20 +266,20 @@ extern typeof(name) __mod_##type##__##name##_device_table \
#else
#define MODULE_VERSION(_version) \
MODULE_INFO(version, _version); \
- static struct module_version_attribute ___modver_attr = { \
- .mattr = { \
- .attr = { \
- .name = "version", \
- .mode = S_IRUGO, \
+ static struct module_version_attribute __modver_attr \
+ __used __section("__modver") \
+ __aligned(__alignof__(struct module_version_attribute)) \
+ = { \
+ .mattr = { \
+ .attr = { \
+ .name = "version", \
+ .mode = S_IRUGO, \
+ }, \
+ .show = __modver_version_show, \
}, \
- .show = __modver_version_show, \
- }, \
- .module_name = KBUILD_MODNAME, \
- .version = _version, \
- }; \
- static const struct module_version_attribute \
- __used __section("__modver") \
- * __moduleparam_const __modver_attr = &___modver_attr
+ .module_name = KBUILD_MODNAME, \
+ .version = _version, \
+ };
#endif
/* Optional firmware file (or files) needed by the module
diff --git a/kernel/params.c b/kernel/params.c
index 3835fb82c64b..aa7d6f2213f1 100644
--- a/kernel/params.c
+++ b/kernel/params.c
@@ -843,18 +843,16 @@ ssize_t __modver_version_show(struct module_attribute *mattr,
return scnprintf(buf, PAGE_SIZE, "%s\n", vattr->version);
}
-extern const struct module_version_attribute *__start___modver[];
-extern const struct module_version_attribute *__stop___modver[];
+extern const struct module_version_attribute __start___modver[];
+extern const struct module_version_attribute __stop___modver[];
static void __init version_sysfs_builtin(void)
{
- const struct module_version_attribute **p;
+ const struct module_version_attribute *vattr;
struct module_kobject *mk;
int err;
- for (p = __start___modver; p < __stop___modver; p++) {
- const struct module_version_attribute *vattr = *p;
-
+ for (vattr = __start___modver; vattr < __stop___modver; vattr++) {
mk = locate_module_kobject(vattr->module_name);
if (mk) {
err = sysfs_create_file(&mk->kobj, &vattr->mattr.attr);
--
2.26.2
next prev parent reply other threads:[~2020-11-03 18:12 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-03 17:57 [PATCH 0/8] linker-section array fix and clean ups Johan Hovold
2020-11-03 17:57 ` [PATCH 1/8] of: fix linker-section match-table corruption Johan Hovold
2020-11-03 17:57 ` [PATCH 2/8] earlycon: simplify earlycon-table implementation Johan Hovold
2020-11-03 17:57 ` [PATCH 3/8] module: drop version-attribute alignment Johan Hovold
2020-11-03 17:57 ` Johan Hovold [this message]
2020-11-03 17:57 ` [PATCH 5/8] init: use type alignment for kernel parameters Johan Hovold
2020-11-03 17:57 ` [PATCH 6/8] params: drop redundant "unused" attributes Johan Hovold
2020-11-03 17:57 ` [PATCH 7/8] params: use type alignment for kernel parameters Johan Hovold
2020-11-03 17:57 ` [PATCH 8/8] params: clean up module-param macros Johan Hovold
2020-11-04 9:16 ` get_maintainer.pl bug? (was: Re: [PATCH 0/8] linker-section array fix and clean ups) Johan Hovold
2020-11-04 12:04 ` Joe Perches
2020-11-04 15:31 ` Johan Hovold
2020-11-06 16:03 ` [PATCH 0/8] linker-section array fix and clean ups Jessica Yu
2020-11-06 16:45 ` Johan Hovold
2020-11-06 16:55 ` Steven Rostedt
2020-11-06 17:02 ` Johan Hovold
2020-11-11 15:47 ` Jessica Yu
2020-11-13 14:18 ` Johan Hovold
2020-11-23 10:39 ` Johan Hovold
2020-11-25 14:51 ` Jessica Yu
2020-11-27 9:59 ` Johan Hovold
2020-12-01 9:55 ` Jessica Yu
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=20201103175711.10731-5-johan@kernel.org \
--to=johan@kernel.org \
--cc=arnd@arndb.de \
--cc=davem@davemloft.net \
--cc=djkurtz@chromium.org \
--cc=dmitry.torokhov@gmail.com \
--cc=frowand.list@gmail.com \
--cc=geert@linux-m68k.org \
--cc=gregkh@linuxfoundation.org \
--cc=jakub@redhat.com \
--cc=jeyu@kernel.org \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-m68k@lists.linux-m68k.org \
--cc=ndesaulniers@gooogle.com \
--cc=peterz@infradead.org \
--cc=robh+dt@kernel.org \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
/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;
as well as URLs for NNTP newsgroup(s).