Re: [PATCH RFC v3 4/9] power: supply: sysfs: register battery properties
From: Sebastian Reichel
Date: Sat Sep 14 2024 - 05:43:42 EST
Hi,
On Wed, Sep 04, 2024 at 09:25:37PM GMT, Thomas Weißschuh wrote:
> Instead of only registering properties from the psy_desc itself,
> also register the ones from the battery.
> Use power_supply_has_property() for this test which makes the logic also
> easier to read.
>
> Signed-off-by: Thomas Weißschuh <linux@xxxxxxxxxxxxxx>
> ---
The properties from the battery_info are already registered, so this
"just" simplifies the logic. Otherwise LGTM.
Greetings,
-- Sebastian
> 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 3e63d165b2f7..4ab08386bcb7 100644
> --- a/drivers/power/supply/power_supply_sysfs.c
> +++ b/drivers/power/supply/power_supply_sysfs.c
> @@ -367,7 +367,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;
> @@ -375,19 +374,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.46.0
>
>
Attachment:
signature.asc
Description: PGP signature