phy: hisilicon: Fix an out of bounds check in hisi_inno_phy_probe()
authorHarshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
Fri, 21 Jul 2023 09:05:55 +0000 (02:05 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 3 Aug 2023 08:23:59 +0000 (10:23 +0200)
commit01cb355bb92e8fcf8306e11a4774d610c5864e39
tree5562912f1c935e0ef8c10d441e2afe64c4b86d5b
parent69534f5ab78449dc568b3beb2f0c06f6c6438cb1
phy: hisilicon: Fix an out of bounds check in hisi_inno_phy_probe()

[ Upstream commit 13c088cf3657d70893d75cf116be937f1509cc0f ]

The size of array 'priv->ports[]' is INNO_PHY_PORT_NUM.

In the for loop, 'i' is used as the index for array 'priv->ports[]'
with a check (i > INNO_PHY_PORT_NUM) which indicates that
INNO_PHY_PORT_NUM is allowed value for 'i' in the same loop.

This > comparison needs to be changed to >=, otherwise it potentially leads
to an out of bounds write on the next iteration through the loop

Fixes: ba8b0ee81fbb ("phy: add inno-usb2-phy driver for hi3798cv200 SoC")
Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
Link: https://lore.kernel.org/r/20230721090558.3588613-1-harshit.m.mogalapalli@oracle.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/phy/hisilicon/phy-hisi-inno-usb2.c