power_supply: Use wrappers to avoid races when registering power supply
authorKrzysztof Kozlowski <k.kozlowski@samsung.com>
Tue, 19 May 2015 07:16:29 +0000 (16:16 +0900)
committerSebastian Reichel <sre@kernel.org>
Sat, 23 May 2015 18:06:19 +0000 (20:06 +0200)
commita9f6a19b57c4f37dfd6aa322071948245fecbd91
tree8a9534550a92c9a0de9da18026d447bcc8e6eb06
parent9f6cd98fc3c64ebcebf63c04f16246f79bcc4c70
power_supply: Use wrappers to avoid races when registering power supply

Use wrappers over get_property() and set_property() internally in power
supply and for sysfs interface. The wrappers provide safe access if
power supply is not yet registered or t is being destroyed.

In case of syfs the theoretical race could happen between ending of
driver's probe and parallel sysfs access:
some_driver_probe()                    userspace
====================================   ===========================
  drv->psy = power_supply_register()
    device_add()
      sysfs entries are created
    atomic_inc(&psy->use_cnt);
                                       store on sysfs attributes
                                         drv->set_property()
                                           dereference of drv->psy
  drv->psy = returned psy;

For leds the race could happen between power supply being destroyed and
ongoing power_supply_changed_work().

Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
Signed-off-by: Sebastian Reichel <sre@kernel.org>
drivers/power/power_supply_leds.c
drivers/power/power_supply_sysfs.c