power: add to_power_supply macro to the API
authorOgnjen Galic <smclt30p@gmail.com>
Wed, 7 Feb 2018 14:58:27 +0000 (15:58 +0100)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Wed, 21 Feb 2018 22:27:13 +0000 (23:27 +0100)
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>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Ognjen Galic <smclt30p@gmail.com>
Reviewed-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/power/supply/ds2780_battery.c
drivers/power/supply/ds2781_battery.c
drivers/power/supply/power_supply_core.c
include/linux/power_supply.h

index e5d81b493c455318135155ca75809853a4c3b7a8..370e9109342b8a3e9340f5c7a4eba7d6a0e69b54 100644 (file)
@@ -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)
 {
index efe83ef8670ccfc114f5aca3f2f6cdda689697df..d1b5a19aae7c67e467000545982bb8c155d342c2 100644 (file)
@@ -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)
 {
index 82f998ab5a528f78e5243b096ee0b0e0e8a3a901..feac7b066e6c4f4894aabd60dd3a2b57bc7b6a8a 100644 (file)
@@ -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);
 }
index 79e90b3d32888fe6fd5e3abff958a346738d4ab2..f0139b460a72313ea74c055860c6480e2855912d 100644 (file)
@@ -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;