i2c/busses: fix -Wmissing-variable-declarations
PATCH 1/1 i2c/busses: fix -Wmissing-variable-declarations
I'm looking to enable -Wmissing-variable-declarations behind W=1. 0day bot spotted the following instance:
drivers/i2c/busses/i2c-amd756.c:286:20: warning: no previous extern declaration for non-static variable 'amd756_smbus' [-Wmissing-variable-declarations]
286 | struct i2c_adapter amd756_smbus = {
| ^
drivers/i2c/busses/i2c-amd756.c:286:1: note: declare 'static' if the variable is not intended to be used outside of this translation unit
286 | struct i2c_adapter amd756_smbus = {
| ^This symbol is referenced by more than one translation unit, so create then include the correct header for their declarations.
--- drivers/i2c/busses/i2c-amd756-s4882.c | 3 +-- drivers/i2c/busses/i2c-amd756.c | 1 + drivers/i2c/busses/i2c-amd756.h | 3 +++ 3 files changed, 5 insertions(+), 2 deletions(-)
drivers/i2c/busses/i2c-amd756-s4882.c +1 -2
@@ -26,8 +26,7 @@#include <linux/init.h> #include <linux/i2c.h> #include <linux/mutex.h> - -extern struct i2c_adapter amd756_smbus; +#include "i2c-amd756.h" static struct i2c_adapter *s4882_adapter;static struct i2c_algorithm *s4882_algo;
drivers/i2c/busses/i2c-amd756.c +1 -0
@@ -31,6 +31,7 @@#include <linux/i2c.h> #include <linux/acpi.h> #include <linux/io.h> +#include "i2c-amd756.h" /* AMD756 SMBus address offsets */ #define SMB_ADDR_OFFSET 0xE0
drivers/i2c/busses/i2c-amd756.h new file +3 -0
@@ -0,0 +1,3 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#include <linux/i2c.h> +extern struct i2c_adapter amd756_smbus;
---
base-commit: 14f9643dc90adea074a0ffb7a17d337eafc6a5cc
change-id: 20230808-i2c-amd_static-81e5c27a84ce
Best regards,
Signature · 1 line
Nick Desaulniers <[email protected]>
Andi Shyti
maintainerHi Nick,
Quoted 13 lines · Nick Desaulniers
I'm looking to enable -Wmissing-variable-declarations behind W=1. 0day bot spotted the following instance:
drivers/i2c/busses/i2c-amd756.c:286:20: warning: no previous extern declaration for non-static variable 'amd756_smbus' [-Wmissing-variable-declarations]
286 | structi2c_adapteramd756_smbus= {
| ^
drivers/i2c/busses/i2c-amd756.c:286:1: note: declare 'static' if the variable is not intended to be used outside of this translation unit286 | struct i2c_adapter amd756_smbus = { | ^
Quoted 6 lines
This symbol is referenced by more than one translation unit, so create then include the correct header for their declarations.
Reported-by kernel test robot <[email protected]>Signed-off-by Nick Desaulniers <[email protected]>
You might want to have a Fixes tag here and
[...]
drivers/i2c/busses/i2c-amd756.h line 1
Quoted 4 lines
drivers/i2c/busses/i2c-amd756.h new file +1
-0@@ -0,0 +1,3 @@ +/* SPDX-License-Identifier: GPL-2.0 */
Please, leave a space here.
And you might also want to have something like:
#ifndef __I2C_AMD_756_H__
#define __I2C_AMD_756_H__
drivers/i2c/busses/i2c-amd756.h line 2
Quoted 1 line
drivers/i2c/busses/i2c-amd756.h new file +1
-0+#include <linux/i2c.h>
space here.
drivers/i2c/busses/i2c-amd756.h line 3
Quoted 1 line
drivers/i2c/busses/i2c-amd756.h new file +1
-0+extern struct i2c_adapter amd756_smbus;
#endif /* __I2C_AMD_756_H__ */
Jean, any opinion on this patch, I don't really know this driver, but is there a way to avoid this extern declaration.
Thanks,
Andi
Hi Andi, Nick,
Quoted 17 lines · Andi Shyti
Quoted 16 lines · Nick Desaulniers
I'm looking to enable -Wmissing-variable-declarations behind W=1. 0day bot spotted the following instance:
drivers/i2c/busses/i2c-amd756.c:286:20: warning: no previous extern declaration for non-static variable 'amd756_smbus' [-Wmissing-variable-declarations]
286 | structi2c_adapteramd756_smbus= {
| ^
drivers/i2c/busses/i2c-amd756.c:286:1: note: declare 'static' if the variable is not intended to be used outside of this translation unit286 | struct i2c_adapter amd756_smbus = { | ^This symbol is referenced by more than one translation unit, so create then include the correct header for their declarations.
Quoted 7 lines
Quoted 3 lines
Reported-by kernel test robot <[email protected]>Signed-off-by Nick Desaulniers <[email protected]>You might want to have a Fixes tag here and
Cc Jean Delvare <[email protected]>
Fixes tag would cause unnecessary worry, with people backporting the patch while it doesn't actually fix anything. No need for that.
Quoted 17 lines
[...]
drivers/i2c/busses/i2c-amd756.h line 1
Quoted 4 lines
drivers/i2c/busses/i2c-amd756.h new file +1
-0@@ -0,0 +1,3 @@ +/* SPDX-License-Identifier: GPL-2.0 */ Please, leave a space here.
And you might also want to have something like:
#ifndef
__I2C_AMD_756_H__
#define__I2C_AMD_756_H__drivers/i2c/busses/i2c-amd756.h line 2
Quoted 1 line
drivers/i2c/busses/i2c-amd756.h new file +1
-0+#include <linux/i2c.h>
Quoted 8 lines
space here.
drivers/i2c/busses/i2c-amd756.h line 3
Quoted 1 line
drivers/i2c/busses/i2c-amd756.h new file +1
-0+extern struct i2c_adapter amd756_smbus;#endif /*
__I2C_AMD_756_H__*/Jean, any opinion on this patch, I don't really know this driver, but is there a way to avoid this extern declaration.
Thanks for your review. I would personally not bother with a header file, this is unnecessary burden. Just add the extern declaration to i2c-amd756.c as was already done in i2c-amd756-s4882.c. The whole thing is a horrible hack anyway and there won't be more occurrences of it, so the more simple it stays, the better.
Some history: I wrote the pseudo-driver i2c-amd756-s4882 when the i2c-core did not yet support multiplexing. Nowadays, proper support would be implemented using i2c-mux-* and i2c-amd756-s4882.c would go away entirely. Actually, I very much doubt any of these 2007 Tyan server boards is still in activity today, so maybe we should just delete the driver.
Note that i2c-nforce2.c will need the same fix as struct i2c_adapter nforce2_smbus is extern as well.
Signature · 2 lines
Jean Delvare SUSE L3 Support