aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/power
diff options
context:
space:
mode:
authorVaishali Thakkar <vthakkar1994@gmail.com>2015-07-24 23:53:16 -0400
committerSebastian Reichel <sre@kernel.org>2015-07-27 10:09:53 -0400
commit71a5a508436332ac40f688ef06e61628f25f3e5b (patch)
tree09d494bd0e61891b0a0f7e437292c1f102b4ea89 /drivers/power
parent3309aa494186b0c5364d812ae000955262590655 (diff)
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>
Diffstat (limited to 'drivers/power')
-rw-r--r--drivers/power/bq24735-charger.c51
1 files changed, 13 insertions, 38 deletions
diff --git a/drivers/power/bq24735-charger.c b/drivers/power/bq24735-charger.c
index b0174379713c..eb2b3689de97 100644
--- a/drivers/power/bq24735-charger.c
+++ b/drivers/power/bq24735-charger.c
@@ -267,8 +267,9 @@ static int bq24735_charger_probe(struct i2c_client *client,
267 267
268 name = (char *)charger->pdata->name; 268 name = (char *)charger->pdata->name;
269 if (!name) { 269 if (!name) {
270 name = kasprintf(GFP_KERNEL, "bq24735@%s", 270 name = devm_kasprintf(&client->dev, GFP_KERNEL,
271 dev_name(&client->dev)); 271 "bq24735@%s",
272 dev_name(&client->dev));
272 if (!name) { 273 if (!name) {
273 dev_err(&client->dev, "Failed to alloc device name\n"); 274 dev_err(&client->dev, "Failed to alloc device name\n");
274 return -ENOMEM; 275 return -ENOMEM;
@@ -296,23 +297,21 @@ static int bq24735_charger_probe(struct i2c_client *client,
296 if (ret < 0) { 297 if (ret < 0) {
297 dev_err(&client->dev, "Failed to read manufacturer id : %d\n", 298 dev_err(&client->dev, "Failed to read manufacturer id : %d\n",
298 ret); 299 ret);
299 goto err_free_name; 300 return ret;
300 } else if (ret != 0x0040) { 301 } else if (ret != 0x0040) {
301 dev_err(&client->dev, 302 dev_err(&client->dev,
302 "manufacturer id mismatch. 0x0040 != 0x%04x\n", ret); 303 "manufacturer id mismatch. 0x0040 != 0x%04x\n", ret);
303 ret = -ENODEV; 304 return -ENODEV;
304 goto err_free_name;
305 } 305 }
306 306
307 ret = bq24735_read_word(client, BQ24735_DEVICE_ID); 307 ret = bq24735_read_word(client, BQ24735_DEVICE_ID);
308 if (ret < 0) { 308 if (ret < 0) {
309 dev_err(&client->dev, "Failed to read device id : %d\n", ret); 309 dev_err(&client->dev, "Failed to read device id : %d\n", ret);
310 goto err_free_name; 310 return ret;
311 } else if (ret != 0x000B) { 311 } else if (ret != 0x000B) {
312 dev_err(&client->dev, 312 dev_err(&client->dev,
313 "device id mismatch. 0x000b != 0x%04x\n", ret); 313 "device id mismatch. 0x000b != 0x%04x\n", ret);
314 ret = -ENODEV; 314 return -ENODEV;
315 goto err_free_name;
316 } 315 }
317 316
318 if (gpio_is_valid(charger->pdata->status_gpio)) { 317 if (gpio_is_valid(charger->pdata->status_gpio)) {
@@ -331,7 +330,7 @@ static int bq24735_charger_probe(struct i2c_client *client,
331 ret = bq24735_config_charger(charger); 330 ret = bq24735_config_charger(charger);
332 if (ret < 0) { 331 if (ret < 0) {
333 dev_err(&client->dev, "failed in configuring charger"); 332 dev_err(&client->dev, "failed in configuring charger");
334 goto err_free_name; 333 return ret;
335 } 334 }
336 335
337 /* check for AC adapter presence */ 336 /* check for AC adapter presence */
@@ -339,17 +338,17 @@ static int bq24735_charger_probe(struct i2c_client *client,
339 ret = bq24735_enable_charging(charger); 338 ret = bq24735_enable_charging(charger);
340 if (ret < 0) { 339 if (ret < 0) {
341 dev_err(&client->dev, "Failed to enable charging\n"); 340 dev_err(&client->dev, "Failed to enable charging\n");
342 goto err_free_name; 341 return ret;
343 } 342 }
344 } 343 }
345 344
346 charger->charger = power_supply_register(&client->dev, supply_desc, 345 charger->charger = devm_power_supply_register(&client->dev, supply_desc,
347 &psy_cfg); 346 &psy_cfg);
348 if (IS_ERR(charger->charger)) { 347 if (IS_ERR(charger->charger)) {
349 ret = PTR_ERR(charger->charger); 348 ret = PTR_ERR(charger->charger);
350 dev_err(&client->dev, "Failed to register power supply: %d\n", 349 dev_err(&client->dev, "Failed to register power supply: %d\n",
351 ret); 350 ret);
352 goto err_free_name; 351 return ret;
353 } 352 }
354 353
355 if (client->irq) { 354 if (client->irq) {
@@ -364,34 +363,11 @@ static int bq24735_charger_probe(struct i2c_client *client,
364 dev_err(&client->dev, 363 dev_err(&client->dev,
365 "Unable to register IRQ %d err %d\n", 364 "Unable to register IRQ %d err %d\n",
366 client->irq, ret); 365 client->irq, ret);
367 goto err_unregister_supply; 366 return ret;
368 } 367 }
369 } 368 }
370 369
371 return 0; 370 return 0;
372err_unregister_supply:
373 power_supply_unregister(charger->charger);
374err_free_name:
375 if (name != charger->pdata->name)
376 kfree(name);
377
378 return ret;
379}
380
381static int bq24735_charger_remove(struct i2c_client *client)
382{
383 struct bq24735 *charger = i2c_get_clientdata(client);
384
385 if (charger->client->irq)
386 devm_free_irq(&charger->client->dev, charger->client->irq,
387 &charger->charger);
388
389 power_supply_unregister(charger->charger);
390
391 if (charger->charger_desc.name != charger->pdata->name)
392 kfree(charger->charger_desc.name);
393
394 return 0;
395} 371}
396 372
397static const struct i2c_device_id bq24735_charger_id[] = { 373static const struct i2c_device_id bq24735_charger_id[] = {
@@ -412,7 +388,6 @@ static struct i2c_driver bq24735_charger_driver = {
412 .of_match_table = bq24735_match_ids, 388 .of_match_table = bq24735_match_ids,
413 }, 389 },
414 .probe = bq24735_charger_probe, 390 .probe = bq24735_charger_probe,
415 .remove = bq24735_charger_remove,
416 .id_table = bq24735_charger_id, 391 .id_table = bq24735_charger_id,
417}; 392};
418 393