]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
power: supply: bq24190_charger: fix race-condition in sysfs registration
authorSebastian Reichel <sebastian.reichel@collabora.com>
Fri, 28 Sep 2018 09:39:16 +0000 (11:39 +0200)
committerSebastian Reichel <sre@kernel.org>
Wed, 12 Dec 2018 23:16:08 +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/bq24190_charger.c

index effa7c3c21e62192c986b8422de506a4f990be4f..cc0dfdc9e85ab5e7cb6534da908862fdd5bac2c4 100644 (file)
@@ -409,9 +409,7 @@ static struct bq24190_sysfs_field_info bq24190_sysfs_field_tbl[] = {
 static struct attribute *
        bq24190_sysfs_attrs[ARRAY_SIZE(bq24190_sysfs_field_tbl) + 1];
 
-static const struct attribute_group bq24190_sysfs_attr_group = {
-       .attrs = bq24190_sysfs_attrs,
-};
+ATTRIBUTE_GROUPS(bq24190_sysfs);
 
 static void bq24190_sysfs_init_attrs(void)
 {
@@ -498,26 +496,6 @@ static ssize_t bq24190_sysfs_store(struct device *dev,
 
        return count;
 }
-
-static int bq24190_sysfs_create_group(struct bq24190_dev_info *bdi)
-{
-       bq24190_sysfs_init_attrs();
-
-       return sysfs_create_group(&bdi->charger->dev.kobj,
-                       &bq24190_sysfs_attr_group);
-}
-
-static void bq24190_sysfs_remove_group(struct bq24190_dev_info *bdi)
-{
-       sysfs_remove_group(&bdi->charger->dev.kobj, &bq24190_sysfs_attr_group);
-}
-#else
-static int bq24190_sysfs_create_group(struct bq24190_dev_info *bdi)
-{
-       return 0;
-}
-
-static inline void bq24190_sysfs_remove_group(struct bq24190_dev_info *bdi) {}
 #endif
 
 #ifdef CONFIG_REGULATOR
@@ -1772,6 +1750,11 @@ static int bq24190_probe(struct i2c_client *client,
                goto out_pmrt;
        }
 
+#ifdef CONFIG_SYSFS
+       bq24190_sysfs_init_attrs();
+       charger_cfg.attr_grp = bq24190_sysfs_groups;
+#endif
+
        charger_cfg.drv_data = bdi;
        charger_cfg.of_node = dev->of_node;
        charger_cfg.supplied_to = bq24190_charger_supplied_to;
@@ -1813,12 +1796,6 @@ static int bq24190_probe(struct i2c_client *client,
        if (ret < 0)
                goto out_charger;
 
-       ret = bq24190_sysfs_create_group(bdi);
-       if (ret < 0) {
-               dev_err(dev, "Can't create sysfs entries\n");
-               goto out_charger;
-       }
-
        bdi->initialized = true;
 
        ret = devm_request_threaded_irq(dev, client->irq, NULL,
@@ -1827,12 +1804,12 @@ static int bq24190_probe(struct i2c_client *client,
                        "bq24190-charger", bdi);
        if (ret < 0) {
                dev_err(dev, "Can't set up irq handler\n");
-               goto out_sysfs;
+               goto out_charger;
        }
 
        ret = bq24190_register_vbus_regulator(bdi);
        if (ret < 0)
-               goto out_sysfs;
+               goto out_charger;
 
        enable_irq_wake(client->irq);
 
@@ -1841,9 +1818,6 @@ static int bq24190_probe(struct i2c_client *client,
 
        return 0;
 
-out_sysfs:
-       bq24190_sysfs_remove_group(bdi);
-
 out_charger:
        if (!IS_ERR_OR_NULL(bdi->battery))
                power_supply_unregister(bdi->battery);
@@ -1868,7 +1842,6 @@ static int bq24190_remove(struct i2c_client *client)
        }
 
        bq24190_register_reset(bdi);
-       bq24190_sysfs_remove_group(bdi);
        if (bdi->battery)
                power_supply_unregister(bdi->battery);
        power_supply_unregister(bdi->charger);