X-Git-Url: http://olsr.org/git/?p=olsrd.git;a=blobdiff_plain;f=src%2Flinux%2Fapm.c;h=7c38447ef948d04af4584354466576bea74293ae;hp=e0436e6e332003e59c1bc3071f7b5acbb6b0585b;hb=545269ae0ef5aeb17289f4b5efa26427f7b28b6b;hpb=351a64a5530d732046455ba70baecb3ea416e1cc diff --git a/src/linux/apm.c b/src/linux/apm.c index e0436e6e..7c38447e 100644 --- a/src/linux/apm.c +++ b/src/linux/apm.c @@ -218,7 +218,6 @@ apm_read_acpi(struct olsr_apm_info *ainfo) FILE *fd; int bat_max = 5000; /* Find some sane value */ int bat_val = 0; - int result; /* reporbe in case ac status changed */ fd_index = acpi_probe(); @@ -271,14 +270,19 @@ apm_read_acpi(struct olsr_apm_info *ainfo) ainfo->ac_line_status = ac_power_on ? OLSR_AC_POWERED : OLSR_BATTERY_POWERED; + /* sanitise ACPI battery data */ + bat_max = abs(bat_max); + bat_val = abs(bat_val); + if (bat_val > bat_max) { + bat_val = bat_max; + } + if (bat_max == 0) { /* protection against stupid acpi data */ ainfo->battery_percentage = 0; } else { - result = bat_val * 100 / bat_max; - - ainfo->battery_percentage = result > 100 ? 100 : result; + ainfo->battery_percentage = (bat_val >= bat_max) ? 100 : (bat_val * 100 / bat_max); } return 1;