From 6a6f85d6bbfb640aadb92521befe3188e99a3d02 Mon Sep 17 00:00:00 2001 From: Hung-Te Lin Date: Wed, 16 Nov 2011 17:31:19 +0800 Subject: [PATCH] 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 Reviewed-by: Gabe Black Commit-Ready: Hung-Te Lin --- host/arch/x86/lib/crossystem_arch.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/host/arch/x86/lib/crossystem_arch.c b/host/arch/x86/lib/crossystem_arch.c index 92f0b9f52a..1042c66e46 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; }