diff mbox series

[net] net: dqs: Do not use extern for unused dql_group

Message ID 20240902101734.3260455-1-leitao@debian.org (mailing list archive)
State Accepted
Commit 77461c10819103eaee7b33c744174b32a8c78b40
Delegated to: Netdev Maintainers
Headers show
Series [net] net: dqs: Do not use extern for unused dql_group | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 16 this patch: 16
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 5 of 5 maintainers
netdev/build_clang success Errors and warnings before: 16 this patch: 16
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 16 this patch: 16
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 8 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-09-02--12-00 (tests: 714)

Commit Message

Breno Leitao Sept. 2, 2024, 10:17 a.m. UTC
When CONFIG_DQL is not enabled, dql_group should be treated as a dead
declaration. However, its current extern declaration assumes the linker
will ignore it, which is generally true across most compiler and
architecture combinations.

But in certain cases, the linker still attempts to resolve the extern
struct, even when the associated code is dead, resulting in a linking
error. For instance the following error in loongarch64:

>> loongarch64-linux-ld: net-sysfs.c:(.text+0x589c): undefined reference to `dql_group'

Modify the declaration of the dead object to be an empty declaration
instead of an extern. This change will prevent the linker from
attempting to resolve an undefined reference.

Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202409012047.eCaOdfQJ-lkp@intel.com/
Fixes: 74293ea1c4db ("net: sysfs: Do not create sysfs for non BQL device")
Signed-off-by: Breno Leitao <leitao@debian.org>
---
 net/core/net-sysfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Simon Horman Sept. 2, 2024, 7:02 p.m. UTC | #1
On Mon, Sep 02, 2024 at 03:17:30AM -0700, Breno Leitao wrote:
> When CONFIG_DQL is not enabled, dql_group should be treated as a dead
> declaration. However, its current extern declaration assumes the linker
> will ignore it, which is generally true across most compiler and
> architecture combinations.
> 
> But in certain cases, the linker still attempts to resolve the extern
> struct, even when the associated code is dead, resulting in a linking
> error. For instance the following error in loongarch64:
> 
> >> loongarch64-linux-ld: net-sysfs.c:(.text+0x589c): undefined reference to `dql_group'
> 
> Modify the declaration of the dead object to be an empty declaration
> instead of an extern. This change will prevent the linker from
> attempting to resolve an undefined reference.
> 
> Reported-by: kernel test robot <lkp@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202409012047.eCaOdfQJ-lkp@intel.com/
> Fixes: 74293ea1c4db ("net: sysfs: Do not create sysfs for non BQL device")
> Signed-off-by: Breno Leitao <leitao@debian.org>

Thanks,

I see this with gcc-13.2.0 but, curiously, not 14.2.0.

Reviewed-by: Simon Horman <horms@kernel.org>
Tested-by: Simon Horman <horms@kernel.org> # build-tested
patchwork-bot+netdevbpf@kernel.org Sept. 3, 2024, 8:10 p.m. UTC | #2
Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Mon,  2 Sep 2024 03:17:30 -0700 you wrote:
> When CONFIG_DQL is not enabled, dql_group should be treated as a dead
> declaration. However, its current extern declaration assumes the linker
> will ignore it, which is generally true across most compiler and
> architecture combinations.
> 
> But in certain cases, the linker still attempts to resolve the extern
> struct, even when the associated code is dead, resulting in a linking
> error. For instance the following error in loongarch64:
> 
> [...]

Here is the summary with links:
  - [net] net: dqs: Do not use extern for unused dql_group
    https://git.kernel.org/netdev/net/c/77461c108191

You are awesome, thank you!
diff mbox series

Patch

diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
index 444f23e74f8e..291fdf4a328b 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -1524,7 +1524,7 @@  static const struct attribute_group dql_group = {
 };
 #else
 /* Fake declaration, all the code using it should be dead */
-extern const struct attribute_group dql_group;
+static const struct attribute_group dql_group = {};
 #endif /* CONFIG_BQL */
 
 #ifdef CONFIG_XPS