Skip to contentSkip to conversation

samples/hw_breakpoint: fix building without module unloading

PATCH In review Arnd Bergmann 3 participants 3 messages Jul 25, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 samples/hw_breakpoint: fix building without module unloading

From: Arnd Bergmann <[email protected]>

__symbol_put() is really meant as an internal helper and is not available when module unloading is disabled, unlike the previously used symbol_put():

samples/hw_breakpoint/data_breakpoint.c: In function 'hw_break_module_exit':
samples/hw_breakpoint/data_breakpoint.c:73:9: error: implicit declaration of function '__symbol_put'; did you mean '__symbol_get'? [-Werror=implicit-function-declaration]

The hw_break_module_exit() function is not actually used when module unloading is disabled, but it still causes the build failure for an undefined identifier. Enclose this one call in an appropriate #ifdef to clarify what the requirement is. Leaving out the entire exit function would also work but feels less clar in this case.

Fixes 910e230d5f1bb ("samples/hw_breakpoint: Fix kernel BUG 'invalid opcode: 0000'")
Fixes d8a84d33a4954 ("samples/hw_breakpoint: drop use of kallsyms_lookup_name()")
---
 samples/hw_breakpoint/data_breakpoint.c | 2 ++
 1 file changed, 2 insertions(+)
samples/hw_breakpoint/data_breakpoint.c +2 -0
index 9debd128b2ab8..b99322f188e59 100644
@@ -70,7 +70,9 @@ static int __init hw_break_module_init(void)
 static void __exit hw_break_module_exit(void)
 {
 	unregister_wide_hw_breakpoint(sample_hbp);
+#ifdef CONFIG_MODULE_UNLOAD
 	__symbol_put(ksym_name);
+#endif
 	printk(KERN_INFO "HW Breakpoint for %s write uninstalled\n", ksym_name);
 }
 
Signature · 1 line
2.39.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

__symbol_put() is really meant as an internal helper and is not available when module unloading is disabled, unlike the previously used symbol_put():

Ah, I have missed this.

Quoted 12 lines

samples/hw_breakpoint/data_breakpoint.c: In function 'hw_break_module_exit':
samples/hw_breakpoint/data_breakpoint.c:73:9: error: implicit declaration of function '__symbol_put'; did you mean '__symbol_get'? [-Werror=implicit-function-declaration]

The hw_break_module_exit() function is not actually used when module unloading is disabled, but it still causes the build failure for an undefined identifier. Enclose this one call in an appropriate #ifdef to clarify what the requirement is. Leaving out the entire exit function would also work but feels less clar in this case.

samples/hw_breakpoint/data_breakpoint.c static int __init hw_break_module_init(void) · line 77

Quoted 8 lines
samples/hw_breakpoint/data_breakpoint.c +2 -0
@@ -70,7 +70,9 @@ static int __init hw_break_module_init(void)
 static void __exit hw_break_module_exit(void)
 {
 	unregister_wide_hw_breakpoint(sample_hbp);
+#ifdef CONFIG_MODULE_UNLOAD
 	__symbol_put(ksym_name);
+#endif
 	printk(KERN_INFO "HW Breakpoint for %s write uninstalled\n", ksym_name);
 }

I see that both symbol_put() and symbol_put_addr() are defined as noops twice:

+ when !defined(CONFIG_MODULE_UNLOAD)
+ when !defined(CONFIG_MODULES)

This patch is enough because samples/hw_breakpoint/data_breakpoint.c could be built only as a module, so feel free to use:

But even better solution would be to define symbol_put_name() as a noop in both situations and use it.

Best Regards,
Petr

#2 lore raw
Quoted 1 line · Petr Mladek

Thanks, patch applied and pushed!

Quoted 2 lines

But even better solution would be to define symbol_put_name() as a noop in both situations and use it.

Patch welcomed!

Luis