]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
phy: stm32-usphyc: Fix off by one in probe()
authorDan Carpenter <dan.carpenter@linaro.org>
Tue, 9 Dec 2025 06:53:36 +0000 (09:53 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 6 Feb 2026 15:43:57 +0000 (16:43 +0100)
[ Upstream commit cabd25b57216ddc132efbcc31f972baa03aad15a ]

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: 94c358da3a05 ("phy: stm32: add support for STM32 USB PHY Controller (USBPHYC)")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Reviewed-by: Amelie Delaunay <amelie.delaunay@foss.st.com>
Link: https://patch.msgid.link/aTfHcMJK1wFVnvEe@stanley.mountain
Signed-off-by: Vinod Koul <vkoul@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/phy/st/phy-stm32-usbphyc.c

index 5bb9647b078f127a30cff5eae55c73399f8597e5..c2947159e8b41f9b7dfc61e93a0903ce39c97065 100644 (file)
@@ -708,7 +708,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;