All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Thomas Weißschuh" <linux@weissschuh.net>
To: Nathan Chancellor <nathan@kernel.org>,
	 Sebastian Reichel <sre@kernel.org>
Cc: Armin Wolf <W_Armin@gmx.de>, Hans de Goede <hdegoede@redhat.com>,
	 Benson Leung <bleung@chromium.org>,
	Guenter Roeck <groeck@chromium.org>,
	 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: Wed, 18 Dec 2024 21:29:31 +0100	[thread overview]
Message-ID: <eb265cb2-b079-4bca-bc35-17a9f4d0ec3e@t-8ch.de> (raw)
In-Reply-To: <20241218195229.GA2796534@ax162>

Hi Nathan,

On 2024-12-18 12:52:29-0700, Nathan Chancellor wrote:
> On Wed, Dec 11, 2024 at 08:57:58PM +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(-)
> ...
> > diff --git a/drivers/power/supply/power_supply.h b/drivers/power/supply/power_supply.h
> > index 531785516d2ac31f9a7f73a58e15e64cb81820ed..9ed749cd09369f0f13017847687509736b30aae8 100644
> > --- a/drivers/power/supply/power_supply.h
> > +++ b/drivers/power/supply/power_supply.h
> > @@ -39,6 +40,7 @@ struct power_supply_ext_registration {
> >  
> >  extern void __init power_supply_init_attrs(void);
> >  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[];
> >  
> >  #else
> > diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c
> > index bc22edbd0e6a02c27500132075f5c98d814a7330..5142fbd580ee3d629a2aae7d0b9bcd5709162129 100644
> > --- 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(&reg->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(&reg->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(&reg->list_head);
> >  			kfree(reg);
> > +			sysfs_remove_link_from_group(&psy->dev.kobj,
> > +						     power_supply_extension_group.name,
> > +						     reg->ext->name);
> >  			power_supply_update_sysfs_and_hwmon(psy);
> >  			return;
> >  		}
> 
> I am seeing a build failure in certain configurations because
> power_supply_extension_group is only declared under a CONFIG_SYSFS ifdef
> but this code can be built without CONFIG_SYSFS.

Thanks for the report.

>   $ echo 'CONFIG_EXPERT=y
>   CONFIG_SYSFS=n' >allno.config
> 
>   $ make -skj"$(nproc)" ARCH=arm64 CROSS_COMPILE=aarch64-linux- KCONFIG_ALLCONFIG=1 mrproper allnoconfig drivers/power/supply/power_supply_core.o
>   drivers/power/supply/power_supply_core.c: In function 'power_supply_register_extension':
>   drivers/power/supply/power_supply_core.c:1389:55: error: 'power_supply_extension_group' undeclared (first use in this function); did you mean 'power_supply_attr_groups'?
>    1389 |         ret = sysfs_add_link_to_group(&psy->dev.kobj, power_supply_extension_group.name,
>         |                                                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
>         |                                                       power_supply_attr_groups
>   drivers/power/supply/power_supply_core.c:1389:55: note: each undeclared identifier is reported only once for each function it appears in
>   drivers/power/supply/power_supply_core.c: In function 'power_supply_unregister_extension':
>   drivers/power/supply/power_supply_core.c:1419:54: error: 'power_supply_extension_group' undeclared (first use in this function); did you mean 'power_supply_attr_groups'?
>    1419 |                                                      power_supply_extension_group.name,
>         |                                                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
>         |                                                      power_supply_attr_groups

The reproducer doesn't actually enable CONFIG_POWER_SUPPLY, when I use it
I get a whole array of errors.

> Should the declaration be moved out from the ifdef or is there some
> other solution I am not seeing?

This, inline constants or a #define.

Sebastian, do you want me to send a patch?

> Cheers,
> Nathan
> 
> diff --git a/drivers/power/supply/power_supply.h b/drivers/power/supply/power_supply.h
> index 9ed749cd0936..6fc9939145fc 100644
> --- a/drivers/power/supply/power_supply.h
> +++ b/drivers/power/supply/power_supply.h
> @@ -40,7 +40,6 @@ struct power_supply_ext_registration {
>  
>  extern void __init power_supply_init_attrs(void);
>  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[];
>  
>  #else
> @@ -51,6 +50,8 @@ static inline void power_supply_init_attrs(void) {}
>  
>  #endif /* CONFIG_SYSFS */
>  
> +extern const struct attribute_group power_supply_extension_group;
> +
>  #ifdef CONFIG_LEDS_TRIGGERS
>  
>  extern void power_supply_update_leds(struct power_supply *psy);

  reply	other threads:[~2024-12-18 20:29 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
2024-12-18 19:52   ` Nathan Chancellor
2024-12-18 20:29     ` Thomas Weißschuh [this message]
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=eb265cb2-b079-4bca-bc35-17a9f4d0ec3e@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=nathan@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.