Commit 54d29ad33e3483bcc7ca433a21cf294854e5154a

Authored by Greg Kroah-Hartman
1 parent 0b00fc5851

Power Supply: fix race in device_create

There is a race from when a device is created with device_create() and
then the drvdata is set with a call to dev_set_drvdata() in which a
sysfs file could be open, yet the drvdata will be NULL, causing all
sorts of bad things to happen.

This patch fixes the problem by using the new function,
device_create_drvdata().

Cc: Kay Sievers <kay.sievers@vrfy.org>
Cc: Anton Vorontsov <cbou@mail.ru>
Cc: David Woodhouse <dwmw2@infradead.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

Showing 1 changed file with 2 additions and 4 deletions Side-by-side Diff

drivers/power/power_supply_core.c
... ... @@ -91,14 +91,12 @@
91 91 {
92 92 int rc = 0;
93 93  
94   - psy->dev = device_create(power_supply_class, parent, 0,
95   - "%s", psy->name);
  94 + psy->dev = device_create_drvdata(power_supply_class, parent, 0,
  95 + psy, "%s", psy->name);
96 96 if (IS_ERR(psy->dev)) {
97 97 rc = PTR_ERR(psy->dev);
98 98 goto dev_create_failed;
99 99 }
100   -
101   - dev_set_drvdata(psy->dev, psy);
102 100  
103 101 INIT_WORK(&psy->changed_work, power_supply_changed_work);
104 102