[PATCH] usb: host: tegra: fix potential NULL pointer dereference

Wei Yongjun weiyj.lk at gmail.com
Thu Nov 1 17:57:38 EST 2012


From: Wei Yongjun <yongjun_wei at trendmicro.com.cn>

The dereference should be moved below the NULL test.

dpatch engine is used to auto generate this patch.
(https://github.com/weiyj/dpatch)

Signed-off-by: Wei Yongjun <yongjun_wei at trendmicro.com.cn>
---
 drivers/usb/host/ehci-tegra.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/host/ehci-tegra.c b/drivers/usb/host/ehci-tegra.c
index 6223d17..e40fcb0 100644
--- a/drivers/usb/host/ehci-tegra.c
+++ b/drivers/usb/host/ehci-tegra.c
@@ -776,9 +776,13 @@ fail_clk:
 static int tegra_ehci_remove(struct platform_device *pdev)
 {
 	struct tegra_ehci_hcd *tegra = platform_get_drvdata(pdev);
-	struct usb_hcd *hcd = ehci_to_hcd(tegra->ehci);
+	struct usb_hcd *hcd;
+
+	if (tegra == NULL)
+		return -EINVAL;
 
-	if (tegra == NULL || hcd == NULL)
+	hcd = ehci_to_hcd(tegra->ehci);
+	if (hcd == NULL)
 		return -EINVAL;
 
 	pm_runtime_get_sync(&pdev->dev);



More information about the devicetree-discuss mailing list