[PATCH v4 5/9] power: supply: sysfs: prepare for power supply extensions

Thomas Weißschuh posted 9 patches 1 year, 2 months ago
There is a newer version of this series
[PATCH v4 5/9] power: supply: sysfs: prepare for power supply extensions
Posted by Thomas Weißschuh 1 year, 2 months ago
The upcoming extension API will add properties which are not part of the
the power_supply_desc.
Use power_supply_has_property() so the properties from extensions are
also checked.

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>
---
 drivers/power/supply/power_supply_sysfs.c | 17 ++++-------------
 1 file changed, 4 insertions(+), 13 deletions(-)

diff --git a/drivers/power/supply/power_supply_sysfs.c b/drivers/power/supply/power_supply_sysfs.c
index a7351b9c8fe34a464a4e69b1a1a4a4179c1a4b4f..bfe48fe01a8d03828c2e539e1e6e5e9fc5c60167 100644
--- a/drivers/power/supply/power_supply_sysfs.c
+++ b/drivers/power/supply/power_supply_sysfs.c
@@ -378,7 +378,6 @@ static umode_t power_supply_attr_is_visible(struct kobject *kobj,
 	struct device *dev = kobj_to_dev(kobj);
 	struct power_supply *psy = dev_get_drvdata(dev);
 	umode_t mode = S_IRUSR | S_IRGRP | S_IROTH;
-	int i;
 
 	if (!power_supply_attrs[attrno].prop_name)
 		return 0;
@@ -386,19 +385,11 @@ static umode_t power_supply_attr_is_visible(struct kobject *kobj,
 	if (attrno == POWER_SUPPLY_PROP_TYPE)
 		return mode;
 
-	for (i = 0; i < psy->desc->num_properties; i++) {
-		int property = psy->desc->properties[i];
-
-		if (property == attrno) {
-			if (power_supply_property_is_writeable(psy, property) > 0)
-				mode |= S_IWUSR;
-
-			return mode;
-		}
-	}
-
-	if (power_supply_battery_info_has_prop(psy->battery_info, attrno))
+	if (power_supply_has_property(psy, attrno)) {
+		if (power_supply_property_is_writeable(psy, attrno) > 0)
+			mode |= S_IWUSR;
 		return mode;
+	}
 
 	return 0;
 }

-- 
2.47.0

Re: [PATCH v4 5/9] power: supply: sysfs: prepare for power supply extensions
Posted by Armin Wolf 1 year, 2 months ago
Am 11.11.24 um 22:40 schrieb Thomas Weißschuh:

> The upcoming extension API will add properties which are not part of the
> the power_supply_desc.
> Use power_supply_has_property() so the properties from extensions are
> also checked.
>
> 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>
> ---
>   drivers/power/supply/power_supply_sysfs.c | 17 ++++-------------
>   1 file changed, 4 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/power/supply/power_supply_sysfs.c b/drivers/power/supply/power_supply_sysfs.c
> index a7351b9c8fe34a464a4e69b1a1a4a4179c1a4b4f..bfe48fe01a8d03828c2e539e1e6e5e9fc5c60167 100644
> --- a/drivers/power/supply/power_supply_sysfs.c
> +++ b/drivers/power/supply/power_supply_sysfs.c
> @@ -378,7 +378,6 @@ static umode_t power_supply_attr_is_visible(struct kobject *kobj,
>   	struct device *dev = kobj_to_dev(kobj);
>   	struct power_supply *psy = dev_get_drvdata(dev);
>   	umode_t mode = S_IRUSR | S_IRGRP | S_IROTH;
> -	int i;
>
>   	if (!power_supply_attrs[attrno].prop_name)
>   		return 0;
> @@ -386,19 +385,11 @@ static umode_t power_supply_attr_is_visible(struct kobject *kobj,
>   	if (attrno == POWER_SUPPLY_PROP_TYPE)
>   		return mode;
>
> -	for (i = 0; i < psy->desc->num_properties; i++) {
> -		int property = psy->desc->properties[i];
> -
> -		if (property == attrno) {
> -			if (power_supply_property_is_writeable(psy, property) > 0)
> -				mode |= S_IWUSR;
> -
> -			return mode;
> -		}
> -	}
> -
> -	if (power_supply_battery_info_has_prop(psy->battery_info, attrno))
> +	if (power_supply_has_property(psy, attrno)) {
> +		if (power_supply_property_is_writeable(psy, attrno) > 0)

What happens with properties supplied via battery_info? Are drivers expecting the power supply core
to call property_is_writable() for those too?

Thanks,
Armin Wolf

> +			mode |= S_IWUSR;
>   		return mode;
> +	}
>
>   	return 0;
>   }
>
Re: [PATCH v4 5/9] power: supply: sysfs: prepare for power supply extensions
Posted by Thomas Weißschuh 1 year, 2 months ago
On 2024-11-24 18:57:23+0100, Armin Wolf wrote:
> Am 11.11.24 um 22:40 schrieb Thomas Weißschuh:
> 
> > The upcoming extension API will add properties which are not part of the
> > the power_supply_desc.
> > Use power_supply_has_property() so the properties from extensions are
> > also checked.
> > 
> > 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>
> > ---
> >   drivers/power/supply/power_supply_sysfs.c | 17 ++++-------------
> >   1 file changed, 4 insertions(+), 13 deletions(-)
> > 
> > diff --git a/drivers/power/supply/power_supply_sysfs.c b/drivers/power/supply/power_supply_sysfs.c
> > index a7351b9c8fe34a464a4e69b1a1a4a4179c1a4b4f..bfe48fe01a8d03828c2e539e1e6e5e9fc5c60167 100644
> > --- a/drivers/power/supply/power_supply_sysfs.c
> > +++ b/drivers/power/supply/power_supply_sysfs.c
> > @@ -378,7 +378,6 @@ static umode_t power_supply_attr_is_visible(struct kobject *kobj,
> >   	struct device *dev = kobj_to_dev(kobj);
> >   	struct power_supply *psy = dev_get_drvdata(dev);
> >   	umode_t mode = S_IRUSR | S_IRGRP | S_IROTH;
> > -	int i;
> > 
> >   	if (!power_supply_attrs[attrno].prop_name)
> >   		return 0;
> > @@ -386,19 +385,11 @@ static umode_t power_supply_attr_is_visible(struct kobject *kobj,
> >   	if (attrno == POWER_SUPPLY_PROP_TYPE)
> >   		return mode;
> > 
> > -	for (i = 0; i < psy->desc->num_properties; i++) {
> > -		int property = psy->desc->properties[i];
> > -
> > -		if (property == attrno) {
> > -			if (power_supply_property_is_writeable(psy, property) > 0)
> > -				mode |= S_IWUSR;
> > -
> > -			return mode;
> > -		}
> > -	}
> > -
> > -	if (power_supply_battery_info_has_prop(psy->battery_info, attrno))
> > +	if (power_supply_has_property(psy, attrno)) {
> > +		if (power_supply_property_is_writeable(psy, attrno) > 0)
> 
> What happens with properties supplied via battery_info? Are drivers expecting the power supply core
> to call property_is_writable() for those too?

I don't think this should be an issue.
But we could also modify power_supply_property_is_writeable() and handle
battery info properties there, they are never writable.

Maybe we could even replace the whole battery_info logic itself with a
powersupply extension.

> Thanks,
> Armin Wolf
> 
> > +			mode |= S_IWUSR;
> >   		return mode;
> > +	}
> > 
> >   	return 0;
> >   }
> >