Skip to content

Commit

Permalink
power_supply: Use wrappers to avoid races when registering power supply
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Krzysztof Kozlowski authored and Sebastian Reichel committed May 23, 2015
1 parent 9f6cd98 commit a9f6a19
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions drivers/power/power_supply_leds.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ static void power_supply_update_bat_leds(struct power_supply *psy)
unsigned long delay_on = 0;
unsigned long delay_off = 0;

if (psy->desc->get_property(psy, POWER_SUPPLY_PROP_STATUS, &status))
if (power_supply_get_property(psy, POWER_SUPPLY_PROP_STATUS, &status))
return;

dev_dbg(&psy->dev, "%s %d\n", __func__, status.intval);
Expand Down Expand Up @@ -115,7 +115,7 @@ static void power_supply_update_gen_leds(struct power_supply *psy)
{
union power_supply_propval online;

if (psy->desc->get_property(psy, POWER_SUPPLY_PROP_ONLINE, &online))
if (power_supply_get_property(psy, POWER_SUPPLY_PROP_ONLINE, &online))
return;

dev_dbg(&psy->dev, "%s %d\n", __func__, online.intval);
Expand Down
2 changes: 1 addition & 1 deletion drivers/power/power_supply_sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ static ssize_t power_supply_store_property(struct device *dev,

value.intval = long_val;

ret = psy->desc->set_property(psy, off, &value);
ret = power_supply_set_property(psy, off, &value);
if (ret < 0)
return ret;

Expand Down

0 comments on commit a9f6a19

Please sign in to comment.