From: "Thomas Weißschuh" <linux@weissschuh.net>
To: Sebastian Reichel <sre@kernel.org>, Armin Wolf <W_Armin@gmx.de>,
Hans de Goede <hdegoede@redhat.com>,
Benson Leung <bleung@chromium.org>,
Guenter Roeck <groeck@chromium.org>
Cc: linux-kernel@vger.kernel.org, chrome-platform@lists.linux.dev,
linux-pm@vger.kernel.org
Subject: Re: [PATCH v6 4/4] power: supply: core: add UAPI to discover currently used extensions
Date: Sat, 14 Dec 2024 08:53:10 +0100 [thread overview]
Message-ID: <12c775fd-0adc-4dca-aac8-91b353e4f01f@t-8ch.de> (raw)
In-Reply-To: <20241211-power-supply-extensions-v6-4-9d9dc3f3d387@weissschuh.net>
On 2024-12-11 20:57:58+0100, Thomas Weißschuh wrote:
> Userspace wants to now about the used power supply extensions,
> for example to handle a device extended by a certain extension
> differently or to discover information about the extending device.
>
> Add a sysfs directory to the power supply device.
> This directory contains links which are named after the used extension
> and point to the device implementing that extension.
>
> Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
> ---
> Documentation/ABI/testing/sysfs-class-power | 9 +++++++++
> drivers/power/supply/cros_charge-control.c | 5 ++++-
> drivers/power/supply/power_supply.h | 2 ++
> drivers/power/supply/power_supply_core.c | 19 +++++++++++++++++--
> drivers/power/supply/power_supply_sysfs.c | 10 ++++++++++
> drivers/power/supply/test_power.c | 4 +++-
> include/linux/power_supply.h | 2 ++
> 7 files changed, 47 insertions(+), 4 deletions(-)
[..]
> --- a/drivers/power/supply/power_supply_core.c
> +++ b/drivers/power/supply/power_supply_core.c
> @@ -1346,17 +1346,21 @@ static int power_supply_update_sysfs_and_hwmon(struct power_supply *psy)
> }
>
> int power_supply_register_extension(struct power_supply *psy, const struct power_supply_ext *ext,
> - void *data)
> + struct device *dev, void *data)
> {
> struct power_supply_ext_registration *reg;
> size_t i;
> int ret;
>
> - if (!psy || !ext || !ext->properties || !ext->num_properties)
> + if (!psy || !dev || !ext || !ext->name || !ext->properties || !ext->num_properties)
> return -EINVAL;
>
> guard(rwsem_write)(&psy->extensions_sem);
>
> + power_supply_for_each_extension(reg, psy)
> + if (strcmp(ext->name, reg->ext->name) == 0)
> + return -EEXIST;
> +
> for (i = 0; i < ext->num_properties; i++)
> if (power_supply_has_property(psy, ext->properties[i]))
> return -EEXIST;
> @@ -1366,9 +1370,15 @@ int power_supply_register_extension(struct power_supply *psy, const struct power
> return -ENOMEM;
>
> reg->ext = ext;
> + reg->dev = dev;
> reg->data = data;
> list_add(®->list_head, &psy->extensions);
>
> + ret = sysfs_add_link_to_group(&psy->dev.kobj, power_supply_extension_group.name,
> + &dev->kobj, ext->name);
> + if (ret)
> + goto sysfs_link_failed;
> +
> ret = power_supply_update_sysfs_and_hwmon(psy);
> if (ret)
> goto sysfs_hwmon_failed;
> @@ -1376,6 +1386,8 @@ int power_supply_register_extension(struct power_supply *psy, const struct power
> return 0;
>
> sysfs_hwmon_failed:
> + sysfs_remove_link_from_group(&psy->dev.kobj, power_supply_extension_group.name, ext->name);
> +sysfs_link_failed:
> list_del(®->list_head);
> kfree(reg);
> return ret;
> @@ -1392,6 +1404,9 @@ void power_supply_unregister_extension(struct power_supply *psy, const struct po
> if (reg->ext == ext) {
> list_del(®->list_head);
> kfree(reg);
> + sysfs_remove_link_from_group(&psy->dev.kobj,
> + power_supply_extension_group.name,
> + reg->ext->name);
Dan Carpenter's sparse bot detected a use after free here.
Could you move the call to sysfs_remove_link_from_group() before the
kfree() when applying?
(Or switch reg->ext->name to ext->name)
> power_supply_update_sysfs_and_hwmon(psy);
> return;
> }
[..]
Thanks,
Thomas
next prev parent reply other threads:[~2024-12-14 7:53 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-11 19:57 [PATCH v6 0/4] power: supply: extension API Thomas Weißschuh
2024-12-11 19:57 ` [PATCH v6 1/4] power: supply: core: implement " Thomas Weißschuh
2024-12-13 22:48 ` Armin Wolf
2024-12-11 19:57 ` [PATCH v6 2/4] power: supply: test-power: implement a power supply extension Thomas Weißschuh
2024-12-11 19:57 ` [PATCH v6 3/4] power: supply: cros_charge-control: " Thomas Weißschuh
2024-12-11 19:57 ` [PATCH v6 4/4] power: supply: core: add UAPI to discover currently used extensions Thomas Weißschuh
2024-12-13 22:50 ` Armin Wolf
2024-12-14 7:53 ` Thomas Weißschuh [this message]
2024-12-18 19:52 ` Nathan Chancellor
2024-12-18 20:29 ` Thomas Weißschuh
2024-12-18 22:11 ` Sebastian Reichel
2024-12-18 22:16 ` Thomas Weißschuh
2024-12-18 22:46 ` Sebastian Reichel
2024-12-12 14:27 ` [PATCH v6 0/4] power: supply: extension API Armin Wolf
2024-12-13 21:00 ` Thomas Weißschuh
2024-12-14 3:26 ` (subset) " Sebastian Reichel
2024-12-14 22:04 ` 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=12c775fd-0adc-4dca-aac8-91b353e4f01f@t-8ch.de \
--to=linux@weissschuh.net \
--cc=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=sre@kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.