diff options
author | Caveh Jalali <caveh@chromium.org> | 2021-04-27 18:38:58 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-04-30 18:39:57 +0000 |
commit | 17938ae62c59bb9c79e5ae7ad4b1f5fbe11b96e1 (patch) | |
tree | c524d3e6a9f19a208eef023e687a6969c45d6406 /driver | |
parent | 422494675494e5103bb3903e8b5645d3d5817f89 (diff) | |
download | chrome-ec-17938ae62c59bb9c79e5ae7ad4b1f5fbe11b96e1.tar.gz |
ps8xxx: Handle null pointers
This adds a null pointer check to prevent undefined behavior. Also, add
check for board_get_ps8xxx_product_id() returning an error.
BRANCH=none
BUG=b:186189039
TEST=buildall passes
Change-Id: I40f5836528e9beaabac27d39ef6dd25013b9302c
Signed-off-by: Caveh Jalali <caveh@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2857795
Reviewed-by: Wai-Hong Tam <waihong@google.com>
Commit-Queue: Wai-Hong Tam <waihong@google.com>
Diffstat (limited to 'driver')
-rw-r--r-- | driver/tcpm/ps8xxx.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/driver/tcpm/ps8xxx.c b/driver/tcpm/ps8xxx.c index 14581a346b..e435621b37 100644 --- a/driver/tcpm/ps8xxx.c +++ b/driver/tcpm/ps8xxx.c @@ -490,8 +490,16 @@ static int ps8xxx_get_chip_info(int port, int live, if (rv != EC_SUCCESS) return rv; + if (chip_info == NULL) + return EC_SUCCESS; + if (!live) { - product_id[port] = board_get_ps8xxx_product_id(port); + uint16_t pid; + + pid = board_get_ps8xxx_product_id(port); + if (pid == 0) + return EC_ERROR_UNKNOWN; + product_id[port] = pid; chip_info->vendor_id = PS8XXX_VENDOR_ID; chip_info->product_id = product_id[port]; } |