mirror of
https://github.com/CTCaer/hekate.git
synced 2024-11-26 11:42:09 +00:00
bdk: bm92t36: add sanity checks
If bm92t i2c comms are broken, it can hang hekate. So sanitize buffer and max profile print supported.
This commit is contained in:
parent
f9e99212fc
commit
ee3fc499cd
1 changed files with 5 additions and 0 deletions
|
@ -73,18 +73,23 @@ void bm92t36_get_sink_info(bool *inserted, usb_pd_objects_t *usb_pd)
|
||||||
|
|
||||||
if (inserted)
|
if (inserted)
|
||||||
{
|
{
|
||||||
|
memset(buf, 0, sizeof(buf));
|
||||||
_bm92t36_read_reg(buf, 2, STATUS1_REG);
|
_bm92t36_read_reg(buf, 2, STATUS1_REG);
|
||||||
*inserted = buf[0] & STATUS1_INSERT ? true : false;
|
*inserted = buf[0] & STATUS1_INSERT ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (usb_pd)
|
if (usb_pd)
|
||||||
{
|
{
|
||||||
|
memset(buf, 0, sizeof(buf));
|
||||||
_bm92t36_read_reg(buf, 29, READ_PDOS_SRC_REG);
|
_bm92t36_read_reg(buf, 29, READ_PDOS_SRC_REG);
|
||||||
memcpy(pdos, &buf[1], 28);
|
memcpy(pdos, &buf[1], 28);
|
||||||
|
|
||||||
memset(usb_pd, 0, sizeof(usb_pd_objects_t));
|
memset(usb_pd, 0, sizeof(usb_pd_objects_t));
|
||||||
usb_pd->pdo_no = buf[0] / sizeof(pd_object_t);
|
usb_pd->pdo_no = buf[0] / sizeof(pd_object_t);
|
||||||
|
|
||||||
|
if (usb_pd->pdo_no > 7)
|
||||||
|
usb_pd->pdo_no = 7;
|
||||||
|
|
||||||
for (u32 i = 0; i < usb_pd->pdo_no; i++)
|
for (u32 i = 0; i < usb_pd->pdo_no; i++)
|
||||||
{
|
{
|
||||||
usb_pd->pdos[i].amperage = pdos[i].amp * 10;
|
usb_pd->pdos[i].amperage = pdos[i].amp * 10;
|
||||||
|
|
Loading…
Reference in a new issue