From 1620833b5e7c97a1f0d2a7007746e1f961d7587f Mon Sep 17 00:00:00 2001 From: Wai-Hong Tam Date: Wed, 24 Jun 2020 10:02:45 -0700 Subject: tcpm: Change the get_chip_info() to prevent race conditions The original get_chip_info() returns a point of point to the chip_info. This way helps to cache the chip_info to a static variable and the function just returns the pointer to the static variable. This static variable has a race condition on the PS8805 chip. The PS8805 chip returns a different PID when the firmware is corrupted, i.e. 0x8803 instead of 0x8805. The !live case fixes the PID, by modifying the static variable directly. When another task calls the same function for the live case, the static variable is modified and has a race condition. This change fixes the issue by changing the get_chip_info() parameter to a point of the chip_info. The caller has to allocate a buffer in the stack and pass the address to the function. For the !live case, the function copies the cache value from the static variable to the buffer. So the static variable doesn't have a race condition. BRANCH=None BUG=b:159588335 TEST=Used ectool to check the PD chip PID 0x8805 (was 0x8803). localhost ~ # ectool pdchipinfo 1 vendor_id: 0x1da0 product_id: 0x8805 device_id: 0x1 fw_version: 0x0 min_req_fw_version: 0x0 Change-Id: Ic24615af77ea58016d286480572d2a282c4fa09a Signed-off-by: Wai-Hong Tam Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2264477 Reviewed-by: Julius Werner --- common/mock/tcpc_mock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'common/mock/tcpc_mock.c') diff --git a/common/mock/tcpc_mock.c b/common/mock/tcpc_mock.c index 8d62710f6a..27b79af989 100644 --- a/common/mock/tcpc_mock.c +++ b/common/mock/tcpc_mock.c @@ -146,7 +146,7 @@ __maybe_unused static int mock_drp_toggle(int port) } static int mock_get_chip_info(int port, int live, - struct ec_response_pd_chip_info_v1 **info) + struct ec_response_pd_chip_info_v1 *info) { return EC_SUCCESS; } -- cgit v1.2.1