diff mbox series

[1/3] phy: sun4i-usb: Fix of_xlate() argument check

Message ID 20230609105621.1410483-2-andre.przywara@arm.com
State Superseded
Delegated to: Andre Przywara
Headers show
Series phy: sun4i: Allwinner F1C100s support and cleanup | expand

Commit Message

Andre Przywara June 9, 2023, 10:56 a.m. UTC
In its of_xlate() function, the Allwinner USB PHY driver compares the
args_count variable against the number of implemented USB PHYs, although
this is the *number of arguments* to the DT phandle property. Per the DT
binding for this PHY device, this number is always one, so this check
will always fail if the particular SoC implements exactly one USB PHY.
So far this affected only the V3s (which has USB support disabled), but
the F1C100s also sports one PHY only.

Fix that check to compare args_count against exactly 1, and the args[0]
content (requested PHY number) against the number of implemented PHYs.

This fixes USB operation on the Allwinner V3s and allows to enable USB
on the Allwinner F1C100s SoC.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
---
 drivers/phy/allwinner/phy-sun4i-usb.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Jernej Škrabec June 9, 2023, 8:40 p.m. UTC | #1
Dne petek, 09. junij 2023 ob 12:56:19 CEST je Andre Przywara napisal(a):
> In its of_xlate() function, the Allwinner USB PHY driver compares the
> args_count variable against the number of implemented USB PHYs, although
> this is the *number of arguments* to the DT phandle property. Per the DT
> binding for this PHY device, this number is always one, so this check
> will always fail if the particular SoC implements exactly one USB PHY.
> So far this affected only the V3s (which has USB support disabled), but
> the F1C100s also sports one PHY only.
> 
> Fix that check to compare args_count against exactly 1, and the args[0]
> content (requested PHY number) against the number of implemented PHYs.
> 
> This fixes USB operation on the Allwinner V3s and allows to enable USB
> on the Allwinner F1C100s SoC.
> 
> Signed-off-by: Andre Przywara <andre.przywara@arm.com>

Nice catch!

Reviewed-by: Jernej Skrabec <jernej.skrabec@gmail.com>

Best regards,
Jernej
diff mbox series

Patch

diff --git a/drivers/phy/allwinner/phy-sun4i-usb.c b/drivers/phy/allwinner/phy-sun4i-usb.c
index 6428163c188..dbea70f9a5e 100644
--- a/drivers/phy/allwinner/phy-sun4i-usb.c
+++ b/drivers/phy/allwinner/phy-sun4i-usb.c
@@ -372,7 +372,10 @@  static int sun4i_usb_phy_xlate(struct phy *phy,
 {
 	struct sun4i_usb_phy_data *data = dev_get_priv(phy->dev);
 
-	if (args->args_count >= data->cfg->num_phys)
+	if (args->args_count != 1)
+		return -EINVAL;
+
+	if (args->args[0] >= data->cfg->num_phys)
 		return -EINVAL;
 
 	if (data->cfg->missing_phys & BIT(args->args[0]))