NvIsAvailable() should report the current state

The ExecuteCommand() function calls NvCheckState() to determine
the current NV state before handling any command. Later, commands
that use NV storage will call NvIsAvailable() to ensure that the
NV state is still good. If it isn't, they should fail.

But the NvIsAvailable() function doesn't actually detect changes.

Instead, it just reports the original state that NvCheckState()
saw. So if the NV state has changed when one of those NV storage
functions calls NvIsAvailable(), the change won't be noticed
until either NvCommit() is called or until the NEXT invocation of
ExecuteCommand().

This CL causes NvIsAvailable() to actually be sure that the NV
state is still good.

BUG=none
BRANCH=none
TEST=run TCG tests, test on Gru (log in/out, reboot, etc.)

All tests pass, no new failures seen (I didn't expect any)

Change-Id: I7f1e713b760f068793513fc2426b2933e8971359
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/390752
Commit-Ready: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
diff --git a/NV.c b/NV.c
index 05b7b4f..0f01100 100644
--- a/NV.c
+++ b/NV.c
@@ -60,6 +60,10 @@
     void
     )
 {
+    // Make sure that NV state is still good
+    if (s_NvStatus == TPM_RC_SUCCESS)
+	NvCheckState();
+
     return s_NvStatus;
 }
 //