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

Alan Stern stern at rowland.harvard.edu
Fri Nov 2 01:52:22 EST 2012


On Thu, 1 Nov 2012, Wei Yongjun wrote:

> 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);

In fact it would be better to remove these tests entirely.  They should 
never trigger, and if they do then an oops is the appropriate outcome.

Alan Stern



More information about the devicetree-discuss mailing list