Commit 3a6d8676 authored by Arnd Bergmann's avatar Arnd Bergmann Committed by Linus Torvalds

x86: apm: avoid uninitialized data

apm_bios_call() can fail, and return a status in its argument structure.
If that status however is zero during a call from
apm_get_power_status(), we end up using data that may have never been
set, as reported by "gcc -Wmaybe-uninitialized":

  arch/x86/kernel/apm_32.c: In function ‘apm’:
  arch/x86/kernel/apm_32.c:1729:17: error: ‘bx’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
  arch/x86/kernel/apm_32.c:1835:5: error: ‘cx’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
  arch/x86/kernel/apm_32.c:1730:17: note: ‘cx’ was declared here
  arch/x86/kernel/apm_32.c:1842:27: error: ‘dx’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
  arch/x86/kernel/apm_32.c:1731:17: note: ‘dx’ was declared here

This changes the function to return "APM_NO_ERROR" here, which makes the
code more robust to broken BIOS versions, and avoids the warning.
Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
Reviewed-by: default avatarJiri Kosina <jkosina@suse.cz>
Reviewed-by: default avatarLuis R. Rodriguez <mcgrof@kernel.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent e84efa32
...@@ -1042,8 +1042,11 @@ static int apm_get_power_status(u_short *status, u_short *bat, u_short *life) ...@@ -1042,8 +1042,11 @@ static int apm_get_power_status(u_short *status, u_short *bat, u_short *life)
if (apm_info.get_power_status_broken) if (apm_info.get_power_status_broken)
return APM_32_UNSUPPORTED; return APM_32_UNSUPPORTED;
if (apm_bios_call(&call)) if (apm_bios_call(&call)) {
if (!call.err)
return APM_NO_ERROR;
return call.err; return call.err;
}
*status = call.ebx; *status = call.ebx;
*bat = call.ecx; *bat = call.ecx;
if (apm_info.get_power_status_swabinminutes) { if (apm_info.get_power_status_swabinminutes) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment