[PATCH 5/5] power: sbs-battery: Change power supply name

Rhyland Klein rklein at nvidia.com
Tue Dec 6 10:58:07 EST 2011


The power supply name used to be fixed as "battery". This change allows
for multiple batteries by generating the name rather than using a fixed
value.

Signed-off-by: Rhyland Klein <rklein at nvidia.com>
---
 drivers/power/sbs-battery.c |   21 ++++++++++++++++++---
 1 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/drivers/power/sbs-battery.c b/drivers/power/sbs-battery.c
index 761500c..9ee6903 100644
--- a/drivers/power/sbs-battery.c
+++ b/drivers/power/sbs-battery.c
@@ -150,6 +150,7 @@ struct sbs_info {
 	int				poll_time;
 	struct delayed_work		work;
 	int				ignore_changes;
+	char				*name;
 };
 
 static int sbs_read_word_data(struct i2c_client *client, u8 address)
@@ -681,15 +682,25 @@ static int __devinit sbs_probe(struct i2c_client *client,
 	struct sbs_platform_data *pdata = client->dev.platform_data;
 	int rc;
 	int irq;
+	char *name;
 
-	chip = kzalloc(sizeof(struct sbs_info), GFP_KERNEL);
-	if (!chip)
+	name = kasprintf(GFP_KERNEL, "%s-%s", "sbs", dev_name(&client->dev));
+	if (!name) {
+		dev_err(&client->dev, "Failed to allocate device name\n");
 		return -ENOMEM;
+	}
+
+	chip = kzalloc(sizeof(struct sbs_info), GFP_KERNEL);
+	if (!chip) {
+		rc = -ENOMEM;
+		goto exit_free_name;
+	}
 
 	chip->client = client;
 	chip->enable_detection = false;
 	chip->gpio_detect = false;
-	chip->power_supply.name = "battery";
+	chip->name = name;
+	chip->power_supply.name = name;
 	chip->power_supply.type = POWER_SUPPLY_TYPE_BATTERY;
 	chip->power_supply.properties = sbs_properties;
 	chip->power_supply.num_properties = ARRAY_SIZE(sbs_properties);
@@ -774,6 +785,9 @@ exit_psupply:
 
 	kfree(chip);
 
+exit_free_name:
+	kfree(name);
+
 	return rc;
 }
 
@@ -790,6 +804,7 @@ static int __devexit sbs_remove(struct i2c_client *client)
 
 	cancel_delayed_work_sync(&chip->work);
 
+	kfree(chip->name);
 	kfree(chip);
 	chip = NULL;
 
-- 
1.7.0.4



More information about the devicetree-discuss mailing list