diff options
author | Sebastian Reichel <sebastian.reichel@collabora.com> | 2018-09-28 11:39:16 +0200 |
---|---|---|
committer | Sebastian Reichel <sre@kernel.org> | 2018-12-13 00:16:08 +0100 |
commit | 348a3c079bfccbdf63767dfb5bb0521d2e889fa9 (patch) | |
tree | 9caf1639fb47953b6c923ee750a47e001ff0fd8f /drivers/power/supply | |
parent | b1f7ee898bdcad18e5a5c008ff7bf30ae9941265 (diff) | |
download | linux-348a3c079bfccbdf63767dfb5bb0521d2e889fa9.tar.bz2 |
power: supply: bq24190_charger: fix race-condition in sysfs registration
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>
Diffstat (limited to 'drivers/power/supply')
-rw-r--r-- | drivers/power/supply/bq24190_charger.c | 43 |
1 files changed, 8 insertions, 35 deletions
diff --git a/drivers/power/supply/bq24190_charger.c b/drivers/power/supply/bq24190_charger.c index effa7c3c21e6..cc0dfdc9e85a 100644 --- a/drivers/power/supply/bq24190_charger.c +++ b/drivers/power/supply/bq24190_charger.c @@ -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); |