summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHung-Te Lin <hungte@chromium.org>2011-11-16 17:31:19 +0800
committerGerrit <chrome-bot@google.com>2011-11-16 06:47:02 -0800
commit6a6f85d6bbfb640aadb92521befe3188e99a3d02 (patch)
treecff984441547b70b6539be25da6ec52ac9672d2a
parent791d6e6d75f1d1a0fb41c3a7be27dac7df78def3 (diff)
downloadvboot-6a6f85d6bbfb640aadb92521befe3188e99a3d02.tar.gz
vboot_reference: fix CMOS writing for x86 platforms
VbCmosWrite should seek to correct offset before starting to write; also fixed file handle leakage. BUG=chromium-os:23000 TEST=crossystem recovery_request=1; echo $? # show: 0 crossystem recovery_request # show: 1 reboot # see recovery screen Change-Id: I33bca8af2b351ba9b364309838df699a31bb543a Reviewed-on: https://gerrit.chromium.org/gerrit/11756 Tested-by: Hung-Te Lin <hungte@chromium.org> Reviewed-by: Gabe Black <gabeblack@chromium.org> Commit-Ready: Hung-Te Lin <hungte@chromium.org>
-rw-r--r--host/arch/x86/lib/crossystem_arch.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/host/arch/x86/lib/crossystem_arch.c b/host/arch/x86/lib/crossystem_arch.c
index 92f0b9f5..1042c66e 100644
--- a/host/arch/x86/lib/crossystem_arch.c
+++ b/host/arch/x86/lib/crossystem_arch.c
@@ -112,12 +112,9 @@ static int VbCmosRead(int offs, size_t size, void *ptr) {
VbFixCmosChecksum(f);
res = fread(ptr, size, 1, f);
}
- if (1 != res) {
- fclose(f);
- return -1;
- }
- return 0;
+ fclose(f);
+ return (1 == res) ? 0 : -1;
}
@@ -129,17 +126,19 @@ static int VbCmosWrite(int offs, size_t size, const void *ptr) {
if (!f)
return -1;
+ if (0 != fseek(f, offs, SEEK_SET)) {
+ fclose(f);
+ return -1;
+ }
+
res = fwrite(ptr, size, 1, f);
if (1 != res && errno == EIO && ferror(f)) {
VbFixCmosChecksum(f);
res = fwrite(ptr, size, 1, f);
}
- if (1 != res) {
- fclose(f);
- return -1;
- }
- return 0;
+ fclose(f);
+ return (1 == res) ? 0 : -1;
}