Commit cabd25b5 authored by Dan Carpenter's avatar Dan Carpenter Committed by Vinod Koul
Browse files

phy: stm32-usphyc: Fix off by one in probe()



The "index" variable is used as an index into the usbphyc->phys[] array
which has usbphyc->nphys elements.  So if it is equal to usbphyc->nphys
then it is one element out of bounds.  The "index" comes from the
device tree so it's data that we trust and it's unlikely to be wrong,
however it's obviously still worth fixing the bug.  Change the > to >=.

Fixes: 94c358da ("phy: stm32: add support for STM32 USB PHY Controller (USBPHYC)")
Signed-off-by: default avatarDan Carpenter <dan.carpenter@linaro.org>
Reviewed-by: default avatarAmelie Delaunay <amelie.delaunay@foss.st.com>
Link: https://patch.msgid.link/aTfHcMJK1wFVnvEe@stanley.mountain


Signed-off-by: default avatarVinod Koul <vkoul@kernel.org>
parent 1ca52c09
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -712,7 +712,7 @@ static int stm32_usbphyc_probe(struct platform_device *pdev)
		}

		ret = of_property_read_u32(child, "reg", &index);
		if (ret || index > usbphyc->nphys) {
		if (ret || index >= usbphyc->nphys) {
			dev_err(&phy->dev, "invalid reg property: %d\n", ret);
			if (!ret)
				ret = -EINVAL;