From: Armin Wolf <W_Armin@gmx.de>
To: "Thomas Weißschuh" <linux@weissschuh.net>,
"Sebastian Reichel" <sre@kernel.org>,
"Hans de Goede" <hdegoede@redhat.com>,
"Thomas Weißschuh" <thomas@weissschuh.net>,
"Benson Leung" <bleung@chromium.org>,
"Guenter Roeck" <groeck@chromium.org>
Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
chrome-platform@lists.linux.dev
Subject: Re: [PATCH v4 6/9] power: supply: sysfs: rework uevent property loop
Date: Sun, 24 Nov 2024 19:00:24 +0100 [thread overview]
Message-ID: <e644ffa6-4c09-4f13-8469-da792b2f105c@gmx.de> (raw)
In-Reply-To: <20241111-power-supply-extensions-v4-6-7240144daa8e@weissschuh.net>
Am 11.11.24 um 22:40 schrieb Thomas Weißschuh:
> Instead of looping through all properties known to be supported by the
> psy, loop over all known properties and decide based on the return value
> of power_supply_get_property() whether the property existed.
>
> This makes the code shorter now and even more so when power supply
> extensions are added.
> It also simplifies the locking, as it can all happen inside
> power_supply_get_property().
Reviewed-by: Armin Wolf <W_Armin@gmx.de>
> Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
> Reviewed-by: Hans de Goede <hdegoede@redhat.com>
> ---
> drivers/power/supply/power_supply_sysfs.c | 28 +++++-----------------------
> 1 file changed, 5 insertions(+), 23 deletions(-)
>
> diff --git a/drivers/power/supply/power_supply_sysfs.c b/drivers/power/supply/power_supply_sysfs.c
> index bfe48fe01a8d03828c2e539e1e6e5e9fc5c60167..99bfe1f03eb8326d38c4e2831c9670313b42e425 100644
> --- a/drivers/power/supply/power_supply_sysfs.c
> +++ b/drivers/power/supply/power_supply_sysfs.c
> @@ -289,7 +289,7 @@ static ssize_t power_supply_format_property(struct device *dev,
> dev_dbg_ratelimited(dev,
> "driver has no data for `%s' property\n",
> attr->attr.name);
> - else if (ret != -ENODEV && ret != -EAGAIN)
> + else if (ret != -ENODEV && ret != -EAGAIN && ret != -EINVAL)
> dev_err_ratelimited(dev,
> "driver failed to report `%s' property: %zd\n",
> attr->attr.name, ret);
> @@ -441,7 +441,7 @@ static int add_prop_uevent(const struct device *dev, struct kobj_uevent_env *env
> dev_attr = &pwr_attr->dev_attr;
>
> ret = power_supply_format_property((struct device *)dev, true, dev_attr, prop_buf);
> - if (ret == -ENODEV || ret == -ENODATA) {
> + if (ret == -ENODEV || ret == -ENODATA || ret == -EINVAL) {
> /*
> * When a battery is absent, we expect -ENODEV. Don't abort;
> * send the uevent with at least the PRESENT=0 property
> @@ -462,11 +462,7 @@ static int add_prop_uevent(const struct device *dev, struct kobj_uevent_env *env
>
> int power_supply_uevent(const struct device *dev, struct kobj_uevent_env *env)
> {
> - const struct power_supply *psy = dev_get_drvdata(dev);
> - const enum power_supply_property *battery_props =
> - power_supply_battery_info_properties;
> - unsigned long psy_drv_properties[POWER_SUPPLY_ATTR_CNT /
> - sizeof(unsigned long) + 1] = {0};
> + struct power_supply *psy = dev_get_drvdata(dev);
> int ret = 0, j;
> char *prop_buf;
>
> @@ -494,22 +490,8 @@ int power_supply_uevent(const struct device *dev, struct kobj_uevent_env *env)
> if (ret)
> goto out;
>
> - for (j = 0; j < psy->desc->num_properties; j++) {
> - set_bit(psy->desc->properties[j], psy_drv_properties);
> - ret = add_prop_uevent(dev, env, psy->desc->properties[j],
> - prop_buf);
> - if (ret)
> - goto out;
> - }
> -
> - for (j = 0; j < power_supply_battery_info_properties_size; j++) {
> - if (test_bit(battery_props[j], psy_drv_properties))
> - continue;
> - if (!power_supply_battery_info_has_prop(psy->battery_info,
> - battery_props[j]))
> - continue;
> - ret = add_prop_uevent(dev, env, battery_props[j],
> - prop_buf);
> + for (j = 0; j < POWER_SUPPLY_ATTR_CNT; j++) {
> + ret = add_prop_uevent(dev, env, j, prop_buf);
> if (ret)
> goto out;
> }
>
next prev parent reply other threads:[~2024-11-24 18:00 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-11 21:40 [PATCH v4 0/9] power: supply: extension API Thomas Weißschuh
2024-11-11 21:40 ` [PATCH v4 1/9] power: supply: sysfs: print single value in uevent for POWER_SUPPLY_PROP_CHARGE_BEHAVIOUR Thomas Weißschuh
2024-11-24 17:47 ` Armin Wolf
2024-11-24 17:55 ` Thomas Weißschuh
2024-11-24 18:01 ` Armin Wolf
2024-11-11 21:40 ` [PATCH v4 2/9] power: supply: core: rename psy_has_property() to psy_desc_has_property() Thomas Weißschuh
2024-11-24 17:48 ` Armin Wolf
2024-11-11 21:40 ` [PATCH v4 3/9] power: supply: core: introduce power_supply_has_property() Thomas Weißschuh
2024-11-24 17:51 ` Armin Wolf
2024-11-11 21:40 ` [PATCH v4 4/9] power: supply: hwmon: prepare for power supply extensions Thomas Weißschuh
2024-11-24 17:53 ` Armin Wolf
2024-11-11 21:40 ` [PATCH v4 5/9] power: supply: sysfs: " Thomas Weißschuh
2024-11-24 17:57 ` Armin Wolf
2024-11-25 8:59 ` Thomas Weißschuh
2024-11-11 21:40 ` [PATCH v4 6/9] power: supply: sysfs: rework uevent property loop Thomas Weißschuh
2024-11-24 18:00 ` Armin Wolf [this message]
2024-11-11 21:40 ` [PATCH v4 7/9] power: supply: core: implement extension API Thomas Weißschuh
2024-11-24 18:15 ` Armin Wolf
2024-11-25 9:22 ` Thomas Weißschuh
2024-11-11 21:40 ` [PATCH v4 8/9] power: supply: test-power: implement a power supply extension Thomas Weißschuh
2024-11-11 21:40 ` [PATCH v4 9/9] power: supply: cros_charge-control: use power_supply extensions Thomas Weißschuh
2024-12-05 1:36 ` (subset) [PATCH v4 0/9] power: supply: extension API Sebastian Reichel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e644ffa6-4c09-4f13-8469-da792b2f105c@gmx.de \
--to=w_armin@gmx.de \
--cc=bleung@chromium.org \
--cc=chrome-platform@lists.linux.dev \
--cc=groeck@chromium.org \
--cc=hdegoede@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=linux@weissschuh.net \
--cc=sre@kernel.org \
--cc=thomas@weissschuh.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox