linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] usb: cdnsp: Fix segmentation fault in cdns_lost_power function
@ 2022-01-11  9:07 Pawel Laszczak
  2022-01-12 12:56 ` Peter Chen
  0 siblings, 1 reply; 3+ messages in thread
From: Pawel Laszczak @ 2022-01-11  9:07 UTC (permalink / raw)
  To: peter.chen
  Cc: a-govindraju, frank.li, rogerq, gregkh, linux-usb, linux-kernel,
	pawell, stable

From: Pawel Laszczak <pawell@cadence.com>

CDNSP driver read not initialized cdns->otg_v0_regs
which lead to segmentation fault. Patch fixes this issue.

Fixes: 2cf2581cd229 ("usb: cdns3: add power lost support for system resume")
cc: <stable@vger.kernel.org>
Signed-off-by: Pawel Laszczak <pawell@cadence.com>
---
 drivers/usb/cdns3/drd.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/cdns3/drd.c b/drivers/usb/cdns3/drd.c
index 55c73b1d8704..d00ff98dffab 100644
--- a/drivers/usb/cdns3/drd.c
+++ b/drivers/usb/cdns3/drd.c
@@ -483,11 +483,11 @@ int cdns_drd_exit(struct cdns *cdns)
 /* Indicate the cdns3 core was power lost before */
 bool cdns_power_is_lost(struct cdns *cdns)
 {
-	if (cdns->version == CDNS3_CONTROLLER_V1) {
-		if (!(readl(&cdns->otg_v1_regs->simulate) & BIT(0)))
+	if (cdns->version == CDNS3_CONTROLLER_V0) {
+		if (!(readl(&cdns->otg_v0_regs->simulate) & BIT(0)))
 			return true;
 	} else {
-		if (!(readl(&cdns->otg_v0_regs->simulate) & BIT(0)))
+		if (!(readl(&cdns->otg_v1_regs->simulate) & BIT(0)))
 			return true;
 	}
 	return false;
-- 
2.25.1


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

* Re: [PATCH] usb: cdnsp: Fix segmentation fault in cdns_lost_power function
  2022-01-11  9:07 [PATCH] usb: cdnsp: Fix segmentation fault in cdns_lost_power function Pawel Laszczak
@ 2022-01-12 12:56 ` Peter Chen
  2022-01-12 13:13   ` Pawel Laszczak
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Chen @ 2022-01-12 12:56 UTC (permalink / raw)
  To: Pawel Laszczak
  Cc: a-govindraju, frank.li, rogerq, gregkh, linux-usb, linux-kernel, stable

On 22-01-11 10:07:37, Pawel Laszczak wrote:
> From: Pawel Laszczak <pawell@cadence.com>
> 
> CDNSP driver read not initialized cdns->otg_v0_regs
> which lead to segmentation fault. Patch fixes this issue.
> 
> Fixes: 2cf2581cd229 ("usb: cdns3: add power lost support for system resume")
> cc: <stable@vger.kernel.org>
> Signed-off-by: Pawel Laszczak <pawell@cadence.com>
> ---
>  drivers/usb/cdns3/drd.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/usb/cdns3/drd.c b/drivers/usb/cdns3/drd.c
> index 55c73b1d8704..d00ff98dffab 100644
> --- a/drivers/usb/cdns3/drd.c
> +++ b/drivers/usb/cdns3/drd.c
> @@ -483,11 +483,11 @@ int cdns_drd_exit(struct cdns *cdns)
>  /* Indicate the cdns3 core was power lost before */
>  bool cdns_power_is_lost(struct cdns *cdns)
>  {
> -	if (cdns->version == CDNS3_CONTROLLER_V1) {
> -		if (!(readl(&cdns->otg_v1_regs->simulate) & BIT(0)))
> +	if (cdns->version == CDNS3_CONTROLLER_V0) {
> +		if (!(readl(&cdns->otg_v0_regs->simulate) & BIT(0)))
>  			return true;
>  	} else {
> -		if (!(readl(&cdns->otg_v0_regs->simulate) & BIT(0)))
> +		if (!(readl(&cdns->otg_v1_regs->simulate) & BIT(0)))
>  			return true;
>  	}
>  	return false;
> -- 

Pawel, may this lead cdns driver segment fault?

-- 

Thanks,
Peter Chen


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

* RE: [PATCH] usb: cdnsp: Fix segmentation fault in cdns_lost_power function
  2022-01-12 12:56 ` Peter Chen
@ 2022-01-12 13:13   ` Pawel Laszczak
  0 siblings, 0 replies; 3+ messages in thread
From: Pawel Laszczak @ 2022-01-12 13:13 UTC (permalink / raw)
  To: Peter Chen
  Cc: a-govindraju, frank.li, rogerq, gregkh, linux-usb, linux-kernel, stable

>
>On 22-01-11 10:07:37, Pawel Laszczak wrote:
>> From: Pawel Laszczak <pawell@cadence.com>
>>
>> CDNSP driver read not initialized cdns->otg_v0_regs
>> which lead to segmentation fault. Patch fixes this issue.
>>
>> Fixes: 2cf2581cd229 ("usb: cdns3: add power lost support for system resume")
>> cc: <stable@vger.kernel.org>
>> Signed-off-by: Pawel Laszczak <pawell@cadence.com>
>> ---
>>  drivers/usb/cdns3/drd.c | 6 +++---
>>  1 file changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/usb/cdns3/drd.c b/drivers/usb/cdns3/drd.c
>> index 55c73b1d8704..d00ff98dffab 100644
>> --- a/drivers/usb/cdns3/drd.c
>> +++ b/drivers/usb/cdns3/drd.c
>> @@ -483,11 +483,11 @@ int cdns_drd_exit(struct cdns *cdns)
>>  /* Indicate the cdns3 core was power lost before */
>>  bool cdns_power_is_lost(struct cdns *cdns)
>>  {
>> -	if (cdns->version == CDNS3_CONTROLLER_V1) {
>> -		if (!(readl(&cdns->otg_v1_regs->simulate) & BIT(0)))
>> +	if (cdns->version == CDNS3_CONTROLLER_V0) {
>> +		if (!(readl(&cdns->otg_v0_regs->simulate) & BIT(0)))
>>  			return true;
>>  	} else {
>> -		if (!(readl(&cdns->otg_v0_regs->simulate) & BIT(0)))
>> +		if (!(readl(&cdns->otg_v1_regs->simulate) & BIT(0)))
>>  			return true;
>>  	}
>>  	return false;
>> --
>
>Pawel, may this lead cdns driver segment fault?
>

Yes, we can observe such situation for CDNSP driver on simulation. 
As you know, it is a common code and driver support two version  of register map for DRD.

If cdns->version  == CDNSP_CONTROLLER_V2 (for CNDSP) the cdns->otg_v0_regs is NULL.
It will cause segmentation fault. 

I didn't analyze why this issue was not observed on my FPGA testing board.

Regards,

Pawel Laszczak  

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

end of thread, other threads:[~2022-01-12 13:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-11  9:07 [PATCH] usb: cdnsp: Fix segmentation fault in cdns_lost_power function Pawel Laszczak
2022-01-12 12:56 ` Peter Chen
2022-01-12 13:13   ` Pawel Laszczak

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