mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-12-29 01:50:53 +00:00
usb_pd_policy: pd_extract_pdo_power: Check that mv != 0
It's preferable to print an error when mv = 0, rather than
crashing. Also, do not even select invalid PDO in
pd_find_pdo_index.
This was seen on elm, where ANX7688 appears to send the EC a
corrupted packet during hard reset when connected to j5create
adapter.
BRANCH=none
BUG=chrome-os-partner:60575
TEST=Plug in j5create adapter, then HDMI adapter, then power, elm
does not crash (note that the HDMI output still does not work,
but at least elm charges).
Change-Id: I2150ad6f13465a005444804ec44ec3bdc0ded361
Reviewed-on: https://chromium-review.googlesource.com/416700
Commit-Ready: Nicolas Boichat <drinkcat@chromium.org>
Tested-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
This commit is contained in:
committed by
chrome-bot
parent
36bfc6ad9a
commit
d0af9df605
@@ -107,6 +107,9 @@ static int pd_find_pdo_index(int cnt, uint32_t *src_caps, int max_mv)
|
||||
/* Get max power that is under our max voltage input */
|
||||
for (i = 0; i < cnt; i++) {
|
||||
mv = ((src_caps[i] >> 10) & 0x3FF) * 50;
|
||||
/* Skip invalid voltage */
|
||||
if (!mv)
|
||||
continue;
|
||||
/* Skip any voltage not supported by this board */
|
||||
if (!pd_is_valid_input_voltage(mv))
|
||||
continue;
|
||||
@@ -154,6 +157,12 @@ static void pd_extract_pdo_power(uint32_t pdo, uint32_t *ma, uint32_t *mv)
|
||||
int max_ma, uw;
|
||||
*mv = ((pdo >> 10) & 0x3FF) * 50;
|
||||
|
||||
if (*mv == 0) {
|
||||
CPRINTF("ERR:PDO mv=0\n");
|
||||
*ma = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if ((pdo & PDO_TYPE_MASK) == PDO_TYPE_BATTERY) {
|
||||
uw = 250000 * (pdo & 0x3FF);
|
||||
max_ma = 1000 * MIN(1000 * uw, PD_MAX_POWER_MW) / *mv;
|
||||
|
||||
Reference in New Issue
Block a user