linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v12 2/4] pm: add to_power_supply macro to the API
@ 2018-01-03 11:59 Ognjen Galic
  2018-01-03 14:34 ` Andy Shevchenko
  0 siblings, 1 reply; 2+ messages in thread
From: Ognjen Galic @ 2018-01-03 11:59 UTC (permalink / raw)
  To: Andy Shevchenko, Rafael J. Wysocki, Ognjen Galić,
	Rafael J. Wysocki, Len Brown, Robert Moore, Lv Zheng,
	ACPI Devel Maling List, devel, Darren Hart, Andy Shevchenko,
	Henrique de Moraes Holschuh, Sebastian Reichel, Platform Driver,
	ibm-acpi-devel, Linux PM, Christoph Böhmwalder, Kevin Locke

This patch adds the to_power_supply macro to upcast
a device to a power_supply struct.

This is needed because the same piece of code using
container_of is used in various other places, so we
abstract away such low-level operations via a macro.

Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Ognjen Galic <smclt30p@gmail.com>
---

Notes:
    v9:
    * Split the pm changes from the thinkpad_acpi patch
    into its own patch
    
    v10:
    * No changes in this patch in v10
    
    v11:
    * Fix changelog formatting
    
    v12:
    * Fix build issues in ds2781 and ds2780 battery drivers

 drivers/power/supply/ds2780_battery.c    | 5 -----
 drivers/power/supply/ds2781_battery.c    | 5 -----
 drivers/power/supply/power_supply_core.c | 2 +-
 include/linux/power_supply.h             | 2 ++
 4 files changed, 3 insertions(+), 11 deletions(-)

diff --git a/drivers/power/supply/ds2780_battery.c b/drivers/power/supply/ds2780_battery.c
index e5d81b4..370e910 100644
--- a/drivers/power/supply/ds2780_battery.c
+++ b/drivers/power/supply/ds2780_battery.c
@@ -56,11 +56,6 @@ to_ds2780_device_info(struct power_supply *psy)
 	return power_supply_get_drvdata(psy);
 }
 
-static inline struct power_supply *to_power_supply(struct device *dev)
-{
-	return dev_get_drvdata(dev);
-}
-
 static inline int ds2780_battery_io(struct ds2780_device_info *dev_info,
 	char *buf, int addr, size_t count, int io)
 {
diff --git a/drivers/power/supply/ds2781_battery.c b/drivers/power/supply/ds2781_battery.c
index efe83ef..d1b5a19 100644
--- a/drivers/power/supply/ds2781_battery.c
+++ b/drivers/power/supply/ds2781_battery.c
@@ -54,11 +54,6 @@ to_ds2781_device_info(struct power_supply *psy)
 	return power_supply_get_drvdata(psy);
 }
 
-static inline struct power_supply *to_power_supply(struct device *dev)
-{
-	return dev_get_drvdata(dev);
-}
-
 static inline int ds2781_battery_io(struct ds2781_device_info *dev_info,
 	char *buf, int addr, size_t count, int io)
 {
diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c
index 82f998a..feac7b0 100644
--- a/drivers/power/supply/power_supply_core.c
+++ b/drivers/power/supply/power_supply_core.c
@@ -668,7 +668,7 @@ EXPORT_SYMBOL_GPL(power_supply_powers);
 
 static void power_supply_dev_release(struct device *dev)
 {
-	struct power_supply *psy = container_of(dev, struct power_supply, dev);
+	struct power_supply *psy = to_power_supply(dev);
 	dev_dbg(dev, "%s\n", __func__);
 	kfree(psy);
 }
diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h
index 79e90b3..f0139b4 100644
--- a/include/linux/power_supply.h
+++ b/include/linux/power_supply.h
@@ -371,6 +371,8 @@ devm_power_supply_register_no_ws(struct device *parent,
 extern void power_supply_unregister(struct power_supply *psy);
 extern int power_supply_powers(struct power_supply *psy, struct device *dev);
 
+#define to_power_supply(device) container_of(device, struct power_supply, dev)
+
 extern void *power_supply_get_drvdata(struct power_supply *psy);
 /* For APM emulation, think legacy userspace. */
 extern struct class *power_supply_class;
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v12 2/4] pm: add to_power_supply macro to the API
  2018-01-03 11:59 [PATCH v12 2/4] pm: add to_power_supply macro to the API Ognjen Galic
@ 2018-01-03 14:34 ` Andy Shevchenko
  0 siblings, 0 replies; 2+ messages in thread
From: Andy Shevchenko @ 2018-01-03 14:34 UTC (permalink / raw)
  To: Ognjen Galic
  Cc: Rafael J. Wysocki, Rafael J. Wysocki, Len Brown, Robert Moore,
	Lv Zheng, ACPI Devel Maling List, devel, Darren Hart,
	Andy Shevchenko, Henrique de Moraes Holschuh, Sebastian Reichel,
	Platform Driver, ibm-acpi-devel, Linux PM,
	Christoph Böhmwalder, Kevin Locke

On Wed, Jan 3, 2018 at 1:59 PM, Ognjen Galic <smclt30p@gmail.com> wrote:
> This patch adds the to_power_supply macro to upcast
> a device to a power_supply struct.
>
> This is needed because the same piece of code using
> container_of is used in various other places, so we
> abstract away such low-level operations via a macro.
>
> Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Signed-off-by: Ognjen Galic <smclt30p@gmail.com>

It took me a while to understand if those private implementations are
equivalent to what you introduced.
Looks so sysfs_create_group() adds the attributes to power supply
device kobject, thus the struct device pointer in the callback will be
power supply child, not the actual hardware which seems correct.

Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>

> ---
>
> Notes:
>     v9:
>     * Split the pm changes from the thinkpad_acpi patch
>     into its own patch
>
>     v10:
>     * No changes in this patch in v10
>
>     v11:
>     * Fix changelog formatting
>
>     v12:
>     * Fix build issues in ds2781 and ds2780 battery drivers
>
>  drivers/power/supply/ds2780_battery.c    | 5 -----
>  drivers/power/supply/ds2781_battery.c    | 5 -----
>  drivers/power/supply/power_supply_core.c | 2 +-
>  include/linux/power_supply.h             | 2 ++
>  4 files changed, 3 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/power/supply/ds2780_battery.c b/drivers/power/supply/ds2780_battery.c
> index e5d81b4..370e910 100644
> --- a/drivers/power/supply/ds2780_battery.c
> +++ b/drivers/power/supply/ds2780_battery.c
> @@ -56,11 +56,6 @@ to_ds2780_device_info(struct power_supply *psy)
>         return power_supply_get_drvdata(psy);
>  }
>
> -static inline struct power_supply *to_power_supply(struct device *dev)
> -{
> -       return dev_get_drvdata(dev);
> -}
> -
>  static inline int ds2780_battery_io(struct ds2780_device_info *dev_info,
>         char *buf, int addr, size_t count, int io)
>  {
> diff --git a/drivers/power/supply/ds2781_battery.c b/drivers/power/supply/ds2781_battery.c
> index efe83ef..d1b5a19 100644
> --- a/drivers/power/supply/ds2781_battery.c
> +++ b/drivers/power/supply/ds2781_battery.c
> @@ -54,11 +54,6 @@ to_ds2781_device_info(struct power_supply *psy)
>         return power_supply_get_drvdata(psy);
>  }
>
> -static inline struct power_supply *to_power_supply(struct device *dev)
> -{
> -       return dev_get_drvdata(dev);
> -}
> -
>  static inline int ds2781_battery_io(struct ds2781_device_info *dev_info,
>         char *buf, int addr, size_t count, int io)
>  {
> diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c
> index 82f998a..feac7b0 100644
> --- a/drivers/power/supply/power_supply_core.c
> +++ b/drivers/power/supply/power_supply_core.c
> @@ -668,7 +668,7 @@ EXPORT_SYMBOL_GPL(power_supply_powers);
>
>  static void power_supply_dev_release(struct device *dev)
>  {
> -       struct power_supply *psy = container_of(dev, struct power_supply, dev);
> +       struct power_supply *psy = to_power_supply(dev);
>         dev_dbg(dev, "%s\n", __func__);
>         kfree(psy);
>  }
> diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h
> index 79e90b3..f0139b4 100644
> --- a/include/linux/power_supply.h
> +++ b/include/linux/power_supply.h
> @@ -371,6 +371,8 @@ devm_power_supply_register_no_ws(struct device *parent,
>  extern void power_supply_unregister(struct power_supply *psy);
>  extern int power_supply_powers(struct power_supply *psy, struct device *dev);
>
> +#define to_power_supply(device) container_of(device, struct power_supply, dev)
> +
>  extern void *power_supply_get_drvdata(struct power_supply *psy);
>  /* For APM emulation, think legacy userspace. */
>  extern struct class *power_supply_class;
> --
> 2.7.4
>



-- 
With Best Regards,
Andy Shevchenko

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-01-03 14:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-01-03 11:59 [PATCH v12 2/4] pm: add to_power_supply macro to the API Ognjen Galic
2018-01-03 14:34 ` Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).