power: supply: core: Fix a build failure due to psy_has_property() definition location
PATCH 1/1 power: supply: core: Fix a build failure due to psy_has_property() definition location
Commit 9ba533eb99bb ("power: supply: core: Add psy_has_property()") in -next tree defines 'psy_has_property()' when 'CONFIG_THERMAL' is set. But, it is also called from '__power_supply_register()', which is defined even if 'CONFIG_THERMAL' is unset. As a result, the build fails when 'CONFIG_THERMAL' is undefined as below.
.../drivers/power/supply/power_supply_core.c: In function '__power_supply_register':
.../drivers/power/supply/power_supply_core.c:1137:6: error: implicit declaration of function 'psy_has_property' [-Werror=implicit-function-declaration]
1137 | if (psy_has_property(desc, POWER_SUPPLY_PROP_USB_TYPE) &&
| ^~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors
.../scripts/Makefile.build:288: recipe for target 'drivers/power/supply/power_supply_core.o' failed
make[4]: *** [drivers/power/supply/power_supply_core.o] Error 1
This commit fixes the issue by moving the definition out of the '#ifdef' block.
--- drivers/power/supply/power_supply_core.c | 32 ++++++++++++------------ 1 file changed, 16 insertions(+), 16 deletions(-)
drivers/power/supply/power_supply_core.c +16 -16
@@ -951,6 +951,22 @@ void power_supply_unreg_notifier(struct notifier_block *nb) }EXPORT_SYMBOL_GPL (power_supply_unreg_notifier); +static bool psy_has_property (const struct power_supply_desc *psy_desc, +enum power_supply_property psp) +{ +bool found = false; +int i; + +for (i =0 ; i < psy_desc->num_properties; i++) { +if (psy_desc->properties[i] == psp) { + found = true; +break ; + } + } + +return found; +} +#ifdef CONFIG_THERMAL static int power_supply_read_temp (struct thermal_zone_device *tzd,int *temp)
@@ -975,22 +991,6 @@ static struct thermal_zone_device_ops psy_tzd_ops = { .get_temp = power_supply_read_temp, }; -static bool psy_has_property (const struct power_supply_desc *psy_desc, -enum power_supply_property psp) -{ -bool found = false; -int i; - -for (i =0 ; i < psy_desc->num_properties; i++) { -if (psy_desc->properties[i] == psp) { - found = true; -break ; - } - } - -return found; -} -static int psy_register_thermal (struct power_supply *psy) {int ret;
Signature · 1 line
2.17.1
Hi SeongJae,
thanks for the fix!
Geert sent a similar patch earlier:
Quoted 74 lines · SeongJae Park
Commit
9ba533eb99bb("power: supply: core: Addpsy_has_property()") in -next tree defines 'psy_has_property()' when 'CONFIG_THERMAL' is set. But, it is also called from '__power_supply_register()', which is defined even if 'CONFIG_THERMAL' is unset. As a result, the build fails when 'CONFIG_THERMAL' is undefined as below.
.../drivers/power/supply/power_supply_core.c: In function '__power_supply_register':
.../drivers/power/supply/power_supply_core.c:1137:6: error: implicit declaration of function 'psy_has_property' [-Werror=implicit-function-declaration]
1137 | if (psy_has_property(desc, POWER_SUPPLY_PROP_USB_TYPE)&&
| ^~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors
.../scripts/Makefile.build:288: recipe for target 'drivers/power/supply/power_supply_core.o' failed
make[4]: *** [drivers/power/supply/power_supply_core.o] Error 1This commit fixes the issue by moving the definition out of the '#ifdef' block.
Signed-off-by SeongJae Park <[email protected]>--- drivers/power/supply/power_supply_core.c | 32 ++++++++++++------------ 1 file changed, 16 insertions(+), 16 deletions(-)drivers/power/supply/power_supply_core.c +16
-16@@ -951,6 +951,22 @@ void power_supply_unreg_notifier(struct notifier_block *nb) }EXPORT_SYMBOL_GPL (power_supply_unreg_notifier); +static bool psy_has_property (const struct power_supply_desc *psy_desc, +enum power_supply_property psp) +{ +bool found = false; +int i; + +for (i =0 ; i < psy_desc->num_properties; i++) { +if (psy_desc->properties[i] == psp) { + found = true; +break ; + } + } + +return found; +} +#ifdef CONFIG_THERMAL static int power_supply_read_temp (struct thermal_zone_device *tzd,int *temp)@@ -975,22 +991,6 @@ static struct thermal_zone_device_ops psy_tzd_ops = { .get_temp = power_supply_read_temp, }; -static bool psy_has_property (const struct power_supply_desc *psy_desc, -enum power_supply_property psp) -{ -bool found = false; -int i; - -for (i =0 ; i < psy_desc->num_properties; i++) { -if (psy_desc->properties[i] == psp) { - found = true; -break ; - } - } - -return found; -} -static int psy_register_thermal (struct power_supply *psy) {int ret;Signature · 1 line
2.17.1
Quoted 7 lines · On Wed, 29 Sep 2021 09:05:40 -0700 Matthias Kaehlcke <[email protected]> wrote:
Hi SeongJae,
thanks for the fix!
Geert sent a similar patch earlier:
No problem, good to hear that!
Thanks,
SJ
[...]