Gmane
Favicon
From: Anton Vorontsov <cbou@...>
Subject: Re: Some h2200 kernel patches
Newsgroups: gmane.comp.handhelds.linux.kernel
Date: 2007-04-24 08:55:20 GMT (2 years, 10 weeks, 1 day, 18 hours and 33 minutes ago)
On Tue, Apr 24, 2007 at 02:07:44AM +0200, Michal Panczyk wrote:
>  Just some test results :
> 
>  Battery power is properly checked - apm works fine . The only thing I
>  would like to add is that CONFIG_APM_POWER in not set in h2200
>  defconfig - so apm is not going to work out of the box.
> 
>  There are some problems with ac_power too. After plugging in the
>  charger the device suspends - it wakes up directly after
>  disconnecting.
>  I got some of the logread output :
> 
[...]
>  Division by zero in kernel.
>  [<c0025fec>] (dump_stack+0x0/0x14) from [<c002697c>] (__div0+0x18/0x20)
>  [<c0026964>] (__div0+0x0/0x20) from [<c00ef4ac>] (Ldiv0+0x8/0x10)
>  [<bf08e000>] (apm_battery_apm_get_power_status+0x0/0x49c [apm_power])
> 

Yup, it's in apm_power. I hope following patch will help.

[PATCH] apm_power: fix division by zero in kernel

Much thanks to Michal Panczyk <mpanczyk@...>

Signed-off-by: Anton Vorontsov <cbou@...>
---
 drivers/hwmon/battery/apm_power.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/drivers/hwmon/battery/apm_power.c b/drivers/hwmon/battery/apm_power.c
index 9263aaa..82fec8b 100644
--- a/drivers/hwmon/battery/apm_power.c
+++ b/drivers/hwmon/battery/apm_power.c
@@ -84,7 +84,9 @@ static int calculate_time(int status)
 	if (!current || !charge || !charge_empty)
 		return -1;

-	if (status == BATTERY_STATUS_CHARGING)
+	if (*current == 0)
+		return 0;
+	else if (status == BATTERY_STATUS_CHARGING)
 		return ((*charge - *charge_full) * 60L) / *current;
 	else
 		return -((*charge - *charge_empty) * 60L) / *current;
-- 
1.5.1.1-dirty