summaryrefslogtreecommitdiff
path: root/common/usb_pd_policy.c
diff options
context:
space:
mode:
authorRuibin Chang <ruibin.chang@ite.com.tw>2020-01-10 17:50:58 +0800
committerCommit Bot <commit-bot@chromium.org>2020-01-13 06:11:02 +0000
commit9e0f24fada37c4a0c0e8bae2837fb591450e642b (patch)
tree0f261435dc84225dc1862188621c39bcfdf15329 /common/usb_pd_policy.c
parentf34ffe037df6594788a7f05efe02ba4760d7eae8 (diff)
downloadchrome-ec-9e0f24fada37c4a0c0e8bae2837fb591450e642b.tar.gz
usb_pd_policy: check if the pointer is NULL or not
Memset() initialize structure pointer fx member point to code address 0 in pd_dfp_pe_init(). When we receive ack of discover mode, we will input svid 0 to pd_dfp_enter_mode(), and if the value of code address 0 and 1 is also same as 0x0000. It means that we will get the both match mode index value 0 in allocate_mode(), but now the pe[].amodes[].fx point to NULL, and later executing enter VDM mode results in EC reset. So in order to get the right mode index, we need check if the pointer is NULL or not when we compare with SVID in get_mode_idx(). BUG=none BRANCH=none TEST=check logs via UART and Lecroy on reef_it8320, ampton, PD EVB with risc-v core: 1.connect to adapter: state to SNK_READY 2.connect to dongle: state to SRC_READY, and done VDM enumeration. Change-Id: I709efc71f4e64540f1526967dca41e8c2bf34a02 Signed-off-by: Ruibin Chang <Ruibin.Chang@ite.com.tw> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1966822 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Diffstat (limited to 'common/usb_pd_policy.c')
-rw-r--r--common/usb_pd_policy.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/common/usb_pd_policy.c b/common/usb_pd_policy.c
index 0980597ee5..0bced8d5e4 100644
--- a/common/usb_pd_policy.c
+++ b/common/usb_pd_policy.c
@@ -513,7 +513,8 @@ static int get_mode_idx(int port, uint16_t svid)
int i;
for (i = 0; i < PD_AMODE_COUNT; i++) {
- if (pe[port].amodes[i].fx->svid == svid)
+ if (pe[port].amodes[i].fx &&
+ (pe[port].amodes[i].fx->svid == svid))
return i;
}
return -1;