subsys/usb: Fix use of 'abs' in computing when to report on_idle

idle_rate is uint8_t, sof_cnt is uint32_t. The result is uint32_t, which
is the wrong type for 'abs'. Explicitly cast idle_rate to uint32_t,
subtract sof_cnt and then explicitly cast to int32_t and then use abs,
storing the result in another int32_t which matches the return type for
abs.

This quiets clang warnings about passing unsigned values to abs.

Signed-off-by: Keith Packard <keithp@keithp.com>
This commit is contained in:
Keith Packard 2022-04-27 21:48:38 -07:00 committed by Stephanos Ioannidis
parent c034050bba
commit abac6ccfaf

View file

@ -327,8 +327,8 @@ void hid_sof_handler(struct hid_device_info *dev_data)
continue;
}
uint32_t diff = abs(dev_data->idle_rate[i] * 4U -
dev_data->sof_cnt[i]);
int32_t diff = abs((int32_t) ((uint32_t) dev_data->idle_rate[i] * 4U -
dev_data->sof_cnt[i]));
if (diff < 2 && reported == false) {
dev_data->sof_cnt[i] = 0U;