2015-02-23

Change the ownership of power_supply structure from each driver

implementing the class to the power supply core.

The patch changes power_supply_register() function thus all drivers

implementing power supply class are adjusted.

Each driver provides the implementation of power supply. However it

should not be the owner of power supply class instance because it is

exposed by core to other subsystems with power_supply_get_by_name().

These other subsystems have no knowledge when the driver will unregister

the power supply. This leads to several issues when driver is unbound -

mostly because user of power supply accesses freed memory.

Instead let the core own the instance of struct 'power_supply'. Other

users of this power supply will still access valid memory because it

will be freed when device reference count reaches 0. Currently this

means "it will leak" but power_supply_put() call in next patches will

solve it.

This solves invalid memory references in following race condition

scenario:

Thread 1: charger manager

Thread 2: power supply driver, used by charger manager

THREAD 1 (charger manager) THREAD 2 (power supply driver)

========================== ==============================

psy = power_supply_get_by_name()

Driver unbind, .remove

power_supply_unregister()

Device fully removed

psy->get_property()

The 'get_property' call is executed in invalid context because the driver was

unbound and struct 'power_supply' memory was freed.

This could be observed easily with charger manager driver (here compiled

with max17040 fuel gauge):

$ cat /sys/devices/virtual/power_supply/cm-battery/capacity &

$ echo "1-0036" > /sys/bus/i2c/drivers/max17040/unbind

[ 55.725123] Unable to handle kernel NULL pointer dereference at virtual address 00000000

[ 55.732584] pgd = d98d4000

[ 55.734060] [00000000] *pgd=5afa2831, *pte=00000000, *ppte=00000000

[ 55.740318] Internal error: Oops: 80000007 [#1] PREEMPT SMP ARM

[ 55.746210] Modules linked in:

[ 55.749259] CPU: 1 PID: 2936 Comm: cat Tainted: G W 3.19.0-rc1-next-20141226-00048-gf79f475f3c44-dirty #1496

[ 55.760190] Hardware name: SAMSUNG EXYNOS (Flattened Device Tree)

[ 55.766270] task: d9b76f00 ti: daf54000 task.ti: daf54000

[ 55.771647] PC is at 0x0

[ 55.774182] LR is at charger_get_property+0x2f4/0x36c

[ 55.779201] pc : [<00000000>] lr : [<c034b0b4>] psr: 60000013

[ 55.779201] sp : daf55e90 ip : 00000003 fp : 00000000

[ 55.790657] r10: 00000000 r9 : c06e2878 r8 : d9b26c68

[ 55.795865] r7 : dad81610 r6 : daec7410 r5 : daf55ebc r4 : 00000000

[ 55.802367] r3 : 00000000 r2 : daf55ebc r1 : 0000002a r0 : d9b26c68

[ 55.808879] Flags: nZCv IRQs on FIQs on Mode SVC_32 ISA ARM Segment user

[ 55.815994] Control: 10c5387d Table: 598d406a DAC: 00000015

[ 55.821723] Process cat (pid: 2936, stack limit = 0xdaf54210)

[ 55.827451] Stack: (0xdaf55e90 to 0xdaf56000)

[ 55.831795] 5e80: 60000013 c01459c4 0000002a c06f8ef8

[ 55.839956] 5ea0: db651000 c06f8ef8 daebac00 c04cb668 daebac08 c0346864 00000000 c01459c4

[ 55.848115] 5ec0: d99eaa80 c06f8ef8 00000fff 00001000 db651000 c027f25c c027f240 d99eaa80

[ 55.856274] 5ee0: d9a06c00 c0146218 daf55f18 00001000 d99eaa80 db4c18c0 00000001 00000001

[ 55.864468] 5f00: daf55f80 c0144c78 c0144c54 c0107f90 00015000 d99eaab0 00000000 00000000

[ 55.872603] 5f20: 000051c7 00000000 db4c18c0 c04a9370 00015000 00001000 daf55f80 00001000

[ 55.880763] 5f40: daf54000 00015000 00000000 c00e53dc db4c18c0 c00e548c 0000000d 00008124

[ 55.888937] 5f60: 00000001 00000000 00000000 db4c18c0 db4c18c0 00001000 00015000 c00e5550

[ 55.897099] 5f80: 00000000 00000000 00001000 00001000 00015000 00000003 00000003 c000f364

[ 55.905239] 5fa0: 00000000 c000f1a0 00001000 00015000 00000003 00015000 00001000 0001333c

[ 55.913399] 5fc0: 00001000 00015000 00000003 00000003 00000002 00000000 00000000 00000000

[ 55.921560] 5fe0: 7fffe000 be999850 0000a225 b6f3c19c 60000010 00000003 00000000 00000000

[ 55.929744] [<c034b0b4>] (charger_get_property) from [<c0346864>] (power_supply_show_property+0x48/0x20c)

[ 55.939286] [<c0346864>] (power_supply_show_property) from [<c027f25c>] (dev_attr_show+0x1c/0x48)

[ 55.948130] [<c027f25c>] (dev_attr_show) from [<c0146218>] (sysfs_kf_seq_show+0x84/0x104)

[ 55.956298] [<c0146218>] (sysfs_kf_seq_show) from [<c0144c78>] (kernfs_seq_show+0x24/0x28)

[ 55.964536] [<c0144c78>] (kernfs_seq_show) from [<c0107f90>] (seq_read+0x1b0/0x484)

[ 55.972172] [<c0107f90>] (seq_read) from [<c00e53dc>] (__vfs_read+0x18/0x4c)

[ 55.979188] [<c00e53dc>] (__vfs_read) from [<c00e548c>] (vfs_read+0x7c/0x100)

[ 55.986304] [<c00e548c>] (vfs_read) from [<c00e5550>] (SyS_read+0x40/0x8c)

[ 55.993164] [<c00e5550>] (SyS_read) from [<c000f1a0>] (ret_fast_syscall+0x0/0x48)

[ 56.000626] Code: bad PC value

[ 56.011652] ---[ end trace 7b64343fbdae8ef1 ]---

Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>

Reviewed-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>

[for the nvec part]

Reviewed-by: Marc Dietrich <marvin24@gmx.de>

---

arch/x86/platform/olpc/olpc-xo1-sci.c | 4 +-

arch/x86/platform/olpc/olpc-xo15-sci.c | 4 +-

drivers/acpi/ac.c | 32 +++---

drivers/acpi/battery.c | 55 +++++-----

drivers/acpi/sbs.c | 68 +++++++-----

drivers/hid/hid-input.c | 51 +++++----

drivers/hid/hid-sony.c | 43 ++++----

drivers/hid/hid-wiimote-modules.c | 41 +++----

drivers/hid/hid-wiimote.h | 3 +-

drivers/hid/wacom.h | 8 +-

drivers/hid/wacom_sys.c | 71 ++++++------

drivers/platform/x86/compal-laptop.c | 29 +++--

drivers/power/88pm860x_battery.c | 40 +++----

drivers/power/88pm860x_charger.c | 32 +++---

drivers/power/ab8500_btemp.c | 68 ++++++------

drivers/power/ab8500_charger.c | 136 ++++++++++++-----------

drivers/power/ab8500_fg.c | 124 ++++++++-------------

drivers/power/abx500_chargalg.c | 90 +++++++--------

drivers/power/apm_power.c | 2 +-

drivers/power/bq2415x_charger.c | 73 ++++++-------

drivers/power/bq24190_charger.c | 103 +++++++++--------

drivers/power/bq24735-charger.c | 45 ++++----

drivers/power/bq27x00_battery.c | 70 ++++++------

drivers/power/charger-manager.c | 54 ++++-----

drivers/power/collie_battery.c | 75 ++++++++-----

drivers/power/da9030_battery.c | 33 +++---

drivers/power/da9052-battery.c | 25 +++--

drivers/power/ds2760_battery.c | 56 +++++-----

drivers/power/ds2780_battery.c | 45 +++++---

drivers/power/ds2781_battery.c | 47 ++++----

drivers/power/ds2782_battery.c | 30 +++--

drivers/power/generic-adc-battery.c | 54 +++++----

drivers/power/goldfish_battery.c | 63 ++++++-----

drivers/power/gpio-charger.c | 34 +++---

drivers/power/intel_mid_battery.c | 57 ++++++----

drivers/power/ipaq_micro_battery.c | 34 +++---

drivers/power/isp1704_charger.c | 49 +++++----

drivers/power/jz4740-battery.c | 37 ++++---

drivers/power/lp8727_charger.c | 88 ++++++++-------

drivers/power/lp8788-charger.c | 55 ++++++----

drivers/power/ltc2941-battery-gauge.c | 51 +++++----

drivers/power/max14577_charger.c | 34 +++---

drivers/power/max17040_battery.c | 31 +++---

drivers/power/max17042_battery.c | 45 +++++---

drivers/power/max77693_charger.c | 32 +++---

drivers/power/max8903_charger.c | 52 +++++----

drivers/power/max8925_power.c | 88 ++++++++-------

drivers/power/max8997_charger.c | 31 ++++--

drivers/power/max8998_charger.c | 32 ++++--

drivers/power/olpc_battery.c | 54 +++++----

drivers/power/pcf50633-charger.c | 95 +++++++++-------

drivers/power/pda_power.c | 52 +++++----

drivers/power/pm2301_charger.c | 42 +++----

drivers/power/pm2301_charger.h | 1 +

drivers/power/pmu_battery.c | 42 ++++---

drivers/power/power_supply_core.c | 176 +++++++++++++++++++-----------

drivers/power/power_supply_leds.c | 25 +++--

drivers/power/power_supply_sysfs.c | 20 ++--

drivers/power/rt5033_battery.c | 27 +++--

drivers/power/rx51_battery.c | 27 +++--

drivers/power/s3c_adc_battery.c | 77 +++++++------

drivers/power/sbs-battery.c | 69 ++++++------

drivers/power/smb347-charger.c | 107 +++++++++---------

drivers/power/test_power.c | 34 +++---

drivers/power/tosa_battery.c | 112 +++++++++++--------

drivers/power/tps65090-charger.c | 35 +++---

drivers/power/twl4030_charger.c | 65 ++++++-----

drivers/power/twl4030_madc_battery.c | 41 +++----

drivers/power/wm831x_backup.c | 26 ++---

drivers/power/wm831x_power.c | 95 ++++++++--------

drivers/power/wm8350_power.c | 89 ++++++++-------

drivers/power/wm97xx_battery.c | 37 ++++---

drivers/power/z2_battery.c | 60 +++++-----

drivers/staging/nvec/nvec_power.c | 29 +++--

include/linux/hid.h | 6 +-

include/linux/mfd/abx500/ux500_chargalg.h | 11 +-

include/linux/mfd/rt5033.h | 2 +-

include/linux/mfd/wm8350/supply.h | 6 +-

include/linux/power/charger-manager.h | 3 +-

include/linux/power_supply.h | 39 ++++---

80 files changed, 2172 insertions(+), 1756 deletions(-)

diff --git a/arch/x86/platform/olpc/olpc-xo1-sci.c b/arch/x86/platform/olpc/olpc-xo1-sci.c

index 9a2e590dd202..e4ed28bbf79d 100644

--- a/arch/x86/platform/olpc/olpc-xo1-sci.c

+++ b/arch/x86/platform/olpc/olpc-xo1-sci.c

@@ -61,7 +61,7 @@ static void battery_status_changed(void)

if (psy) {

power_supply_changed(psy);

- put_device(psy->dev);

+ put_device(&psy->dev);

}

}

@@ -71,7 +71,7 @@ static void ac_status_changed(void)

if (psy) {

power_supply_changed(psy);

- put_device(psy->dev);

+ put_device(&psy->dev);

}

}

diff --git a/arch/x86/platform/olpc/olpc-xo15-sci.c b/arch/x86/platform/olpc/olpc-xo15-sci.c

index 08e350e757dc..186634e9021d 100644

--- a/arch/x86/platform/olpc/olpc-xo15-sci.c

+++ b/arch/x86/platform/olpc/olpc-xo15-sci.c

@@ -83,7 +83,7 @@ static void battery_status_changed(void)

if (psy) {

power_supply_changed(psy);

- put_device(psy->dev);

+ put_device(&psy->dev);

}

}

@@ -93,7 +93,7 @@ static void ac_status_changed(void)

if (psy) {

power_supply_changed(psy);

- put_device(psy->dev);

+ put_device(&psy->dev);

}

}

diff --git a/drivers/acpi/ac.c b/drivers/acpi/ac.c

index 8bf516885ede..bbcc2b5a70d4 100644

--- a/drivers/acpi/ac.c

+++ b/drivers/acpi/ac.c

@@ -95,13 +95,14 @@ static struct acpi_driver acpi_ac_driver = {

};

struct acpi_ac {

- struct power_supply charger;

+ struct power_supply *charger;

+ struct power_supply_desc charger_desc;

struct acpi_device * device;

unsigned long long state;

struct notifier_block battery_nb;

};

-#define to_acpi_ac(x) container_of(x, struct acpi_ac, charger)

+#define to_acpi_ac(x) power_supply_get_drvdata(x)

#ifdef CONFIG_ACPI_PROCFS_POWER

static const struct file_operations acpi_ac_fops = {

@@ -275,7 +276,7 @@ static void acpi_ac_notify(struct acpi_device *device, u32 event)

dev_name(&device->dev), event,

(u32) ac->state);

acpi_notifier_call_chain(device, event, (u32) ac->state);

- kobject_uevent(&ac->charger.dev->kobj, KOBJ_CHANGE);

+ kobject_uevent(&ac->charger->dev.kobj, KOBJ_CHANGE);

}

return;

@@ -321,6 +322,7 @@ static struct dmi_system_id ac_dmi_table[] = {

static int acpi_ac_add(struct acpi_device *device)

{

+ struct power_supply_config psy_cfg = {};

int result = 0;

struct acpi_ac *ac = NULL;

@@ -341,19 +343,24 @@ static int acpi_ac_add(struct acpi_device *device)

if (result)

goto end;

- ac->charger.name = acpi_device_bid(device);

+ psy_cfg.drv_data = ac;

+

+ ac->charger_desc.name = acpi_device_bid(device);

#ifdef CONFIG_ACPI_PROCFS_POWER

result = acpi_ac_add_fs(ac);

if (result)

goto end;

#endif

- ac->charger.type = POWER_SUPPLY_TYPE_MAINS;

- ac->charger.properties = ac_props;

- ac->charger.num_properties = ARRAY_SIZE(ac_props);

- ac->charger.get_property = get_ac_property;

- result = power_supply_register(&ac->device->dev, &ac->charger, NULL);

- if (result)

+ ac->charger_desc.type = POWER_SUPPLY_TYPE_MAINS;

+ ac->charger_desc.properties = ac_props;

+ ac->charger_desc.num_properties = ARRAY_SIZE(ac_props);

+ ac->charger_desc.get_property = get_ac_property;

+ ac->charger = power_supply_register(&ac->device->dev,

+ &ac->charger_desc, &psy_cfg);

+ if (IS_ERR(ac->charger)) {

+ result = PTR_ERR(ac->charger);

goto end;

+ }

printk(KERN_INFO PREFIX "%s [%s] (%s)\n",

acpi_device_name(device), acpi_device_bid(device),

@@ -390,7 +397,7 @@ static int acpi_ac_resume(struct device *dev)

if (acpi_ac_get_state(ac))

return 0;

if (old_state != ac->state)

- kobject_uevent(&ac->charger.dev->kobj, KOBJ_CHANGE);

+ kobject_uevent(&ac->charger->dev.kobj, KOBJ_CHANGE);

return 0;

}

#else

@@ -407,8 +414,7 @@ static int acpi_ac_remove(struct acpi_device *device)

ac = acpi_driver_data(device);

- if (ac->charger.dev)

- power_supply_unregister(&ac->charger);

+ power_supply_unregister(ac->charger);

unregister_acpi_notifier(&ac->battery_nb);

#ifdef CONFIG_ACPI_PROCFS_POWER

diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c

index fd8c06f492a1..fdc16ce9d272 100644

--- a/drivers/acpi/battery.c

+++ b/drivers/acpi/battery.c

@@ -117,7 +117,8 @@ enum {

struct acpi_battery {

struct mutex lock;

struct mutex sysfs_lock;

- struct power_supply bat;

+ struct power_supply *bat;

+ struct power_supply_desc bat_desc;

struct acpi_device *device;

struct notifier_block pm_nb;

unsigned long update_time;

@@ -149,7 +150,7 @@ struct acpi_battery {

unsigned long flags;

};

-#define to_acpi_battery(x) container_of(x, struct acpi_battery, bat)

+#define to_acpi_battery(x) power_supply_get_drvdata(x)

static inline int acpi_battery_present(struct acpi_battery *battery)

{

@@ -608,41 +609,45 @@ static struct device_attribute alarm_attr = {

static int sysfs_add_battery(struct acpi_battery *battery)

{

- int result;

+ struct power_supply_config psy_cfg = { .drv_data = battery, };

if (battery->power_unit == ACPI_BATTERY_POWER_UNIT_MA) {

- battery->bat.properties = charge_battery_props;

- battery->bat.num_properties =

+ battery->bat_desc.properties = charge_battery_props;

+ battery->bat_desc.num_properties =

ARRAY_SIZE(charge_battery_props);

} else {

- battery->bat.properties = energy_battery_props;

- battery->bat.num_properties =

+ battery->bat_desc.properties = energy_battery_props;

+ battery->bat_desc.num_properties =

ARRAY_SIZE(energy_battery_props);

}

- battery->bat.name = acpi_device_bid(battery->device);

- battery->bat.type = POWER_SUPPLY_TYPE_BATTERY;

- battery->bat.get_property = acpi_battery_get_property;

+ battery->bat_desc.name = acpi_device_bid(battery->device);

+ battery->bat_desc.type = POWER_SUPPLY_TYPE_BATTERY;

+ battery->bat_desc.get_property = acpi_battery_get_property;

- result = power_supply_register_no_ws(&battery->device->dev,

- &battery->bat, NULL);

+ battery->bat = power_supply_register_no_ws(&battery->device->dev,

+ &battery->bat_desc, &psy_cfg);

- if (result)

+ if (IS_ERR(battery->bat)) {

+ int result = PTR_ERR(battery->bat);

+

+ battery->bat = NULL;

return result;

- return device_create_file(battery->bat.dev, &alarm_attr);

+ }

+ return device_create_file(&battery->bat->dev, &alarm_attr);

}

static void sysfs_remove_battery(struct acpi_battery *battery)

{

mutex_lock(&battery->sysfs_lock);

- if (!battery->bat.dev) {

+ if (!battery->bat) {

mutex_unlock(&battery->sysfs_lock);

return;

}

- device_remove_file(battery->bat.dev, &alarm_attr);

- power_supply_unregister(&battery->bat);

- battery->bat.dev = NULL;

+ device_remove_file(&battery->bat->dev, &alarm_attr);

+ power_supply_unregister(battery->bat);

+ battery->bat = NULL;

mutex_unlock(&battery->sysfs_lock);

}

@@ -739,7 +744,7 @@ static int acpi_battery_update(struct acpi_battery *battery, bool resume)

return result;

acpi_battery_init_alarm(battery);

}

- if (!battery->bat.dev) {

+ if (!battery->bat) {

result = sysfs_add_battery(battery);

if (result)

return result;

@@ -765,7 +770,7 @@ static void acpi_battery_refresh(struct acpi_battery *battery)

{

int power_unit;

- if (!battery->bat.dev)

+ if (!battery->bat)

return;

power_unit = battery->power_unit;

@@ -1063,11 +1068,11 @@ static void acpi_battery_remove_fs(struct acpi_device *device)

static void acpi_battery_notify(struct acpi_device *device, u32 event)

{

struct acpi_battery *battery = acpi_driver_data(device);

- struct device *old;

+ struct power_supply *old;

if (!battery)

return;

- old = battery->bat.dev;

+ old = battery->bat;

/*

* On Acer Aspire V5-573G notifications are sometimes triggered too

* early. For example, when AC is unplugged and notification is

@@ -1084,8 +1089,8 @@ static void acpi_battery_notify(struct acpi_device *device, u32 event)

acpi_battery_present(battery));

acpi_notifier_call_chain(device, event, acpi_battery_present(battery));

/* acpi_battery_update could remove power_supply object */

- if (old && battery->bat.dev)

- power_supply_changed(&battery->bat);

+ if (old && battery->bat)

+ power_supply_changed(battery->bat);

}

static int battery_notify(struct notifier_block *nb,

@@ -1101,7 +1106,7 @@ static int battery_notify(struct notifier_block *nb,

if (!acpi_battery_present(battery))

return 0;

- if (!battery->bat.dev) {

+ if (battery->bat) {

result = acpi_battery_get_info(battery);

if (result)

return result;

diff --git a/drivers/acpi/sbs.c b/drivers/acpi/sbs.c

index 2038ec1d021d..cd827625cf07 100644

--- a/drivers/acpi/sbs.c

+++ b/drivers/acpi/sbs.c

@@ -74,7 +74,8 @@ static const struct acpi_device_id sbs_device_ids[] = {

MODULE_DEVICE_TABLE(acpi, sbs_device_ids);

struct acpi_battery {

- struct power_supply bat;

+ struct power_supply *bat;

+ struct power_supply_desc bat_desc;

struct acpi_sbs *sbs;

unsigned long update_time;

char name[8];

@@ -101,10 +102,10 @@ struct acpi_battery {

u8 have_sysfs_alarm:1;

};

-#define to_acpi_battery(x) container_of(x, struct acpi_battery, bat)

+#define to_acpi_battery(x) power_supply_get_drvdata(x)

struct acpi_sbs {

- struct power_supply charger;

+ struct power_supply *charger;

struct acpi_device *device;

struct acpi_smb_hc *hc;

struct mutex lock;

@@ -115,7 +116,7 @@ struct acpi_sbs {

u8 charger_exists:1;

};

-#define to_acpi_sbs(x) container_of(x, struct acpi_sbs, charger)

+#define to_acpi_sbs(x) power_supply_get_drvdata(x)

static int acpi_sbs_remove(struct acpi_device *device);

static int acpi_battery_get_state(struct acpi_battery *battery);

@@ -303,6 +304,13 @@ static enum power_supply_property sbs_energy_battery_props[] = {

POWER_SUPPLY_PROP_MANUFACTURER,

};

+static const struct power_supply_desc acpi_sbs_charger_desc = {

+ .name = "sbs-charger",

+ .type = POWER_SUPPLY_TYPE_MAINS,

+ .properties = sbs_ac_props,

+ .num_properties = ARRAY_SIZE(sbs_ac_props),

+ .get_property = sbs_get_ac_property,

+};

/* --------------------------------------------------------------------------

Smart Battery System Management

@@ -519,6 +527,7 @@ static int acpi_battery_read(struct acpi_battery *battery)

static int acpi_battery_add(struct acpi_sbs *sbs, int id)

{

struct acpi_battery *battery = &sbs->battery[id];

+ struct power_supply_config psy_cfg = { .drv_data = battery, };

int result;

battery->id = id;

@@ -528,23 +537,27 @@ static int acpi_battery_add(struct acpi_sbs *sbs, int id)

return result;

sprintf(battery->name, ACPI_BATTERY_DIR_NAME, id);

- battery->bat.name = battery->name;

- battery->bat.type = POWER_SUPPLY_TYPE_BATTERY;

+ battery->bat_desc.name = battery->name;

+ battery->bat_desc.type = POWER_SUPPLY_TYPE_BATTERY;

if (!acpi_battery_mode(battery)) {

- battery->bat.properties = sbs_charge_battery_props;

- battery->bat.num_properties =

+ battery->bat_desc.properties = sbs_charge_battery_props;

+ battery->bat_desc.num_properties =

ARRAY_SIZE(sbs_charge_battery_props);

} else {

- battery->bat.properties = sbs_energy_battery_props;

- battery->bat.num_properties =

+ battery->bat_desc.properties = sbs_energy_battery_props;

+ battery->bat_desc.num_properties =

ARRAY_SIZE(sbs_energy_battery_props);

}

- battery->bat.get_property = acpi_sbs_battery_get_property;

- result = power_supply_register(&sbs->device->dev, &battery->bat, NULL);

- if (result)

+ battery->bat_desc.get_property = acpi_sbs_battery_get_property;

+ battery->bat = power_supply_register(&sbs->device->dev,

+ &battery->bat_desc, &psy_cfg);

+ if (IS_ERR(battery->bat)) {

+ result = PTR_ERR(battery->bat);

+ battery->bat = NULL;

goto end;

+ }

- result = device_create_file(battery->bat.dev, &alarm_attr);

+ result = device_create_file(&battery->bat->dev, &alarm_attr);

if (result)

goto end;

battery->have_sysfs_alarm = 1;

@@ -559,28 +572,29 @@ static void acpi_battery_remove(struct acpi_sbs *sbs, int id)

{

struct acpi_battery *battery = &sbs->battery[id];

- if (battery->bat.dev) {

+ if (battery->bat) {

if (battery->have_sysfs_alarm)

- device_remove_file(battery->bat.dev, &alarm_attr);

- power_supply_unregister(&battery->bat);

+ device_remove_file(&battery->bat->dev, &alarm_attr);

+ power_supply_unregister(battery->bat);

}

}

static int acpi_charger_add(struct acpi_sbs *sbs)

{

int result;

+ struct power_supply_config psy_cfg = { .drv_data = sbs, };

result = acpi_ac_get_present(sbs);

if (result)

goto end;

sbs->charger_exists = 1;

- sbs->charger.name = "sbs-charger";

- sbs->charger.type = POWER_SUPPLY_TYPE_MAINS;

- sbs->charger.properties = sbs_ac_props;

- sbs->charger.num_properties = ARRAY_SIZE(sbs_ac_props);

- sbs->charger.get_property = sbs_get_ac_property;

- power_supply_register(&sbs->device->dev, &sbs->charger, NULL);

+ sbs->charger = power_supply_register(&sbs->device->dev,

+ &acpi_sbs_charger_desc, &psy_cfg);

+ if (IS_ERR(sbs->charger)) {

+ result = PTR_ERR(sbs->charger);

+ sbs->charger = NULL;

+ }

printk(KERN_INFO PREFIX "%s [%s]: AC Adapter [%s] (%s)\n",

ACPI_SBS_DEVICE_NAME, acpi_device_bid(sbs->device),

ACPI_AC_DIR_NAME, sbs->charger_present ? "on-line" : "off-line");

@@ -590,8 +604,8 @@ static int acpi_charger_add(struct acpi_sbs *sbs)

static void acpi_charger_remove(struct acpi_sbs *sbs)

{

- if (sbs->charger.dev)

- power_supply_unregister(&sbs->charger);

+ if (sbs->charger)

+ power_supply_unregister(sbs->charger);

}

static void acpi_sbs_callback(void *context)

@@ -605,7 +619,7 @@ static void acpi_sbs_callback(void *context)

if (sbs->charger_exists) {

acpi_ac_get_present(sbs);

if (sbs->charger_present != saved_charger_state)

- kobject_uevent(&sbs->charger.dev->kobj, KOBJ_CHANGE);

+ kobject_uevent(&sbs->charger->dev.kobj, KOBJ_CHANGE);

}

if (sbs->manager_present) {

@@ -617,7 +631,7 @@ static void acpi_sbs_callback(void *context)

acpi_battery_read(bat);

if (saved_battery_state == bat->present)

continue;

- kobject_uevent(&bat->bat.dev->kobj, KOBJ_CHANGE);

+ kobject_uevent(&bat->bat->dev.kobj, KOBJ_CHANGE);

}

}

}

diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c

index 6182265a6571..5d5a8c42645f 100644

--- a/drivers/hid/hid-input.c

+++ b/drivers/hid/hid-input.c

@@ -339,7 +339,7 @@ static int hidinput_get_battery_property(struct power_supply *psy,

enum power_supply_property prop,

union power_supply_propval *val)

{

- struct hid_device *dev = container_of(psy, struct hid_device, battery);

+ struct hid_device *dev = power_supply_get_drvdata(psy);

int ret = 0;

__u8 *buf;

@@ -397,26 +397,32 @@ static int hidinput_get_battery_property(struct power_supply *psy,

static bool hidinput_setup_battery(struct hid_device *dev, unsigned report_type, struct hid_field *field)

{

- struct power_supply *battery = &dev->battery;

- int ret;

+ struct power_supply_desc *psy_desc = NULL;

+ struct power_supply_config psy_cfg = { .drv_data = dev, };

unsigned quirks;

s32 min, max;

if (field->usage->hid != HID_DC_BATTERYSTRENGTH)

return false; /* no match */

- if (battery->name != NULL)

+ if (dev->battery != NULL)

goto out; /* already initialized? */

- battery->name = kasprintf(GFP_KERNEL, "hid-%s-battery", dev->uniq);

- if (battery->name == NULL)

+ psy_desc = kzalloc(sizeof(*psy_desc), GFP_KERNEL);

+ if (psy_desc == NULL)

goto out;

- battery->type = POWER_SUPPLY_TYPE_BATTERY;

- battery->properties = hidinput_battery_props;

- battery->num_properties = ARRAY_SIZE(hidinput_battery_props);

- battery->use_for_apm = 0;

- battery->get_property = hidinput_get_battery_property;

+ psy_desc->name = kasprintf(GFP_KERNEL, "hid-%s-battery", dev->uniq);

+ if (psy_desc->name == NULL) {

+ kfree(psy_desc);

+ goto out;

+ }

+

+ psy_desc->type = POWER_SUPPLY_TYPE_BATTERY;

+ psy_desc->properties = hidinput_battery_props;

+ psy_desc->num_properties = ARRAY_SIZE(hidinput_battery_props);

+ psy_desc->use_for_apm = 0;

+ psy_desc->get_property = hidinput_get_battery_property;

quirks = find_battery_quirk(dev);

@@ -439,14 +445,16 @@ static bool hidinput_setup_battery(struct hid_device *dev, unsigned report_type,

dev->battery_report_type = report_type;

dev->battery_report_id = field->report->id;

- ret = power_supply_register(&dev->dev, battery, NULL);

- if (ret != 0) {

- hid_warn(dev, "can't register power supply: %d\n", ret);

- kfree(battery->name);

- battery->name = NULL;

+ dev->battery = power_supply_register(&dev->dev, psy_desc, &psy_cfg);

+ if (IS_ERR(dev->battery)) {

+ hid_warn(dev, "can't register power supply: %ld\n",

+ PTR_ERR(dev->battery));

+ kfree(psy_desc->name);

+ kfree(psy_desc);

+ dev->battery = NULL;

}

- power_supply_powers(battery, &dev->dev);

+ power_supply_powers(dev->battery, &dev->dev);

out:

return true;

@@ -454,12 +462,13 @@ out:

static void hidinput_cleanup_battery(struct hid_device *dev)

{

- if (!dev->battery.name)

+ if (!dev->battery)

return;

- power_supply_unregister(&dev->battery);

- kfree(dev->battery.name);

- dev->battery.name = NULL;

+ power_supply_unregister(dev->battery);

+ kfree(dev->battery->desc->name);

+ kfree(dev->battery->desc);

+ dev->battery = NULL;

}

#else /* !CONFIG_HID_BATTERY_STRENGTH */

static bool hidinput_setup_battery(struct hid_device *dev, unsigned report_type,

diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c

index 16fc6a17ac63..65007ec2d96e 100644

--- a/drivers/hid/hid-sony.c

+++ b/drivers/hid/hid-sony.c

@@ -815,7 +815,8 @@ struct sony_sc {

struct led_classdev *leds[MAX_LEDS];

unsigned long quirks;

struct work_struct state_worker;

- struct power_supply battery;

+ struct power_supply *battery;

+ struct power_supply_desc battery_desc;

int device_id;

__u8 *output_report_dmabuf;

@@ -1660,7 +1661,7 @@ static int sony_battery_get_property(struct power_supply *psy,

enum power_supply_property psp,

union power_supply_propval *val)

{

- struct sony_sc *sc = container_of(psy, struct sony_sc, battery);

+ struct sony_sc *sc = power_supply_get_drvdata(psy);

unsigned long flags;

int ret = 0;

u8 battery_charging, battery_capacity, cable_state;

@@ -1699,6 +1700,7 @@ static int sony_battery_get_property(struct power_supply *psy,

static int sony_battery_probe(struct sony_sc *sc)

{

+ struct power_supply_config psy_cfg = { .drv_data = sc, };

struct hid_device *hdev = sc->hdev;

int ret;

@@ -1708,39 +1710,42 @@ static int sony_battery_probe(struct sony_sc *sc)

*/

sc->battery_capacity = 100;

- sc->battery.properties = sony_battery_props;

- sc->battery.num_properties = ARRAY_SIZE(sony_battery_props);

- sc->battery.get_property = sony_battery_get_property;

- sc->battery.type = POWER_SUPPLY_TYPE_BATTERY;

- sc->battery.use_for_apm = 0;

- sc->battery.name = kasprintf(GFP_KERNEL, "sony_controller_battery_%pMR",

- sc->mac_address);

- if (!sc->battery.name)

+ sc->battery_desc.properties = sony_battery_props;

+ sc->battery_desc.num_properties = ARRAY_SIZE(sony_battery_props);

+ sc->battery_desc.get_property = sony_battery_get_property;

+ sc->battery_desc.type = POWER_SUPPLY_TYPE_BATTERY;

+ sc->battery_desc.use_for_apm = 0;

+ sc->battery_desc.name = kasprintf(GFP_KERNEL,

+ "sony_controller_battery_%pMR",

+ sc->mac_address);

+ if (!sc->battery_desc.name)

return -ENOMEM;

- ret = power_supply_register(&hdev->dev, &sc->battery, NULL);

- if (ret) {

+ sc->battery = power_supply_register(&hdev->dev, &sc->battery_desc,

+ &psy_cfg);

+ if (IS_ERR(sc->battery)) {

+ ret = PTR_ERR(sc->battery);

hid_err(hdev, "Unable to register battery device\n");

goto err_free;

}

- power_supply_powers(&sc->battery, &hdev->dev);

+ power_supply_powers(sc->battery, &hdev->dev);

return 0;

err_free:

- kfree(sc->battery.name);

- sc->battery.name = NULL;

+ kfree(sc->battery_desc.name);

+ sc->battery_desc.name = NULL;

return ret;

}

static void sony_battery_remove(struct sony_sc *sc)

{

- if (!sc->battery.name)

+ if (!sc->battery_desc.name)

return;

- power_supply_unregister(&sc->battery);

- kfree(sc->battery.name);

- sc->battery.name = NULL;

+ power_supply_unregister(sc->battery);

+ kfree(sc->battery_desc.name);

+ sc->battery_desc.name = NULL;

}

/*

diff --git a/drivers/hid/hid-wiimote-modules.c b/drivers/hid/hid-wiimote-modules.c

index 91cb00abcb8e..05e23c417d50 100644

--- a/drivers/hid/hid-wiimote-modules.c

+++ b/drivers/hid/hid-wiimote-modules.c

@@ -203,8 +203,7 @@ static int wiimod_battery_get_property(struct power_supply *psy,

enum power_supply_property psp,

union power_supply_propval *val)

{

- struct wiimote_data *wdata = container_of(psy, struct wiimote_data,

- battery);

+ struct wiimote_data *wdata = power_supply_get_drvdata(psy);

int ret = 0, state;

unsigned long flags;

@@ -238,42 +237,46 @@ static int wiimod_battery_get_property(struct power_supply *psy,

static int wiimod_battery_probe(const struct wiimod_ops *ops,

struct wiimote_data *wdata)

{

+ struct power_supply_config psy_cfg = { .drv_data = wdata, };

int ret;

- wdata->battery.properties = wiimod_battery_props;

- wdata->battery.num_properties = ARRAY_SIZE(wiimod_battery_props);

- wdata->battery.get_property = wiimod_battery_get_property;

- wdata->battery.type = POWER_SUPPLY_TYPE_BATTERY;

- wdata->battery.use_for_apm = 0;

- wdata->battery.name = kasprintf(GFP_KERNEL, "wiimote_battery_%s",

- wdata->hdev->uniq);

- if (!wdata->battery.name)

+ wdata->battery_desc.properties = wiimod_battery_props;

+ wdata->battery_desc.num_properties = ARRAY_SIZE(wiimod_battery_props);

+ wdata->battery_desc.get_property = wiimod_battery_get_property;

+ wdata->battery_desc.type = POWER_SUPPLY_TYPE_BATTERY;

+ wdata->battery_desc.use_for_apm = 0;

+ wdata->battery_desc.name = kasprintf(GFP_KERNEL, "wiimote_battery_%s",

+ wdata->hdev->uniq);

+ if (!wdata->battery_desc.name)

return -ENOMEM;

- ret = power_supply_register(&wdata->hdev->dev, &wdata->battery, NULL);

- if (ret) {

+ wdata->battery = power_supply_register(&wdata->hdev->dev,

+ &wdata->battery_desc,

+ &psy_cfg);

+ if (IS_ERR(wdata->battery)) {

hid_err(wdata->hdev, "cannot register battery device\n");

+ ret = PTR_ERR(wdata->battery);

goto err_free;

}

- power_supply_powers(&wdata->battery, &wdata->hdev->dev);

+ power_supply_powers(wdata->battery, &wdata->hdev->dev);

return 0;

err_free:

- kfree(wdata->battery.name);

- wdata->battery.name = NULL;

+ kfree(wdata->battery_desc.name);

+ wdata->battery_desc.name = NULL;

return ret;

}

static void wiimod_battery_remove(const struct wiimod_ops *ops,

struct wiimote_data *wdata)

{

- if (!wdata->battery.name)

+ if (!wdata->battery_desc.name)

return;

- power_supply_unregister(&wdata->battery);

- kfree(wdata->battery.name);

- wdata->battery.name = NULL;

+ power_supply_unregister(wdata->battery);

+ kfree(wdata->battery_desc.name);

+ wdata->battery_desc.name = NULL;

}

static const struct wiimod_ops wiimod_battery = {

diff --git a/drivers/hid/hid-wiimote.h b/drivers/hid/hid-wiimote.h

index 10934aa129fb..875694d43e4d 100644

--- a/drivers/hid/hid-wiimote.h

+++ b/drivers/hid/hid-wiimote.h

@@ -147,7 +147,8 @@ struct wiimote_data {

struct led_classdev *leds[4];

struct input_dev *accel;

struct input_dev *ir;

- struct power_supply battery;

+ struct power_supply *battery;

+ struct power_supply_desc battery_desc;

struct input_dev *mp;

struct timer_list timer;

struct wiimote_debug *debug;

diff --git a/drivers/hid/wacom.h b/drivers/hid/wacom.h

index 7db432809e9e..0d0d0dd89d17 100644

--- a/drivers/hid/wacom.h

+++ b/drivers/hid/wacom.h

@@ -119,8 +119,10 @@ struct wacom {

u8 img_lum; /* OLED matrix display brightness */

} led;

bool led_initialized;

- struct power_supply battery;

- struct power_supply ac;

+ struct power_supply *battery;

+ struct power_supply *ac;

+ struct power_supply_desc battery_desc;

+ struct power_supply_desc ac_desc;

};

static inline void wacom_schedule_work(struct wacom_wac *wacom_wac)

@@ -133,7 +135,7 @@ static inline void wacom_notify_battery(struct wacom_wac *wacom_wac)

{

struct wacom *wacom = container_of(wacom_wac, struct wacom, wacom_wac);

- power_supply_changed(&wacom->battery);

+ power_supply_changed(wacom->battery);

}

extern const struct hid_device_id wacom_ids[];

diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c

index 148949c0e039..ba9af470bea0 100644

--- a/drivers/hid/wacom_sys.c

+++ b/drivers/hid/wacom_sys.c

@@ -944,7 +944,7 @@ static int wacom_battery_get_property(struct power_supply *psy,

enum power_supply_property psp,

union power_supply_propval *val)

{

- struct wacom *wacom = container_of(psy, struct wacom, battery);

+ struct wacom *wacom = power_supply_get_drvdata(psy);

int ret = 0;

switch (psp) {

@@ -976,7 +976,7 @@ static int wacom_ac_get_property(struct power_supply *psy,

enum power_supply_property psp,

union power_supply_propval *val)

{

- struct wacom *wacom = container_of(psy, struct wacom, ac);

+ struct wacom *wacom = power_supply_get_drvdata(psy);

int ret = 0;

switch (psp) {

@@ -998,43 +998,46 @@ static int wacom_ac_get_property(struct power_supply *psy,

static int wacom_initialize_battery(struct wacom *wacom)

{

static atomic_t battery_no = ATOMIC_INIT(0);

- int error;

+ struct power_supply_config psy_cfg = { .drv_data = wacom, };

unsigned long n;

if (wacom->wacom_wac.features.quirks & WACOM_QUIRK_BATTERY) {

+ struct power_supply_desc *bat_desc = &wacom->battery_desc;

+ struct power_supply_desc *ac_desc = &wacom->ac_desc;

n = atomic_inc_return(&battery_no) - 1;

- wacom->battery.properties = wacom_battery_props;

- wacom->battery.num_properties = ARRAY_SIZE(wacom_battery_props);

- wacom->battery.get_property = wacom_battery_get_property;

+ bat_desc->properties = wacom_battery_props;

+ bat_desc->num_properties = ARRAY_SIZE(wacom_battery_props);

+ bat_desc->get_property = wacom_battery_get_property;

sprintf(wacom->wacom_wac.bat_name, "wacom_battery_%ld", n);

- wacom->battery.name = wacom->wacom_wac.bat_name;

- wacom->battery.type = POWER_SUPPLY_TYPE_BATTERY;

- wacom->battery.use_for_apm = 0;

+ bat_desc->name = wacom->wacom_wac.bat_name;

+ bat_desc->type = POWER_SUPPLY_TYPE_BATTERY;

+ bat_desc->use_for_apm = 0;

- wacom->ac.properties = wacom_ac_props;

- wacom->ac.num_properties = ARRAY_SIZE(wacom_ac_props);

- wacom->ac.get_property = wacom_ac_get_property;

+ ac_desc->properties = wacom_ac_props;

+ ac_desc->num_properties = ARRAY_SIZE(wacom_ac_props);

+ ac_desc->get_property = wacom_ac_get_property;

sprintf(wacom->wacom_wac.ac_name, "wacom_ac_%ld", n);

- wacom->ac.name = wacom->wacom_wac.ac_name;

- wacom->ac.type = POWER_SUPPLY_TYPE_MAINS;

- wacom->ac.use_for_apm = 0;

-

- error = power_supply_register(&wacom->hdev->dev,

- &wacom->battery, NULL);

- if (error)

- return error;

-

- power_supply_powers(&wacom->battery, &wacom->hdev->dev);

-

- error = power_supply_register(&wacom->hdev->dev, &wacom->ac,

- NULL);

- if (error) {

- power_supply_unregister(&wacom->battery);

- return error;

+ ac_desc->name = wacom->wacom_wac.ac_name;

+ ac_desc->type = POWER_SUPPLY_TYPE_MAINS;

+ ac_desc->use_for_apm = 0;

+

+ wacom->battery = power_supply_register(&wacom->hdev->dev,

+ &wacom->battery_desc, &psy_cfg);

+ if (IS_ERR(wacom->battery))

+ return PTR_ERR(wacom->battery);

+

+ power_supply_powers(wacom->battery, &wacom->hdev->dev);

+

+ wacom->ac = power_supply_register(&wacom->hdev->dev,

+ &wacom->ac_desc,

+ &psy_cfg);

+ if (IS_ERR(wacom->ac)) {

+ power_supply_unregister(wacom->battery);

+ return PTR_ERR(wacom->ac);

}

- power_supply_powers(&wacom->ac, &wacom->hdev->dev);

+ power_supply_powers(wacom->ac, &wacom->hdev->dev);

}

return 0;

@@ -1043,11 +1046,11 @@ static int wacom_initialize_battery(struct wacom *wacom)

static void wacom_destroy_battery(struct wacom *wacom)

{

if ((wacom->wacom_wac.features.quirks & WACOM_QUIRK_BATTERY) &&

- wacom->battery.dev) {

- power_supply_unregister(&wacom->battery);

- wacom->battery.dev = NULL;

- power_supply_unregister(&wacom->ac);

- wacom->ac.dev = NULL;

+ wacom->battery) {

+ power_supply_unregister(wacom->battery);

+ wacom->battery = NULL;

+ power_supply_unregister(wacom->ac);

+ wacom->ac = NULL;

}

}

diff --git a/drivers/platform/x86/compal-laptop.c b/drivers/platform/x86/compal-laptop.c

index 041a592fe753..b4e94471f3d5 100644

--- a/drivers/platform/x86/compal-laptop.c

+++ b/drivers/platform/x86/compal-laptop.c

@@ -177,7 +177,7 @@ struct compal_data{

unsigned char curr_pwm;

/* Power supply */

- struct power_supply psy;

+ struct power_supply *psy;

struct power_supply_info psy_info;

char bat_model_name[BAT_MODEL_NAME_LEN + 1];

char bat_manufacturer_name[BAT_MANUFACTURER_NAME_LEN + 1];

@@ -565,8 +565,7 @@ static int bat_get_property(struct power_supply *psy,

enum power_supply_property psp,

union power_supply_propval *val)

{

- struct compal_data *data;

- data = container_of(psy, struct compal_data, psy);

+ struct compal_data *data = power_supply_get_drvdata(psy);

switch (psp) {

case POWER_SUPPLY_PROP_STATUS:

@@ -875,13 +874,16 @@ static struct dmi_system_id __initdata compal_dmi_table[] = {

};

MODULE_DEVICE_TABLE(dmi, compal_dmi_table);

+static const struct power_supply_desc psy_bat_desc = {

+ .name = DRIVER_NAME,

+ .type = POWER_SUPPLY_TYPE_BATTERY,

+ .properties = compal_bat_properties,

+ .num_properties = ARRAY_SIZE(compal_bat_properties),

+ .get_property = bat_get_property,

+};

+

static void initialize_power_supply_data(struct compal_data *data)

{

- data->psy.name = DRIVER_NAME;

- data->psy.type = POWER_SUPPLY_TYPE_BATTERY;

- data->psy.properties = compal_bat_properties;

- data->psy.num_properties = ARRAY_SIZE(compal_bat_properties);

- data->psy.get_property = bat_get_property;

ec_read_sequence(BAT_MANUFACTURER_NAME_ADDR,

data->bat_manufacturer_name,

@@ -1011,6 +1013,7 @@ static int compal_probe(struct platform_device *pdev)

int err;

struct compal_data *data;

struct device *hwmon_dev;

+ struct power_supply_config psy_cfg = {};

if (!extra_features)

return 0;

@@ -1036,9 +1039,13 @@ static int compal_probe(struct platform_device *pdev)

/* Power supply */

initialize_power_supply_data(data);

- err = power_supply_register(&compal_device->dev, &data->psy, NULL);

- if (err < 0)

+ psy_cfg.drv_data = data;

+ data->psy = power_supply_register(&compal_device->dev, &psy_bat_desc,

+ &psy_cfg);

+ if (IS_ERR(data->psy)) {

+ err = PTR_ERR(data->psy);

goto remove;

+ }

platform_set_drvdata(pdev, data);

@@ -1073,7 +1080,7 @@ static int compal_remove(struct platform_device *pdev)

pwm_disable_control();

data = platform_get_drvdata(pdev);

- power_supply_unregister(&data->psy);

+ power_supply_unregister(data->psy);

sysfs_remove_group(&pdev->dev.kobj, &compal_platform_attr_group);

diff --git a/drivers/power/88pm860x_battery.c b/drivers/power/88pm860x_battery.c

index a99d7f2829a7..d49579b227ec 100644

--- a/drivers/power/88pm860x_battery.c

+++ b/drivers/power/88pm860x_battery.c

@@ -98,7 +98,7 @@ struct pm860x_battery_info {

struct i2c_client *i2c;

struct device *dev;

- struct power_supply battery;

+ struct power_supply *battery;

struct mutex lock;

int status;

int irq_cc;

@@ -798,9 +798,8 @@ out:

static void pm860x_external_power_changed(struct power_supply *psy)

{

- struct pm860x_battery_info *info;

+ struct pm860x_battery_info *info = dev_get_drvdata(psy->dev.parent);

- info = container_of(psy, struct pm860x_battery_info, battery);

calc_resistor(info);

}

@@ -808,7 +807,7 @@ static int pm860x_batt_get_prop(struct power_supply *psy,

enum power_supply_property psp,

union power_supply_propval *val)

{

- struct pm860x_battery_info *info = dev_get_drvdata(psy->dev->parent);

+ struct pm860x_battery_info *info = dev_get_drvdata(psy->dev.parent);

int data;

int ret;

@@ -874,7 +873,7 @@ static int pm860x_batt_set_prop(struct power_supply *psy,

enum power_supply_property psp,

const union power_supply_propval *val)

{

- struct pm860x_battery_info *info = dev_get_drvdata(psy->dev->parent);

+ struct pm860x_battery_info *info = dev_get_drvdata(psy->dev.parent);

switch (psp) {

case POWER_SUPPLY_PROP_CHARGE_FULL:

@@ -901,6 +900,16 @@ static enum power_supply_property pm860x_batt_props[] = {

POWER_SUPPLY_PROP_TEMP,

};

+static const struct power_supply_desc pm860x_battery_desc = {

+ .name = "battery-monitor",

+ .type = POWER_SUPPLY_TYPE_BATTERY,

+ .properties = pm860x_batt_props,

+ .num_properties = ARRAY_SIZE(pm860x_batt_props),

+ .get_property = pm860x_batt_get_prop,

+ .set_property = pm860x_batt_set_prop,

+ .external_power_changed = pm860x_external_power_changed,

+};

+

static int pm860x_battery_probe(struct platform_device *pdev)

{

struct pm860x_chip *chip = dev_get_drvdata(pdev->dev.parent);

@@ -936,14 +945,6 @@ static int pm860x_battery_probe(struct platform_device *pdev)

pm860x_init_battery(info);

- info->battery.name = "battery-monitor";

- info->battery.type = POWER_SUPPLY_TYPE_BATTERY;

- info->battery.properties = pm860x_batt_props;

- info->battery.num_properties = ARRAY_SIZE(pm860x_batt_props);

- info->battery.get_property = pm860x_batt_get_prop;

- info->battery.set_property = pm860x_batt_set_prop;

- info->battery.external_power_changed = pm860x_external_power_changed;

-

if (pdata && pdata->max_capacity)

info->max_capacity = pdata->max_capacity;

else

@@ -953,10 +954,11 @@ static int pm860x_battery_probe(struct platform_device *pdev)

else

info->resistor = 300; /* set default internal resistor */

- ret = power_supply_register(&pdev->dev, &info->battery, NULL);

- if (ret)

- return ret;

- info->battery.dev->parent = &pdev->dev;

+ info->battery = power_supply_register(&pdev->dev, &pm860x_battery_desc,

+ NULL);

+ if (IS_ERR(info->battery))

+ return PTR_ERR(info->battery);

+ info->battery->dev.parent = &pdev->dev;

ret = request_threaded_irq(info->irq_cc, NULL,

pm860x_coulomb_handler, IRQF_ONESHOT,

@@ -981,7 +983,7 @@ static int pm860x_battery_probe(struct platform_device *pdev)

out_coulomb:

free_irq(info->irq_cc, info);

out_reg:

- power_supply_unregister(&info->battery);

+ power_supply_unregister(info->battery);

return ret;

}

@@ -991,7 +993,7 @@ static int pm860x_battery_remove(struct platform_device *pdev)

free_irq(info->irq_batt, info);

free_irq(info->irq_cc, info);

- power_supply_unregister(&info->battery);

+ power_supply_unregister(info->battery);

return 0;

}

diff --git a/drivers/power/88pm860x_charger.c b/drivers/power/88pm860x_charger.c

index 98e31419d9cf..a7f32a5b2299 100644

--- a/drivers/power/88pm860x_charger.c

+++ b/drivers/power/88pm860x_charger.c

@@ -102,7 +102,7 @@ struct pm860x_charger_info {

struct i2c_client *i2c_8606;

struct device *dev;

- struct power_supply usb;

+ struct power_supply *usb;

struct mutex lock;

int irq_nums;

int irq[7];

@@ -415,7 +415,7 @@ static irqreturn_t pm860x_charger_handler(int irq, void *data)

set_charging_fsm(info);

- power_supply_changed(&info->usb);

+ power_supply_changed(info->usb);

out:

return IRQ_HANDLED;

}

@@ -587,8 +587,7 @@ static int pm860x_usb_get_prop(struct power_supply *psy,

enum power_supply_property psp,

union power_supply_propval *val)

{

- struct pm860x_charger_info *info =

- dev_get_drvdata(psy->dev->parent);

+ struct pm860x_charger_info *info = power_supply_get_drvdata(psy);

switch (psp) {

case POWER_SUPPLY_PROP_STATUS:

@@ -648,6 +647,14 @@ static struct pm860x_irq_desc {

{ "vchg", pm860x_vchg_handler },

};

+static const struct power_supply_desc pm860x_charger_desc = {

+ .name = "usb",

+ .type = POWER_SUPPLY_TYPE_USB,

+ .properties = pm860x_usb_props,

+ .num_properties = ARRAY_SIZE(pm860x_usb_props),

+ .get_property = pm860x_usb_get_prop,

+};

+

static int pm860x_charger_probe(struct platform_device *pdev)

{

struct pm860x_chip *chip = dev_get_drvdata(pdev->dev.parent);

@@ -689,16 +696,15 @@ static int pm860x_charger_probe(struct platform_device *pdev)

mutex_init(&info->lock);

platform_set_drvdata(pdev, info);

- info->usb.name = "usb";

- info->usb.type = POWER_SUPPLY_TYPE_USB;

- info->usb.properties = pm860x_usb_props;

- info->usb.num_properties = ARRAY_SIZE(pm860x_usb_props);

- info->usb.get_property = pm860x_usb_get_prop;

+ psy_cfg.drv_data = info;

psy_cfg.supplied_to = pm860x_supplied_to;

psy_cfg.num_supplicants = ARRAY_SIZE(pm860x_supplied_to);

- ret = power_supply_register(&pdev->dev, &info->usb, &psy_cfg);

- if (ret)

+ info->usb = power_supply_register(&pdev->dev, &pm860x_charger_desc,

+ &psy_cfg);

+ if (IS_ERR(info->usb)) {

+ ret = PTR_ERR(info->usb);

goto out;

+ }

pm860x_init_charger(info);

@@ -715,7 +721,7 @@ static int pm860x_charger_probe(struct platform_device *pdev)

return 0;

out_irq:

- power_supply_unregister(&info->usb);

+ power_supply_unregister(info->usb);

while (--i >= 0)

free_irq(info->irq, info);

out:

@@ -727,7 +733,7 @@ static int pm860x_charger_remove(struct platform_device *pdev)

struct pm860x_charger_info *info = platform_get_drvdata(pdev);

int i;

- power_supply_unregister(&info->usb);

+ power_supply_unregister(info->usb);

free_irq(info->irq[0], info);

for (i = 0; i < info->irq_nums; i++)

free_irq(info->irq, info);

diff --git a/drivers/power/ab8500_btemp.c b/drivers/power/ab8500_btemp.c

index 4d18464d6400..8f8044e1acf3 100644

--- a/drivers/power/ab8500_btemp.c

+++ b/drivers/power/ab8500_btemp.c

@@ -45,9 +45,6 @@

#define BTEMP_BATCTRL_CURR_SRC_60UA 60

#define BTEMP_BATCTRL_CURR_SRC_120UA 120

-#define to_ab8500_btemp_device_info(x) container_of((x), \

- struct ab8500_btemp, btemp_psy);

-

/**

* struct ab8500_btemp_interrupts - ab8500 interrupts

* @name: name of the interrupt

@@ -102,7 +99,7 @@ struct ab8500_btemp {

struct ab8500_gpadc *gpadc;

struct ab8500_fg *fg;

struct abx500_bm_data *bm;

- struct power_supply btemp_psy;

+ struct power_supply *btemp_psy;

struct ab8500_btemp_events events;

struct ab8500_btemp_ranges btemp_ranges;

struct workqueue_struct *btemp_wq;

@@ -654,14 +651,14 @@ static void ab8500_btemp_periodic_work(struct work_struct *work)

if ((di->bat_temp != di->prev_bat_temp) || !di->initialized) {

di->initialized = true;

di->bat_temp = bat_temp;

- power_supply_changed(&di->btemp_psy);

+ power_supply_changed(di->btemp_psy);

}

} else if (bat_temp < di->prev_bat_temp) {

di->bat_temp--;

- power_supply_changed(&di->btemp_psy);

+ power_supply_changed(di->btemp_psy);

} else if (bat_temp > di->prev_bat_temp) {

di->bat_temp++;

- power_supply_changed(&di->btemp_psy);

+ power_supply_changed(di->btemp_psy);

}

di->prev_bat_temp = bat_temp;

@@ -689,7 +686,7 @@ static irqreturn_t ab8500_btemp_batctrlindb_handler(int irq, void *_di)

dev_err(di->dev, "Battery removal detected!\n");

di->events.batt_rem = true;

- power_supply_changed(&di->btemp_psy);

+ power_supply_changed(di->btemp_psy);

return IRQ_HANDLED;

}

@@ -715,7 +712,7 @@ static irqreturn_t ab8500_btemp_templow_handler(int irq, void *_di)

di->events.btemp_high = false;

di->events.btemp_medhigh = false;

di->events.btemp_lowmed = false;

- power_supply_changed(&di->btemp_psy);

+ power_supply_changed(di->btemp_psy);

}

return IRQ_HANDLED;

@@ -738,7 +735,7 @@ static irqreturn_t ab8500_btemp_temphigh_handler(int irq, void *_di)

di->events.btemp_medhigh = false;

di->events.btemp_lowmed = false;

di->events.btemp_low = false;

- power_supply_changed(&di->btemp_psy);

+ power_supply_changed(di->btemp_psy);

return IRQ_HANDLED;

}

@@ -760,7 +757,7 @@ static irqreturn_t ab8500_btemp_lowmed_handler(int irq, void *_di)

di->events.btemp_medhigh = false;

di->events.btemp_high = false;

di->events.btemp_low = false;

- power_supply_changed(&di->btemp_psy);

+ power_supply_changed(di->btemp_psy);

return IRQ_HANDLED;

}

@@ -782,7 +779,7 @@ static irqreturn_t ab8500_btemp_medhigh_handler(int irq, void *_di)

di->events.btemp_lowmed = false;

di->events.btemp_high = false;

di->events.btemp_low = false;

- power_supply_changed(&di->btemp_psy);

+ power_supply_changed(di->btemp_psy);

return IRQ_HANDLED;

}

@@ -884,9 +881,7 @@ static int ab8500_btemp_get_property(struct power_supply *psy,

enum power_supply_property psp,

union power_supply_propval *val)

{

- struct ab8500_btemp *di;

-

- di = to_ab8500_btemp_device_info(psy);

+ struct ab8500_btemp *di = power_supply_get_drvdata(psy);

switch (psp) {

case POWER_SUPPLY_PROP_PRESENT:

@@ -919,14 +914,14 @@ static int ab8500_btemp_get_ext_psy_data(struct device *dev, void *data)

psy = (struct power_supply *)data;

ext = dev_get_drvdata(dev);

- di = to_ab8500_btemp_device_info(psy);

+ di = power_supply_get_drvdata(psy);

/*

* For all psy where the name of your driver

* appears in any supplied_to

*/

for (i = 0; i < ext->num_supplicants; i++) {

- if (!strcmp(ext->supplied_to, psy->name))

+ if (!strcmp(ext->supplied_to, psy->desc->name))

psy_found = true;

}

@@ -934,16 +929,16 @@ static int ab8500_btemp_get_ext_psy_data(struct device *dev, void *data)

return 0;

/* Go through all properties for the psy */

- for (j = 0; j < ext->num_properties; j++) {

+ for (j = 0; j < ext->desc->num_properties; j++) {

enum power_supply_property prop;

- prop = ext->properties[j];

+ prop = ext->desc->properties[j];

if (power_supply_get_property(ext, prop, &ret))

continue;

switch (prop) {

case POWER_SUPPLY_PROP_PRESENT:

- switch (ext->type) {

+ switch (ext->desc->type) {

case POWER_SUPPLY_TYPE_MAINS:

/* AC disconnected */

if (!ret.intval && di->events.ac_conn) {

@@ -990,10 +985,10 @@ static int ab8500_btemp_get_ext_psy_data(struct device *dev, void *data)

*/

static void ab8500_btemp_external_power_changed(struct power_supply *psy)

{

- struct ab8500_btemp *di = to_ab8500_btemp_device_info(psy);

+ struct ab8500_btemp *di = power_supply_get_drvdata(psy);

class_for_each_device(power_supply_class, NULL,

- &di->btemp_psy, ab8500_btemp_get_ext_psy_data);

+ di->btemp_psy, ab8500_btemp_get_ext_psy_data);

}

/* ab8500 btemp driver interrupts and their respective isr */

@@ -1044,7 +1039,7 @@ static int ab8500_btemp_remove(struct platform_device *pdev)

destroy_workqueue(di->btemp_wq);

flush_scheduled_work();

- power_supply_unregister(&di->btemp_psy);

+ power_supply_unregister(di->btemp_psy);

return 0;

}

@@ -1054,6 +1049,15 @@ static char *supply_interface[] = {

"ab8500_fg",

};

+static const struct power_supply_desc ab8500_btemp_desc = {

+ .name = "ab8500_btemp",

+ .type = POWER_SUPPLY_TYPE_BATTERY,

+ .properties = ab8500_btemp_props,

+ .num_properties = ARRAY_SIZE(ab8500_btemp_props),

+ .get_property = ab8500_btemp_get_property,

+ .external_power_changed = ab8500_btemp_external_power_changed,

+};

+

static int ab8500_btemp_probe(struct platform_device *pdev)

{

struct device_node *np = pdev->dev.of_node;

@@ -1090,17 +1094,9 @@ static int ab8500_btemp_probe(struct platform_device *pdev)

di->initialized = false;

- /* BTEMP supply */

- di->btemp_psy.name = "ab8500_btemp";

- di->btemp_psy.type = POWER_SUPPLY_TYPE_BATTERY;

- di->btemp_psy.properties = ab8500_btemp_props;

- di->btemp_psy.num_properties = ARRAY_SIZE(ab8500_btemp_props);

- di->btemp_psy.get_property = ab8500_btemp_get_property;

- di->btemp_psy.external_power_changed =

- ab8500_btemp_external_power_changed;

-

psy_cfg.supplied_to = supply_interface;

psy_cfg.num_supplicants = ARRAY_SIZE(supply_interface);

+ psy_cfg.drv_data = di;

/* Create a work queue for the btemp */

di->btemp_wq =

@@ -1141,9 +1137,11 @@ static int ab8500_btemp_probe(struct platform_device *pdev)

}

/* Register BTEMP power supply class */

- ret = power_supply_register(di->dev, &di->btemp_psy, &psy_cfg);

- if (ret) {

+ di->btemp_psy = power_supply_register(di->dev, &ab8500_btemp_desc,

+ &psy_cfg);

+ if (IS_ERR(di->btemp_psy)) {

dev_err(di->dev, "failed to register BTEMP psy\n");

+ ret = PTR_ERR(di->btemp_psy);

goto free_btemp_wq;

}

@@ -1172,7 +1170,7 @@ static int ab8500_btemp_probe(struct platform_device *pdev)

return ret;

free_irq:

- power_supply_unregister(&di->btemp_psy);

+ power_supply_unregister(di->btemp_psy);

/* We also have to free all successfully registered irqs */

for (i = i - 1; i >= 0; i--) {

diff --git a/drivers/power/ab8500_charger.c b/drivers/power/ab8500_charger.c

index f9eb7fff1d65..e388171f4e58 100644

--- a/drivers/power/ab8500_charger.c

+++ b/drivers/power/ab8500_charger.c

@@ -435,7 +435,7 @@ static void ab8500_charger_set_usb_connected(struct ab8500_charger *di,

if (!connected)

di->flags.vbus_drop_end = false;

- sysfs_notify(&di->usb_chg.psy.dev->kobj, NULL, "present");

+ sysfs_notify(&di->usb_chg.psy->dev.kobj, NULL, "present");

if (connected) {

mutex_lock(&di->charger_attached_mutex);

@@ -1516,7 +1516,7 @@ static int ab8500_charger_ac_en(struct ux500_charger *charger,

dev_dbg(di->dev, "%s Disabled AC charging\n", __func__);

}

- ab8500_power_supply_changed(di, &di->ac_chg.psy);

+ ab8500_power_supply_changed(di, di->ac_chg.psy);

return ret;

}

@@ -1672,7 +1672,7 @@ static int ab8500_charger_usb_en(struct ux500_charger *charger,

cancel_delayed_work(&di->check_vbat_work);

}

- ab8500_power_supply_changed(di, &di->usb_chg.psy);

+ ab8500_power_supply_changed(di, di->usb_chg.psy);

return ret;

}

@@ -1811,9 +1811,9 @@ static int ab8500_charger_watchdog_kick(struct ux500_charger *charger)

int ret;

struct ab8500_charger *di;

- if (charger->psy.type == POWER_SUPPLY_TYPE_MAINS)

+ if (charger->psy->desc->type == POWER_SUPPLY_TYPE_MAINS)

di = to_ab8500_charger_ac_device_info(charger);

- else if (charger->psy.type == POWER_SUPPLY_TYPE_USB)

+ else if (charger->psy->desc->type == POWER_SUPPLY_TYPE_USB)

di = to_ab8500_charger_usb_device_info(charger);

else

return -ENXIO;

@@ -1839,9 +1839,9 @@ static int ab8500_charger_update_charger_current(struct ux500_charger *charger,

int ret;

struct ab8500_charger *di;

- if (charger->psy.type == POWER_SUPPLY_TYPE_MAINS)

+ if (charger->psy->desc->type == POWER_SUPPLY_TYPE_MAINS)

di = to_ab8500_charger_ac_device_info(charger);

- else if (charger->psy.type == POWER_SUPPLY_TYPE_USB)

+ else if (charger->psy->desc->type == POWER_SUPPLY_TYPE_USB)

di = to_ab8500_charger_usb_device_info(charger);

else

retur

Show more