Skip to contentSkip to conversation

pm: add to_power_supply macro to the API

PATCH Superseded Ognjen Galic 2 participants 2 messages Dec 31, 2017 – Jan 1, 2018

Subsystems (4)

v11 of 13 Superseded Latest is v13 →

lore
Share & tools
lore
#0 lore raw

PATCH v11 2/5 pm: add to_power_supply macro to the API

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.

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

---
 drivers/power/supply/power_supply_core.c | 2 +-
 include/linux/power_supply.h             | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)
drivers/power/supply/power_supply_core.c +1 -1
index 82f998a..feac7b0 100644
@@ -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);
 }
include/linux/power_supply.h +2 -0
index 79e90b3..f0139b4 100644
@@ -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;
Signature · 1 line
2.7.4
#1 lore raw
Quoted 6 lines · Ognjen Galic

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.

The patch 5 must be folded into this one. I told you that. Otherwise you will leave bisectability issue.

Quoted 8 lines
Suggested-by Andy Shevchenko <andriy.shevchenko(a)linux.intel.com>
Signed-off-by Ognjen Galic <smclt30p(a)gmail.com>

v9:
* Split the pm changes from the thinkpad_acpi patch into its own patch

Quoted 5 lines

v10:
* No changes in this patch in v10

v11:
* Fix changelog formatting

Changelog should go *after* --- line...

Quoted 1 line

---

...to here.

Quoted 2 lines
 drivers/power/supply/power_supply_core.c | 2 +-
 include/linux/power_supply.h             | 2 ++
Signature · 2 lines
With Best Regards,
Andy Shevchenko