Skip to content

Commit

Permalink
power: add to_power_supply macro to the API
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Ognjen Galic authored and Rafael J. Wysocki committed Feb 21, 2018
1 parent fa93854 commit 285995d
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 11 deletions.
5 changes: 0 additions & 5 deletions drivers/power/supply/ds2780_battery.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
5 changes: 0 additions & 5 deletions drivers/power/supply/ds2781_battery.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion drivers/power/supply/power_supply_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 2 additions & 0 deletions include/linux/power_supply.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 285995d

Please sign in to comment.