Skip to contentSkip to conversation

sbs-battery: probe should try talking to the device

PATCH Applied Olof Johansson 3 participants 3 messages Sep 6, 2012 – Sep 20, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sbs-battery: probe should try talking to the device

Turns out this driver doesn't actually try talking to the device at probe time, so if it's incorrectly configured in the device tree or platform data (or if the battery has been removed from the system), then probe will succeed and every access will sit there and time out. The end result is a possibly laggy system that thinks it has a battery but can never read status, which isn't very useful.

Instead, just read any register (I chose status) at probe, and if that fails, don't register the device.

---
 drivers/power/sbs-battery.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/power/sbs-battery.c +10 -0
index a65e8f5..2f24253 100644
@@ -760,6 +760,16 @@ static int __devinit sbs_probe(struct i2c_client *client,
 
 skip_gpio:
 
+	/* Before we register, we need to make sure we can actually talk
+	 * to the battery.
+	 */
+	rc = sbs_read_word_data(client, sbs_data[REG_STATUS].addr);
+	if (rc < 0) {
+		dev_err(&client->dev, "%s: Failed to get device status\n",
+			__func__);
+		goto exit_psupply;
+	}
+
 	rc = power_supply_register(&client->dev, &chip->power_supply);
 	if (rc) {
 		dev_err(&client->dev,
Signature · 1 line
1.7.10.1.488.g05fbf7a
Acked-by on v1 1/1
#1 lore raw
Quoted 27 lines · Olof Johansson

Turns out this driver doesn't actually try talking to the device at probe time, so if it's incorrectly configured in the device tree or platform data (or if the battery has been removed from the system), then probe will succeed and every access will sit there and time out. The end result is a possibly laggy system that thinks it has a battery but can never read status, which isn't very useful.

Instead, just read any register (I chose status) at probe, and if that fails, don't register the device.

---
  drivers/power/sbs-battery.c | 10 ++++++++++
  1 file changed, 10 insertions(+)
drivers/power/sbs-battery.c +3 -0
index a65e8f5..2f24253 100644
@@ -760,6 +760,16 @@ static int __devinit sbs_probe(struct i2c_client *client,
 
  skip_gpio:
 
+	/* Before we register, we need to make sure we can actually talk
+	 * to the battery.
+	 */

drivers/power/sbs-battery.c static int __devinit sbs_probe(struct i2c_client *client, · line 775

Quoted 10 lines
drivers/power/sbs-battery.c +7 -0
+	rc = sbs_read_word_data(client, sbs_data[REG_STATUS].addr);
+	if (rc < 0) {
+		dev_err(&client->dev, "%s: Failed to get device status\n",
+			__func__);
+		goto exit_psupply;
+	}
+
  	rc = power_supply_register(&client->dev, &chip->power_supply);
  	if (rc) {
  		dev_err(&client->dev,
Signature · 1 line
nvpublic
#2 lore raw
Quoted 12 lines · Rhyland Klein
Quoted 11 lines · Olof Johansson

Turns out this driver doesn't actually try talking to the device at probe time, so if it's incorrectly configured in the device tree or platform data (or if the battery has been removed from the system), then probe will succeed and every access will sit there and time out. The end result is a possibly laggy system that thinks it has a battery but can never read status, which isn't very useful.

Instead, just read any register (I chose status) at probe, and if that fails, don't register the device.

[...]

Quoted 1 line

Applied, thank you folks!