linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] usb: cdns3: fix NULL pointer dereference on no platform data
@ 2020-11-23 10:49 Roger Quadros
  2020-11-23 11:24 ` Pawel Laszczak
  2020-11-24  6:49 ` Peter Chen
  0 siblings, 2 replies; 3+ messages in thread
From: Roger Quadros @ 2020-11-23 10:49 UTC (permalink / raw)
  To: peter.chen, pawell
  Cc: balbi, nm, nsekhar, a-govindraju, linux-usb, linux-kernel, Roger Quadros

Some platforms (e.g. TI) will not have any platform data which will
lead to NULL pointer dereference if we don't check for NULL pdata.

Fixes: a284b7fd1b8f ("usb: cdns3: add quirk for enable runtime pm by default")
Reported-by: Nishanth Menon <nm@ti.com>
Signed-off-by: Roger Quadros <rogerq@ti.com>
---
 drivers/usb/cdns3/core.c | 2 +-
 drivers/usb/cdns3/host.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/cdns3/core.c b/drivers/usb/cdns3/core.c
index 54d841aa626f..0f08aebce86d 100644
--- a/drivers/usb/cdns3/core.c
+++ b/drivers/usb/cdns3/core.c
@@ -559,7 +559,7 @@ static int cdns3_probe(struct platform_device *pdev)
 	device_set_wakeup_capable(dev, true);
 	pm_runtime_set_active(dev);
 	pm_runtime_enable(dev);
-	if (!(cdns->pdata->quirks & CDNS3_DEFAULT_PM_RUNTIME_ALLOW))
+	if (!(cdns->pdata && (cdns->pdata->quirks & CDNS3_DEFAULT_PM_RUNTIME_ALLOW)))
 		pm_runtime_forbid(dev);
 
 	/*
diff --git a/drivers/usb/cdns3/host.c b/drivers/usb/cdns3/host.c
index 08103785a17a..ec89f2e5430f 100644
--- a/drivers/usb/cdns3/host.c
+++ b/drivers/usb/cdns3/host.c
@@ -59,7 +59,7 @@ static int __cdns3_host_init(struct cdns3 *cdns)
 		goto err1;
 	}
 
-	if (cdns->pdata->quirks & CDNS3_DEFAULT_PM_RUNTIME_ALLOW)
+	if (cdns->pdata && (cdns->pdata->quirks & CDNS3_DEFAULT_PM_RUNTIME_ALLOW))
 		cdns->xhci_plat_data->quirks |= XHCI_DEFAULT_PM_RUNTIME_ALLOW;
 
 	ret = platform_device_add_data(xhci, cdns->xhci_plat_data,
-- 
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* RE: [PATCH] usb: cdns3: fix NULL pointer dereference on no platform data
  2020-11-23 10:49 [PATCH] usb: cdns3: fix NULL pointer dereference on no platform data Roger Quadros
@ 2020-11-23 11:24 ` Pawel Laszczak
  2020-11-24  6:49 ` Peter Chen
  1 sibling, 0 replies; 3+ messages in thread
From: Pawel Laszczak @ 2020-11-23 11:24 UTC (permalink / raw)
  To: Roger Quadros, peter.chen
  Cc: balbi, nm, nsekhar, a-govindraju, linux-usb, linux-kernel

Hi,

>
>Some platforms (e.g. TI) will not have any platform data which will
>lead to NULL pointer dereference if we don't check for NULL pdata.
>
>Fixes: a284b7fd1b8f ("usb: cdns3: add quirk for enable runtime pm by default")
>Reported-by: Nishanth Menon <nm@ti.com>
>Signed-off-by: Roger Quadros <rogerq@ti.com>

Acked-by: Pawel Laszczak <pawell@cadence.com>

I see the same issue on my PCI based platform. 

But I afraid that there will be some conflict with applying my CDSNP series after
applying this patch on Peter Chen branch :(

>---
> drivers/usb/cdns3/core.c | 2 +-
> drivers/usb/cdns3/host.c | 2 +-
> 2 files changed, 2 insertions(+), 2 deletions(-)
>
>diff --git a/drivers/usb/cdns3/core.c b/drivers/usb/cdns3/core.c
>index 54d841aa626f..0f08aebce86d 100644
>--- a/drivers/usb/cdns3/core.c
>+++ b/drivers/usb/cdns3/core.c
>@@ -559,7 +559,7 @@ static int cdns3_probe(struct platform_device *pdev)
> 	device_set_wakeup_capable(dev, true);
> 	pm_runtime_set_active(dev);
> 	pm_runtime_enable(dev);
>-	if (!(cdns->pdata->quirks & CDNS3_DEFAULT_PM_RUNTIME_ALLOW))
>+	if (!(cdns->pdata && (cdns->pdata->quirks & CDNS3_DEFAULT_PM_RUNTIME_ALLOW)))
> 		pm_runtime_forbid(dev);
>
> 	/*
>diff --git a/drivers/usb/cdns3/host.c b/drivers/usb/cdns3/host.c
>index 08103785a17a..ec89f2e5430f 100644
>--- a/drivers/usb/cdns3/host.c
>+++ b/drivers/usb/cdns3/host.c
>@@ -59,7 +59,7 @@ static int __cdns3_host_init(struct cdns3 *cdns)
> 		goto err1;
> 	}
>
>-	if (cdns->pdata->quirks & CDNS3_DEFAULT_PM_RUNTIME_ALLOW)
>+	if (cdns->pdata && (cdns->pdata->quirks & CDNS3_DEFAULT_PM_RUNTIME_ALLOW))
> 		cdns->xhci_plat_data->quirks |= XHCI_DEFAULT_PM_RUNTIME_ALLOW;
>
> 	ret = platform_device_add_data(xhci, cdns->xhci_plat_data,

--
Regards,
Pawel Laszczak

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] usb: cdns3: fix NULL pointer dereference on no platform data
  2020-11-23 10:49 [PATCH] usb: cdns3: fix NULL pointer dereference on no platform data Roger Quadros
  2020-11-23 11:24 ` Pawel Laszczak
@ 2020-11-24  6:49 ` Peter Chen
  1 sibling, 0 replies; 3+ messages in thread
From: Peter Chen @ 2020-11-24  6:49 UTC (permalink / raw)
  To: Roger Quadros
  Cc: pawell, balbi, nm, nsekhar, a-govindraju, linux-usb, linux-kernel

On 20-11-23 12:49:31, Roger Quadros wrote:
> Some platforms (e.g. TI) will not have any platform data which will
> lead to NULL pointer dereference if we don't check for NULL pdata.
> 
> Fixes: a284b7fd1b8f ("usb: cdns3: add quirk for enable runtime pm by default")
> Reported-by: Nishanth Menon <nm@ti.com>
> Signed-off-by: Roger Quadros <rogerq@ti.com>
> ---
>  drivers/usb/cdns3/core.c | 2 +-
>  drivers/usb/cdns3/host.c | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/usb/cdns3/core.c b/drivers/usb/cdns3/core.c
> index 54d841aa626f..0f08aebce86d 100644
> --- a/drivers/usb/cdns3/core.c
> +++ b/drivers/usb/cdns3/core.c
> @@ -559,7 +559,7 @@ static int cdns3_probe(struct platform_device *pdev)
>  	device_set_wakeup_capable(dev, true);
>  	pm_runtime_set_active(dev);
>  	pm_runtime_enable(dev);
> -	if (!(cdns->pdata->quirks & CDNS3_DEFAULT_PM_RUNTIME_ALLOW))
> +	if (!(cdns->pdata && (cdns->pdata->quirks & CDNS3_DEFAULT_PM_RUNTIME_ALLOW)))
>  		pm_runtime_forbid(dev);
>  
>  	/*
> diff --git a/drivers/usb/cdns3/host.c b/drivers/usb/cdns3/host.c
> index 08103785a17a..ec89f2e5430f 100644
> --- a/drivers/usb/cdns3/host.c
> +++ b/drivers/usb/cdns3/host.c
> @@ -59,7 +59,7 @@ static int __cdns3_host_init(struct cdns3 *cdns)
>  		goto err1;
>  	}
>  
> -	if (cdns->pdata->quirks & CDNS3_DEFAULT_PM_RUNTIME_ALLOW)
> +	if (cdns->pdata && (cdns->pdata->quirks & CDNS3_DEFAULT_PM_RUNTIME_ALLOW))
>  		cdns->xhci_plat_data->quirks |= XHCI_DEFAULT_PM_RUNTIME_ALLOW;
>  
>  	ret = platform_device_add_data(xhci, cdns->xhci_plat_data,

Thanks for fixing it, already applied to -next tree.

-- 

Thanks,
Peter Chen

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-11-24  6:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-23 10:49 [PATCH] usb: cdns3: fix NULL pointer dereference on no platform data Roger Quadros
2020-11-23 11:24 ` Pawel Laszczak
2020-11-24  6:49 ` Peter Chen

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