Skip to contentSkip to conversation

serial: 8250: Fix section mismatch with CONFIG_MODULES=n

PATCH In review Danish Khateeb 3 participants 4 messages Sep 26 – Sep 27

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 serial: 8250: Fix section mismatch with CONFIG_MODULES=n

Without CONFIG_MODULES, __init_or_module means __init, so serial8250_pnp_exit() and serial8250_hub6_exit() end up in .init.text. They are also called from serial8250_exit(), which is __exit, and modpost warns:

WARNING: modpost: vmlinux: section mismatch in reference: serial8250_exit+0x2a (section: .exit.text) -> serial8250_pnp_exit (section: .init.text)

The exit code never runs in such a kernel, so nothing breaks at runtime. But a function that is called from both __init and __exit code can't carry either annotation, so drop it.

Fixes a300273c458c ("serial: 8250: hub6: Add cleanup code")
Fixes 4cf187f9dea9 ("serial: 8250: pnp: Annotate init and exit functions for conditional discarding")
Assisted-by LLM

---

Notes:
Tested on tty-next bf961847813d:
- x86_64 defconfig with MODULES=n warns for serial8250_pnp_exit(), and i386 defconfig with MODULES=n, ISA and SERIAL_8250_HUB6 also warns for serial8250_hub6_exit(). Neither warns before a300273c458c. With this patch both build without warnings, and so does x86_64 defconfig.
- Both MODULES=n kernels still register ttyS0 through 8250_pnp in QEMU.

 drivers/tty/serial/8250/8250_hub6.c | 2 +-
 drivers/tty/serial/8250/8250_pnp.c  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/tty/serial/8250/8250_hub6.c +1 -1
index 4d4c54c951cb..848d9723ac56 100644
@@ -54,7 +54,7 @@ int __init serial8250_hub6_init(void)
 	return platform_device_register(&hub6_device);
 }
 
-void __init_or_module serial8250_hub6_exit(void)
+void serial8250_hub6_exit(void)
 {
 	platform_device_unregister(&hub6_device);
 }
drivers/tty/serial/8250/8250_pnp.c +1 -1
index 7decf62400ab..a6257cd6e246 100644
@@ -531,7 +531,7 @@ int __init serial8250_pnp_init(void)
 	return pnp_register_driver(&serial_pnp_driver);
 }
 
-void __init_or_module serial8250_pnp_exit(void)
+void serial8250_pnp_exit(void)
 {
 	pnp_unregister_driver(&serial_pnp_driver);
 }

base-commit: bf961847813d9edcb5a9c089714069428d141fa9

Signature · 1 line
2.55.0
#1 lore raw
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 7 lines

Without CONFIG_MODULES, __init_or_module means __init, so serial8250_pnp_exit() and serial8250_hub6_exit() end up in .init.text. They are also called from serial8250_exit(), which is __exit, and modpost warns:

WARNING: modpost: vmlinux: section mismatch in reference: serial8250_exit+0x2a (section: .exit.text) -> serial8250_pnp_exit (section: .init.text)

Quoted 8 lines

The exit code never runs in such a kernel, so nothing breaks at runtime. But a function that is called from both __init and __exit code can't carry either annotation, so drop it.

Fixes a300273c458c ("serial: 8250: hub6: Add cleanup code")
Fixes 4cf187f9dea9 ("serial: 8250: pnp: Annotate init and exit functions for conditional discarding")
Assisted-by LLM

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#2 lore raw
In reply to Danish Khateeb

Hello Danish,

Quoted 6 lines · Danish Khateeb

Without CONFIG_MODULES, __init_or_module means __init, so serial8250_pnp_exit() and serial8250_hub6_exit() end up in .init.text. They are also called from serial8250_exit(), which is __exit, and modpost warns:

WARNING: modpost: vmlinux: section mismatch in reference: serial8250_exit+0x2a (section: .exit.text) -> serial8250_pnp_exit (section: .init.text)

Isn't that a false positive because with CONFIG_MODULES=n .exit is discarded and so the section mismatch doesn't matter?

Quoted 1 line

The exit code never runs in such a kernel, so nothing breaks at runtime.

Ah, you found that, too.

Quoted 2 lines

But a function that is called from both __init and __exit code can't carry either annotation, so drop it.

I thought __init_or_module was the right annotation ...

Best regards
Uwe

#3 lore raw

Hello Uwe,

Quoted 2 lines · Uwe Kleine-König

Isn't that a false positive because with CONFIG_MODULES=n .exit is discarded and so the section mismatch doesn't matter?

Yes, it's harmless at runtime, but modpost still warns on every CONFIG_MODULES=n build with SERIAL_8250_PNP (e.g. kunit.py --alltests), and the build fails with CONFIG_SECTION_MISMATCH_WARN_ONLY=n.

Quoted 1 line

I thought __init_or_module was the right annotation ...

It is, modpost just doesn't know that. Without it the two helpers stay in memory after boot, 16 bytes each on x86_64. The alternative is teaching modpost to skip exit -> init references in vmlinux when CONFIG_MODULES=n.

Thanks
Danish