]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
power_supply: sysfs: Bring back write to writeable properties
authorKrzysztof Kozlowski <k.kozlowski@samsung.com>
Mon, 8 Jun 2015 01:09:48 +0000 (10:09 +0900)
committerSebastian Reichel <sre@kernel.org>
Wed, 10 Jun 2015 14:10:59 +0000 (16:10 +0200)
The fix for NULL pointer exception related to calling uevent for not
finished probe caused to set all writeable properties as non-writeable.
This was caused by checking if property is writeable before the initial
increase of power supply usage counter and in the same time using
wrapper over property_is_writeable(). The wrapper returns ENODEV if the
usage counter is still 0.

The call trace looked like:
  device probe:
    power_supply_register()
      use_cnt = 0;
      device_add()
        create sysfs entries
          power_supply_attr_is_visible()
            power_supply_property_is_writeable()
              if (use_cnt == 0) return -ENODEV;
      use_cnt++;

Replace the usage of wrapper with direct call to property_is_writeable()
from driver. This should be safe call during device probe because
implementations of this callback just return 0/1 for different
properties and they do not access any of the driver's internal data.

Fixes: 8e59c7f23410 ("power_supply: Fix NULL pointer dereference during bq27x00_battery probe")
Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
Signed-off-by: Sebastian Reichel <sre@kernel.org>
drivers/power/power_supply_sysfs.c
include/linux/power_supply.h

index af026806cba5e2b16e94951bbc8205b68506051e..ed2d7fd0c734dc47fc192fe7cccf825c63e1a35b 100644 (file)
@@ -223,7 +223,7 @@ static umode_t power_supply_attr_is_visible(struct kobject *kobj,
 
                if (property == attrno) {
                        if (psy->desc->property_is_writeable &&
-                           power_supply_property_is_writeable(psy, property) > 0)
+                           psy->desc->property_is_writeable(psy, property) > 0)
                                mode |= S_IWUSR;
 
                        return mode;
index a80f1fd01ddb630fc1f5a32cf749ea8f87228d65..0395bcb18ddb8613366a38300baba52f346333e9 100644 (file)
@@ -206,6 +206,11 @@ struct power_supply_desc {
        int (*set_property)(struct power_supply *psy,
                            enum power_supply_property psp,
                            const union power_supply_propval *val);
+       /*
+        * property_is_writeable() will be called during registration
+        * of power supply. If this happens during device probe then it must
+        * not access internal data of device (because probe did not end).
+        */
        int (*property_is_writeable)(struct power_supply *psy,
                                     enum power_supply_property psp);
        void (*external_power_changed)(struct power_supply *psy);