mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
synced 2025-01-17 05:45:20 +00:00
power: supply: core: fix build of extension sysfs group if CONFIG_SYSFS=n
Add and use wrapper functions for the sysfs interaction. Restore the compatibility of CONFIG_POWER_SUPPLY=y and CONFIG_SYSFS=n. Reported-by: Nathan Chancellor <nathan@kernel.org> Closes: https://lore.kernel.org/lkml/20241218195229.GA2796534@ax162/ Fixes: 288a2cabcf6b ("power: supply: core: add UAPI to discover currently used extensions") Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> Link: https://lore.kernel.org/r/20241219-psy-extensions-sysfs-v1-1-868fc6cb46d6@weissschuh.net Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
This commit is contained in:
parent
5972da73f7
commit
21096800c5
@ -40,14 +40,24 @@ struct power_supply_ext_registration {
|
|||||||
|
|
||||||
extern void __init power_supply_init_attrs(void);
|
extern void __init power_supply_init_attrs(void);
|
||||||
extern int power_supply_uevent(const struct device *dev, struct kobj_uevent_env *env);
|
extern int power_supply_uevent(const struct device *dev, struct kobj_uevent_env *env);
|
||||||
extern const struct attribute_group power_supply_extension_group;
|
|
||||||
extern const struct attribute_group *power_supply_attr_groups[];
|
extern const struct attribute_group *power_supply_attr_groups[];
|
||||||
|
extern int power_supply_sysfs_add_extension(struct power_supply *psy,
|
||||||
|
const struct power_supply_ext *ext,
|
||||||
|
struct device *dev);
|
||||||
|
extern void power_supply_sysfs_remove_extension(struct power_supply *psy,
|
||||||
|
const struct power_supply_ext *ext);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
static inline void power_supply_init_attrs(void) {}
|
static inline void power_supply_init_attrs(void) {}
|
||||||
#define power_supply_attr_groups NULL
|
#define power_supply_attr_groups NULL
|
||||||
#define power_supply_uevent NULL
|
#define power_supply_uevent NULL
|
||||||
|
static inline int power_supply_sysfs_add_extension(struct power_supply *psy,
|
||||||
|
const struct power_supply_ext *ext,
|
||||||
|
struct device *dev)
|
||||||
|
{ return 0; }
|
||||||
|
static inline void power_supply_sysfs_remove_extension(struct power_supply *psy,
|
||||||
|
const struct power_supply_ext *ext) {}
|
||||||
|
|
||||||
#endif /* CONFIG_SYSFS */
|
#endif /* CONFIG_SYSFS */
|
||||||
|
|
||||||
|
@ -1386,10 +1386,9 @@ int power_supply_register_extension(struct power_supply *psy, const struct power
|
|||||||
reg->data = data;
|
reg->data = data;
|
||||||
list_add(®->list_head, &psy->extensions);
|
list_add(®->list_head, &psy->extensions);
|
||||||
|
|
||||||
ret = sysfs_add_link_to_group(&psy->dev.kobj, power_supply_extension_group.name,
|
ret = power_supply_sysfs_add_extension(psy, ext, dev);
|
||||||
&dev->kobj, ext->name);
|
|
||||||
if (ret)
|
if (ret)
|
||||||
goto sysfs_link_failed;
|
goto sysfs_add_failed;
|
||||||
|
|
||||||
ret = power_supply_update_sysfs_and_hwmon(psy);
|
ret = power_supply_update_sysfs_and_hwmon(psy);
|
||||||
if (ret)
|
if (ret)
|
||||||
@ -1398,8 +1397,8 @@ int power_supply_register_extension(struct power_supply *psy, const struct power
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
sysfs_hwmon_failed:
|
sysfs_hwmon_failed:
|
||||||
sysfs_remove_link_from_group(&psy->dev.kobj, power_supply_extension_group.name, ext->name);
|
power_supply_sysfs_remove_extension(psy, ext);
|
||||||
sysfs_link_failed:
|
sysfs_add_failed:
|
||||||
list_del(®->list_head);
|
list_del(®->list_head);
|
||||||
kfree(reg);
|
kfree(reg);
|
||||||
return ret;
|
return ret;
|
||||||
@ -1415,9 +1414,7 @@ void power_supply_unregister_extension(struct power_supply *psy, const struct po
|
|||||||
power_supply_for_each_extension(reg, psy) {
|
power_supply_for_each_extension(reg, psy) {
|
||||||
if (reg->ext == ext) {
|
if (reg->ext == ext) {
|
||||||
list_del(®->list_head);
|
list_del(®->list_head);
|
||||||
sysfs_remove_link_from_group(&psy->dev.kobj,
|
power_supply_sysfs_remove_extension(psy, ext);
|
||||||
power_supply_extension_group.name,
|
|
||||||
reg->ext->name);
|
|
||||||
kfree(reg);
|
kfree(reg);
|
||||||
power_supply_update_sysfs_and_hwmon(psy);
|
power_supply_update_sysfs_and_hwmon(psy);
|
||||||
return;
|
return;
|
||||||
|
@ -462,7 +462,7 @@ static struct attribute *power_supply_extension_attrs[] = {
|
|||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct attribute_group power_supply_extension_group = {
|
static const struct attribute_group power_supply_extension_group = {
|
||||||
.name = "extensions",
|
.name = "extensions",
|
||||||
.attrs = power_supply_extension_attrs,
|
.attrs = power_supply_extension_attrs,
|
||||||
};
|
};
|
||||||
@ -624,3 +624,16 @@ int power_supply_charge_types_parse(unsigned int available_types, const char *bu
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(power_supply_charge_types_parse);
|
EXPORT_SYMBOL_GPL(power_supply_charge_types_parse);
|
||||||
|
|
||||||
|
int power_supply_sysfs_add_extension(struct power_supply *psy, const struct power_supply_ext *ext,
|
||||||
|
struct device *dev)
|
||||||
|
{
|
||||||
|
return sysfs_add_link_to_group(&psy->dev.kobj, power_supply_extension_group.name,
|
||||||
|
&dev->kobj, ext->name);
|
||||||
|
}
|
||||||
|
|
||||||
|
void power_supply_sysfs_remove_extension(struct power_supply *psy,
|
||||||
|
const struct power_supply_ext *ext)
|
||||||
|
{
|
||||||
|
sysfs_remove_link_from_group(&psy->dev.kobj, power_supply_extension_group.name, ext->name);
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user