power_supply: bq24735: Convert to using managed resources
Use managed resource functions like devm_kasprintf and devm_power_supply_register in bq24735_charger_probe. To be compatible with the change, replace various gotos by direct returns and drop unneeded labels. Also, remove bq24735_charger_remove as it is now redundant. Signed-off-by: Vaishali Thakkar <vthakkar1994@gmail.com> Signed-off-by: Sebastian Reichel <sre@kernel.org>
This commit is contained in:
parent
3309aa4941
commit
71a5a50843
|
@ -267,8 +267,9 @@ static int bq24735_charger_probe(struct i2c_client *client,
|
||||||
|
|
||||||
name = (char *)charger->pdata->name;
|
name = (char *)charger->pdata->name;
|
||||||
if (!name) {
|
if (!name) {
|
||||||
name = kasprintf(GFP_KERNEL, "bq24735@%s",
|
name = devm_kasprintf(&client->dev, GFP_KERNEL,
|
||||||
dev_name(&client->dev));
|
"bq24735@%s",
|
||||||
|
dev_name(&client->dev));
|
||||||
if (!name) {
|
if (!name) {
|
||||||
dev_err(&client->dev, "Failed to alloc device name\n");
|
dev_err(&client->dev, "Failed to alloc device name\n");
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
@ -296,23 +297,21 @@ static int bq24735_charger_probe(struct i2c_client *client,
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
dev_err(&client->dev, "Failed to read manufacturer id : %d\n",
|
dev_err(&client->dev, "Failed to read manufacturer id : %d\n",
|
||||||
ret);
|
ret);
|
||||||
goto err_free_name;
|
return ret;
|
||||||
} else if (ret != 0x0040) {
|
} else if (ret != 0x0040) {
|
||||||
dev_err(&client->dev,
|
dev_err(&client->dev,
|
||||||
"manufacturer id mismatch. 0x0040 != 0x%04x\n", ret);
|
"manufacturer id mismatch. 0x0040 != 0x%04x\n", ret);
|
||||||
ret = -ENODEV;
|
return -ENODEV;
|
||||||
goto err_free_name;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = bq24735_read_word(client, BQ24735_DEVICE_ID);
|
ret = bq24735_read_word(client, BQ24735_DEVICE_ID);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
dev_err(&client->dev, "Failed to read device id : %d\n", ret);
|
dev_err(&client->dev, "Failed to read device id : %d\n", ret);
|
||||||
goto err_free_name;
|
return ret;
|
||||||
} else if (ret != 0x000B) {
|
} else if (ret != 0x000B) {
|
||||||
dev_err(&client->dev,
|
dev_err(&client->dev,
|
||||||
"device id mismatch. 0x000b != 0x%04x\n", ret);
|
"device id mismatch. 0x000b != 0x%04x\n", ret);
|
||||||
ret = -ENODEV;
|
return -ENODEV;
|
||||||
goto err_free_name;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gpio_is_valid(charger->pdata->status_gpio)) {
|
if (gpio_is_valid(charger->pdata->status_gpio)) {
|
||||||
|
@ -331,7 +330,7 @@ static int bq24735_charger_probe(struct i2c_client *client,
|
||||||
ret = bq24735_config_charger(charger);
|
ret = bq24735_config_charger(charger);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
dev_err(&client->dev, "failed in configuring charger");
|
dev_err(&client->dev, "failed in configuring charger");
|
||||||
goto err_free_name;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check for AC adapter presence */
|
/* check for AC adapter presence */
|
||||||
|
@ -339,17 +338,17 @@ static int bq24735_charger_probe(struct i2c_client *client,
|
||||||
ret = bq24735_enable_charging(charger);
|
ret = bq24735_enable_charging(charger);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
dev_err(&client->dev, "Failed to enable charging\n");
|
dev_err(&client->dev, "Failed to enable charging\n");
|
||||||
goto err_free_name;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
charger->charger = power_supply_register(&client->dev, supply_desc,
|
charger->charger = devm_power_supply_register(&client->dev, supply_desc,
|
||||||
&psy_cfg);
|
&psy_cfg);
|
||||||
if (IS_ERR(charger->charger)) {
|
if (IS_ERR(charger->charger)) {
|
||||||
ret = PTR_ERR(charger->charger);
|
ret = PTR_ERR(charger->charger);
|
||||||
dev_err(&client->dev, "Failed to register power supply: %d\n",
|
dev_err(&client->dev, "Failed to register power supply: %d\n",
|
||||||
ret);
|
ret);
|
||||||
goto err_free_name;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (client->irq) {
|
if (client->irq) {
|
||||||
|
@ -364,33 +363,10 @@ static int bq24735_charger_probe(struct i2c_client *client,
|
||||||
dev_err(&client->dev,
|
dev_err(&client->dev,
|
||||||
"Unable to register IRQ %d err %d\n",
|
"Unable to register IRQ %d err %d\n",
|
||||||
client->irq, ret);
|
client->irq, ret);
|
||||||
goto err_unregister_supply;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
|
||||||
err_unregister_supply:
|
|
||||||
power_supply_unregister(charger->charger);
|
|
||||||
err_free_name:
|
|
||||||
if (name != charger->pdata->name)
|
|
||||||
kfree(name);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int bq24735_charger_remove(struct i2c_client *client)
|
|
||||||
{
|
|
||||||
struct bq24735 *charger = i2c_get_clientdata(client);
|
|
||||||
|
|
||||||
if (charger->client->irq)
|
|
||||||
devm_free_irq(&charger->client->dev, charger->client->irq,
|
|
||||||
&charger->charger);
|
|
||||||
|
|
||||||
power_supply_unregister(charger->charger);
|
|
||||||
|
|
||||||
if (charger->charger_desc.name != charger->pdata->name)
|
|
||||||
kfree(charger->charger_desc.name);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -412,7 +388,6 @@ static struct i2c_driver bq24735_charger_driver = {
|
||||||
.of_match_table = bq24735_match_ids,
|
.of_match_table = bq24735_match_ids,
|
||||||
},
|
},
|
||||||
.probe = bq24735_charger_probe,
|
.probe = bq24735_charger_probe,
|
||||||
.remove = bq24735_charger_remove,
|
|
||||||
.id_table = bq24735_charger_id,
|
.id_table = bq24735_charger_id,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue