Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

power: supply: core: introduce power_supply_has_property()

Introduce a helper to check if a power supply implements a certain
property. It will be used by the sysfs and hwmon code to remove similar
open-coded checks.
It also paves the way for the extension API to hook into.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Reviewed-by: Armin Wolf <W_Armin@gmx.de>
Link: https://lore.kernel.org/r/20241111-power-supply-extensions-v4-3-7240144daa8e@weissschuh.net
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>

authored by

Thomas Weißschuh and committed by
Sebastian Reichel
aa40f37d 172f2151

+14
+2
drivers/power/supply/power_supply.h
··· 15 15 16 16 extern int power_supply_property_is_writeable(struct power_supply *psy, 17 17 enum power_supply_property psp); 18 + extern bool power_supply_has_property(struct power_supply *psy, 19 + enum power_supply_property psp); 18 20 19 21 #ifdef CONFIG_SYSFS 20 22
+12
drivers/power/supply/power_supply_core.c
··· 1196 1196 return found; 1197 1197 } 1198 1198 1199 + bool power_supply_has_property(struct power_supply *psy, 1200 + enum power_supply_property psp) 1201 + { 1202 + if (psy_desc_has_property(psy->desc, psp)) 1203 + return true; 1204 + 1205 + if (power_supply_battery_info_has_prop(psy->battery_info, psp)) 1206 + return true; 1207 + 1208 + return false; 1209 + } 1210 + 1199 1211 int power_supply_get_property(struct power_supply *psy, 1200 1212 enum power_supply_property psp, 1201 1213 union power_supply_propval *val)