common/usb_pd_protocol: Avoid unitialized use of port flags
common/usb_pd_protocol: Avoid unitialized use of port flags

On reset, when pd_partner_port_reset is called, if, for any reason
pd_get_saved_port_flags fails to get the saved port status, we
would risk using unitialized flags from the stack.

The function logic was a little complicated, and can be simplified
quite a bit by returning early if no contract is in place (or if
we fail to read flags from BBRAM).

This should not be a problem on real boards, as the stored value
should be readable from BBRAM.

In any case, the first time we used the flag
	if (explicit_contract_in_place && pd_comm_is_enabled(port))
only applies to unlocked RO images, so this never happens in production
(where RO images are locked).

The second case is a little tricker, and we may end up (not) applying
Rp where we should (not):
	/* If we just lost power, don't apply Rp. */
	if (!explicit_contract_in_place ||
	   system_get_reset_flags() &
	   (RESET_FLAG_BROWNOUT | RESET_FLAG_POWER_ON))
		return;
Presumably, the worst case here is that a charger may not work after
a brownout/power on.

BRANCH=none
BUG=chromium:958510
TEST=setup_board --board=amd64-generic --profile=msan-fuzzer
     cros_fuzz --board=amd64-generic reproduce --fuzzer \
        chromeos_ec_usb_pd_fuzzer --testcase \
        ./clusterfuzz-testcase-minimized-ec_usb_pd_fuzzer-5086219896225792 \
        --package chromeos-ec --build-type msan
    => No more MemorySanitizer error.

Change-Id: I40fb87b68dbe5244e8a2ae136508b431db7f96a8
Signed-off-by: Nicolas Boichat <f3daba1cdc403799935674d3cd4b0e5bd1804232@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1600935
Commit-Ready: ChromeOS CL Exonerator Bot <fa429e5907f00867f797423aea74327bb02c91b6@appspot.gserviceaccount.com>
Reviewed-by: Jett Rink <9d4aef0593e6843318d99df31597fb6153b89787@chromium.org>
Reviewed-by: Daisuke Nojiri <fd5f93af191bf7e8f73ea71cc3c0f66b41b1dd49@chromium.org>

coreboot/chrome-ec,coreboot/chrome-ec,coreboot/chrome-ec,coreboot/chrome-ec,coreboot/chrome-ec,coreboot/chrome-ec