mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Philip Rakity <prakity@marvell.com>
To: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Cc: Anton Vorontsov <cbouatmailru@gmail.com>,
	Kyungmin Park <kyungmin.park@samsung.com>,
	"myungjoo.ham@samsung.com" <myungjoo.ham@samsung.com>
Subject: [PATCH] power: max17042: divide by 0 Crash because r_sns init too late
Date: Fri, 12 Aug 2011 21:18:18 -0700	[thread overview]
Message-ID: <019FE779-4090-404F-9CE0-A2966384F14C@marvell.com> (raw)

On MMP2 brownstone divide by 0 error since probe sets r_sns
after calling power_supply_register.

Move the code up a few lines.  r_sns comes from the platform
data.

PROP_CURRENT_AVG and PROP_CURRENT divide the result by r_sns.

Signed-off-by: Philip Rakity <prakity@marvell.com>
---
 drivers/power/max17042_battery.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/power/max17042_battery.c b/drivers/power/max17042_battery.c
index 9f0183c..4245806 100644
--- a/drivers/power/max17042_battery.c
+++ b/drivers/power/max17042_battery.c
@@ -210,6 +210,9 @@ static int __devinit max17042_probe(struct i2c_client *client,
 	if (!chip->pdata->enable_current_sense)
 		chip->battery.num_properties -= 2;
 
+	if (chip->pdata->r_sns == 0)
+		chip->pdata->r_sns = MAX17042_DEFAULT_SNS_RESISTOR;
+
 	ret = power_supply_register(&client->dev, &chip->battery);
 	if (ret) {
 		dev_err(&client->dev, "failed: power supply register\n");
@@ -226,9 +229,6 @@ static int __devinit max17042_probe(struct i2c_client *client,
 		max17042_write_reg(client, MAX17042_CGAIN, 0x0000);
 		max17042_write_reg(client, MAX17042_MiscCFG, 0x0003);
 		max17042_write_reg(client, MAX17042_LearnCFG, 0x0007);
-	} else {
-		if (chip->pdata->r_sns == 0)
-			chip->pdata->r_sns = MAX17042_DEFAULT_SNS_RESISTOR;
 	}
 
 	return 0;
-- 
1.7.0.4



             reply	other threads:[~2011-08-13  4:18 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-13  4:18 Philip Rakity [this message]
2011-08-16  6:10 MyungJoo Ham
2011-08-19 16:49 ` Anton Vorontsov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=019FE779-4090-404F-9CE0-A2966384F14C@marvell.com \
    --to=prakity@marvell.com \
    --cc=cbouatmailru@gmail.com \
    --cc=kyungmin.park@samsung.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=myungjoo.ham@samsung.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®