Skip to contentSkip to conversation

usb: ehci-sh: fix illegal phy_init() running when platform_data is NULL

PATCH Shimoda, Yoshihiro 2 participants 3 messages Jun 11, 2012 – Jun 12, 2012

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

If the platform_data is not set, pdata will be uninitialized value. Then, the phy_init() may run on illegal address.

This patch also fixes the following warning:

CC drivers/usb/host/ehci-hcd.o
drivers/usb/host/ehci-sh.c: In function ‘ehci_hcd_sh_probe’:
drivers/usb/host/ehci-sh.c:104: warning: ‘pdata’ may be used uninitialized in this function

---
 drivers/usb/host/ehci-sh.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
drivers/usb/host/ehci-sh.c +1 -2
index ca819cd..e7cb392 100644
@@ -126,8 +126,7 @@ static int ehci_hcd_sh_probe(struct platform_device *pdev)
 		goto fail_create_hcd;
 	}
 
-	if (pdev->dev.platform_data != NULL)
-		pdata = pdev->dev.platform_data;
+	pdata = pdev->dev.platform_data;
 
 	/* initialize hcd */
 	hcd = usb_create_hcd(&ehci_sh_hc_driver, &pdev->dev,
Signature · 1 line
1.7.1
maintainer Acked-by
#1 lore raw
Quoted 2 lines · Yoshihiro

If the platform_data is not set, pdata will be uninitialized value. Then, the phy_init() may run on illegal address.

I don't see how this patch fixes that problem.

Quoted 5 lines

This patch also fixes the following warning:

CC drivers/usb/host/ehci-hcd.o
drivers/usb/host/ehci-sh.c: In function ‘ehci_hcd_sh_probe’:
drivers/usb/host/ehci-sh.c:104: warning: ‘pdata’ may be used uninitialized in this function

That alone is a good enough reason to accept the patch. You might want to update the patch description, though.

Quoted 10 lines
---
 drivers/usb/host/ehci-sh.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
drivers/usb/host/ehci-sh.c +0 -0
index ca819cd..e7cb392 100644

drivers/usb/host/ehci-sh.c static int ehci_hcd_sh_probe(struct platform_device *pdev) · line 132

Quoted 9 lines
drivers/usb/host/ehci-sh.c +1 -2
@@ -126,8 +126,7 @@ static int ehci_hcd_sh_probe(struct platform_device *pdev)
 		goto fail_create_hcd;
 	}
 
-	if (pdev->dev.platform_data != NULL)
-		pdata = pdev->dev.platform_data;
+	pdata = pdev->dev.platform_data;
 
 	/* initialize hcd */
 	hcd = usb_create_hcd(&ehci_sh_hc_driver, &pdev->dev,
#2 lore raw
In reply to Shimoda, Yoshihiro
Quoted 6 lines · Alan Stern
Quoted 2 lines · Yoshihiro

If the platform_data is not set, pdata will be uninitialized value. Then, the phy_init() may run on illegal address.

I don't see how this patch fixes that problem.

The driver has the following code:

	if (pdata && pdata->phy_init)
		pdata->phy_init();

So, if the condition is true when the pdata is uninitialize value, the driver may jump the illegal pdata->phy_init().

I will modify this patch to add this patch description.

Quoted 9 lines
Quoted 5 lines

This patch also fixes the following warning:

CC drivers/usb/host/ehci-hcd.o
drivers/usb/host/ehci-sh.c: In function ‘ehci_hcd_sh_probe’:
drivers/usb/host/ehci-sh.c:104: warning: ‘pdata’ may be used uninitialized in this function

That alone is a good enough reason to accept the patch. You might want to update the patch description, though.

< snip >

Quoted 3 lines

Thank you for the Acked-by:

Best regards,
Yoshihiro Shimoda