* [PATCH] phy: stm32-usphyc: Fix off by one in probe()
@ 2025-12-09 6:53 Dan Carpenter
2025-12-09 8:52 ` [Linux-stm32] " Amelie Delaunay
2025-12-23 17:33 ` Vinod Koul
0 siblings, 2 replies; 3+ messages in thread
From: Dan Carpenter @ 2025-12-09 6:53 UTC (permalink / raw)
To: Amelie Delaunay
Cc: Vinod Koul, Neil Armstrong, Maxime Coquelin, Alexandre Torgue,
Johan Hovold, Fengguang Wu, Kishon Vijay Abraham I, linux-phy,
linux-stm32, linux-arm-kernel, linux-kernel, kernel-janitors
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>
---
drivers/phy/st/phy-stm32-usbphyc.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/phy/st/phy-stm32-usbphyc.c b/drivers/phy/st/phy-stm32-usbphyc.c
index 27fe92f73f33..b44afbff8616 100644
--- a/drivers/phy/st/phy-stm32-usbphyc.c
+++ b/drivers/phy/st/phy-stm32-usbphyc.c
@@ -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;
--
2.51.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [Linux-stm32] [PATCH] phy: stm32-usphyc: Fix off by one in probe()
2025-12-09 6:53 [PATCH] phy: stm32-usphyc: Fix off by one in probe() Dan Carpenter
@ 2025-12-09 8:52 ` Amelie Delaunay
2025-12-23 17:33 ` Vinod Koul
1 sibling, 0 replies; 3+ messages in thread
From: Amelie Delaunay @ 2025-12-09 8:52 UTC (permalink / raw)
To: Dan Carpenter, Amelie Delaunay
Cc: Kishon Vijay Abraham I, Neil Armstrong, kernel-janitors,
linux-kernel, Vinod Koul, linux-arm-kernel, Maxime Coquelin,
linux-phy, Fengguang Wu, linux-stm32, Johan Hovold
On 12/9/25 07:53, Dan Carpenter wrote:
> 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>
Hi Dan, thanks for your patch.
Reviewed-by: Amelie Delaunay <amelie.delaunay@foss.st.com>
> ---
> drivers/phy/st/phy-stm32-usbphyc.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/phy/st/phy-stm32-usbphyc.c b/drivers/phy/st/phy-stm32-usbphyc.c
> index 27fe92f73f33..b44afbff8616 100644
> --- a/drivers/phy/st/phy-stm32-usbphyc.c
> +++ b/drivers/phy/st/phy-stm32-usbphyc.c
> @@ -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;
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] phy: stm32-usphyc: Fix off by one in probe()
2025-12-09 6:53 [PATCH] phy: stm32-usphyc: Fix off by one in probe() Dan Carpenter
2025-12-09 8:52 ` [Linux-stm32] " Amelie Delaunay
@ 2025-12-23 17:33 ` Vinod Koul
1 sibling, 0 replies; 3+ messages in thread
From: Vinod Koul @ 2025-12-23 17:33 UTC (permalink / raw)
To: Amelie Delaunay, Dan Carpenter
Cc: Neil Armstrong, Maxime Coquelin, Alexandre Torgue, Johan Hovold,
Fengguang Wu, Kishon Vijay Abraham I, linux-phy, linux-stm32,
linux-arm-kernel, linux-kernel, kernel-janitors
On Tue, 09 Dec 2025 09:53:36 +0300, Dan Carpenter wrote:
> 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 >=.
>
>
> [...]
Applied, thanks!
[1/1] phy: stm32-usphyc: Fix off by one in probe()
commit: cabd25b57216ddc132efbcc31f972baa03aad15a
Best regards,
--
~Vinod
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-12-23 17:34 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-09 6:53 [PATCH] phy: stm32-usphyc: Fix off by one in probe() Dan Carpenter
2025-12-09 8:52 ` [Linux-stm32] " Amelie Delaunay
2025-12-23 17:33 ` Vinod Koul
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).