Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

power/ltc2941-battery-gauge.c: Use the devicetree node name as supply name

Make it possible to set the name of the supply from the devicetree.
Like other power supply drivers just use the node name. This makes
the code smaller as well, as it doesn't need to allocate memory to
hold the name and allocate a unique ID.

Signed-off-by: Mike Looijmans <mike.looijmans@topic.nl>
Signed-off-by: Sebastian Reichel <sre@kernel.org>

authored by

Mike Looijmans and committed by
Sebastian Reichel
377b641a 325b50aa

+8 -46
+8 -46
drivers/power/ltc2941-battery-gauge.c
··· 14 14 #include <linux/swab.h> 15 15 #include <linux/i2c.h> 16 16 #include <linux/delay.h> 17 - #include <linux/idr.h> 18 17 #include <linux/power_supply.h> 19 18 #include <linux/slab.h> 20 19 ··· 62 63 struct power_supply_desc supply_desc; /* Supply description */ 63 64 struct delayed_work work; /* Work scheduler */ 64 65 int num_regs; /* Number of registers (chip type) */ 65 - int id; /* Identifier of ltc294x chip */ 66 66 int charge; /* Last charge register content */ 67 67 int r_sense; /* mOhm */ 68 68 int Qlsb; /* nAh */ 69 69 }; 70 - 71 - static DEFINE_IDR(ltc294x_id); 72 - static DEFINE_MUTEX(ltc294x_lock); 73 70 74 71 static inline int convert_bin_to_uAh( 75 72 const struct ltc294x_info *info, int Q) ··· 366 371 367 372 cancel_delayed_work(&info->work); 368 373 power_supply_unregister(info->supply); 369 - kfree(info->supply_desc.name); 370 - mutex_lock(&ltc294x_lock); 371 - idr_remove(&ltc294x_id, info->id); 372 - mutex_unlock(&ltc294x_lock); 373 374 return 0; 374 375 } 375 376 ··· 375 384 struct power_supply_config psy_cfg = {}; 376 385 struct ltc294x_info *info; 377 386 int ret; 378 - int num; 379 387 u32 prescaler_exp; 380 388 s32 r_sense; 381 389 struct device_node *np; 382 390 383 - mutex_lock(&ltc294x_lock); 384 - ret = idr_alloc(&ltc294x_id, client, 0, 0, GFP_KERNEL); 385 - mutex_unlock(&ltc294x_lock); 386 - if (ret < 0) 387 - goto fail_id; 388 - 389 - num = ret; 390 - 391 391 info = devm_kzalloc(&client->dev, sizeof(*info), GFP_KERNEL); 392 - if (info == NULL) { 393 - ret = -ENOMEM; 394 - goto fail_info; 395 - } 392 + if (info == NULL) 393 + return -ENOMEM; 396 394 397 395 i2c_set_clientdata(client, info); 398 396 399 - info->num_regs = id->driver_data; 400 - info->supply_desc.name = kasprintf(GFP_KERNEL, "%s-%d", client->name, 401 - num); 402 - if (!info->supply_desc.name) { 403 - ret = -ENOMEM; 404 - goto fail_name; 405 - } 406 - 407 397 np = of_node_get(client->dev.of_node); 398 + 399 + info->num_regs = id->driver_data; 400 + info->supply_desc.name = np->name; 408 401 409 402 /* r_sense can be negative, when sense+ is connected to the battery 410 403 * instead of the sense-. This results in reversed measurements. */ ··· 396 421 if (ret < 0) { 397 422 dev_err(&client->dev, 398 423 "Could not find lltc,resistor-sense in devicetree\n"); 399 - goto fail_name; 424 + return ret; 400 425 } 401 426 info->r_sense = r_sense; 402 427 ··· 421 446 } 422 447 423 448 info->client = client; 424 - info->id = num; 425 449 info->supply_desc.type = POWER_SUPPLY_TYPE_BATTERY; 426 450 info->supply_desc.properties = ltc294x_properties; 427 451 if (info->num_regs >= LTC294X_REG_TEMPERATURE_LSB) ··· 447 473 ret = ltc294x_reset(info, prescaler_exp); 448 474 if (ret < 0) { 449 475 dev_err(&client->dev, "Communication with chip failed\n"); 450 - goto fail_comm; 476 + return ret; 451 477 } 452 478 453 479 info->supply = power_supply_register(&client->dev, &info->supply_desc, 454 480 &psy_cfg); 455 481 if (IS_ERR(info->supply)) { 456 482 dev_err(&client->dev, "failed to register ltc2941\n"); 457 - ret = PTR_ERR(info->supply); 458 - goto fail_register; 483 + return PTR_ERR(info->supply); 459 484 } else { 460 485 schedule_delayed_work(&info->work, LTC294X_WORK_DELAY * HZ); 461 486 } 462 487 463 488 return 0; 464 - 465 - fail_register: 466 - kfree(info->supply_desc.name); 467 - fail_comm: 468 - fail_name: 469 - fail_info: 470 - mutex_lock(&ltc294x_lock); 471 - idr_remove(&ltc294x_id, num); 472 - mutex_unlock(&ltc294x_lock); 473 - fail_id: 474 - return ret; 475 489 } 476 490 477 491 #ifdef CONFIG_PM_SLEEP