]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
power: supply: bq24257: fix race-condition in sysfs registration
authorSebastian Reichel <sebastian.reichel@collabora.com>
Fri, 28 Sep 2018 09:46:04 +0000 (11:46 +0200)
committerSebastian Reichel <sre@kernel.org>
Wed, 12 Dec 2018 23:16:12 +0000 (00:16 +0100)
This registers custom sysfs properties using the native functionality
of the power-supply framework, which cleans up the code a bit and
fixes a race-condition. Before this patch the sysfs attributes were
not properly registered to udev.

Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
drivers/power/supply/bq24257_charger.c

index 6fc31bdc639bc54ac0fbd9008740d19912391330..673c7d6ff1a7462a0c64c4cf0f27fff09cd0cfa0 100644 (file)
@@ -845,7 +845,7 @@ static DEVICE_ATTR(high_impedance_enable, S_IWUSR | S_IRUGO,
 static DEVICE_ATTR(sysoff_enable, S_IWUSR | S_IRUGO,
                   bq24257_sysfs_show_enable, bq24257_sysfs_set_enable);
 
-static struct attribute *bq24257_charger_attr[] = {
+static struct attribute *bq24257_charger_sysfs_attrs[] = {
        &dev_attr_ovp_voltage.attr,
        &dev_attr_in_dpm_voltage.attr,
        &dev_attr_high_impedance_enable.attr,
@@ -853,14 +853,13 @@ static struct attribute *bq24257_charger_attr[] = {
        NULL,
 };
 
-static const struct attribute_group bq24257_attr_group = {
-       .attrs = bq24257_charger_attr,
-};
+ATTRIBUTE_GROUPS(bq24257_charger_sysfs);
 
 static int bq24257_power_supply_init(struct bq24257_device *bq)
 {
        struct power_supply_config psy_cfg = { .drv_data = bq, };
 
+       psy_cfg.attr_grp = bq24257_charger_sysfs_groups;
        psy_cfg.supplied_to = bq24257_charger_supplied_to;
        psy_cfg.num_supplicants = ARRAY_SIZE(bq24257_charger_supplied_to);
 
@@ -1084,12 +1083,6 @@ static int bq24257_probe(struct i2c_client *client,
                return ret;
        }
 
-       ret = sysfs_create_group(&bq->charger->dev.kobj, &bq24257_attr_group);
-       if (ret < 0) {
-               dev_err(dev, "Can't create sysfs entries\n");
-               return ret;
-       }
-
        return 0;
 }
 
@@ -1100,8 +1093,6 @@ static int bq24257_remove(struct i2c_client *client)
        if (bq->iilimit_autoset_enable)
                cancel_delayed_work_sync(&bq->iilimit_setup_work);
 
-       sysfs_remove_group(&bq->charger->dev.kobj, &bq24257_attr_group);
-
        bq24257_field_write(bq, F_RESET, 1); /* reset to defaults */
 
        return 0;