2
0
mirror of https://github.com/edk2-porting/linux-next.git synced 2024-12-23 12:43:55 +08:00

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>
This commit is contained in:
Sebastian Reichel 2018-09-28 11:39:16 +02:00 committed by Sebastian Reichel
parent b1f7ee898b
commit 348a3c079b

View 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);