usb: chipidea: host: fix port index underflow and UBSAN complains
authorLi Jun <jun.li@nxp.com>
Fri, 18 Jun 2021 08:28:58 +0000 (16:28 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 18 Sep 2021 11:40:30 +0000 (13:40 +0200)
commit2d3fab9ceafad925d30d0ea78f3a2b1bc8ce550b
treee57b2ef5c5e6b359a9c29e64962843fe26a61c11
parent2225a5cd2fbc2ef0e0f78e585db3844f60416a39
usb: chipidea: host: fix port index underflow and UBSAN complains

[ Upstream commit e5d6a7c6cfae9e714a0e8ff64facd1ac68a784c6 ]

If wIndex is 0 (and it often is), these calculations underflow and
UBSAN complains, here resolve this by not decrementing the index when
it is equal to 0, this copies the solution from commit 85e3990bea49
("USB: EHCI: avoid undefined pointer arithmetic and placate UBSAN")

Reported-by: Zhipeng Wang <zhipeng.wang_1@nxp.com>
Signed-off-by: Li Jun <jun.li@nxp.com>
Link: https://lore.kernel.org/r/1624004938-2399-1-git-send-email-jun.li@nxp.com
Signed-off-by: Peter Chen <peter.chen@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/usb/chipidea/host.c