power: supply: core: move power_supply_attr_group into #ifdef block
authorRicardo B. Marliere <ricardo@marliere.net>
Wed, 28 Feb 2024 13:46:28 +0000 (10:46 -0300)
committerSebastian Reichel <sebastian.reichel@collabora.com>
Wed, 28 Feb 2024 22:04:25 +0000 (23:04 +0100)
When building with CONFIG_SYSFS=n, the build error below is triggered:

ld: drivers/power/supply/power_supply_core.o:(.data+0x0): undefined
reference to `power_supply_attr_group'

The problem is that power_supply_attr_group is needed in
power_supply_core.c but defined in power_supply_sysfs.c, which is only
targeted with CONFIG_SYSFS=y. Therefore, move the extern declaration into
the #ifdef block that checks for CONFIG_SYSFS, and define an empty static
const struct otherwise. This is safe because the macro __ATRIBUTE_GROUPS in
power_supply_core.c will expand into an empty attribute_group array.

Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reported-by: Nathan Chancellor <nathan@kernel.org>
Link: https://lore.kernel.org/all/20240227214916.GA3699076@dev-arch.thelio-3990X/
Fixes: 7b46b60944d7 ("power: supply: core: constify the struct device_type usage")
Signed-off-by: Ricardo B. Marliere <ricardo@marliere.net>
Tested-by: Nathan Chancellor <nathan@kernel.org> # build
Link: https://lore.kernel.org/r/20240228-device_cleanup-power-v1-1-52c0321c48e1@marliere.net
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
drivers/power/supply/power_supply.h

index 7d05756398b92727638d4d8c090debec2328aa83..06749a534db4bca2b9127105e393c4d47c85a307 100644 (file)
@@ -13,16 +13,16 @@ struct device;
 struct device_type;
 struct power_supply;
 
-extern const struct attribute_group power_supply_attr_group;
-
 #ifdef CONFIG_SYSFS
 
 extern void power_supply_init_attrs(void);
 extern int power_supply_uevent(const struct device *dev, struct kobj_uevent_env *env);
+extern const struct attribute_group power_supply_attr_group;
 
 #else
 
 static inline void power_supply_init_attrs(void) {}
+static const struct attribute_group power_supply_attr_group;
 #define power_supply_uevent NULL
 
 #endif /* CONFIG_SYSFS */