kernel-janitors.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] usb: dwc3: Fix dereferencing of null dwc->usb_psy
@ 2021-03-03  9:58 Colin King
  2021-03-03 16:02 ` Ray Chi
  0 siblings, 1 reply; 4+ messages in thread
From: Colin King @ 2021-03-03  9:58 UTC (permalink / raw)
  To: Felipe Balbi, Greg Kroah-Hartman, Ray Chi, linux-usb
  Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

Currently the null check logic on dwc->usb_psy is inverted as it allows
calls to power_supply_put with a null dwc->usb_psy causing a null
pointer dereference. Fix this by removing the ! operator.

Addresses-Coverity: ("Dereference after null check")
Fixes: 59fa3def35de ("usb: dwc3: add a power supply for current control")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/usb/dwc3/core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index d15f065849cd..94fdbe502ce9 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -1628,7 +1628,7 @@ static int dwc3_probe(struct platform_device *pdev)
 assert_reset:
 	reset_control_assert(dwc->reset);
 
-	if (!dwc->usb_psy)
+	if (dwc->usb_psy)
 		power_supply_put(dwc->usb_psy);
 
 	return ret;
@@ -1653,7 +1653,7 @@ static int dwc3_remove(struct platform_device *pdev)
 	dwc3_free_event_buffers(dwc);
 	dwc3_free_scratch_buffers(dwc);
 
-	if (!dwc->usb_psy)
+	if (dwc->usb_psy)
 		power_supply_put(dwc->usb_psy);
 
 	return 0;
-- 
2.30.0


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

* Re: [PATCH] usb: dwc3: Fix dereferencing of null dwc->usb_psy
  2021-03-03  9:58 [PATCH] usb: dwc3: Fix dereferencing of null dwc->usb_psy Colin King
@ 2021-03-03 16:02 ` Ray Chi
  2021-03-03 21:29   ` Heiko Thiery
  0 siblings, 1 reply; 4+ messages in thread
From: Ray Chi @ 2021-03-03 16:02 UTC (permalink / raw)
  To: Colin King
  Cc: Felipe Balbi, Greg Kroah-Hartman, linux-usb, kernel-janitors,
	linux-kernel

On Wed, Mar 3, 2021 at 6:00 PM Colin King <colin.king@canonical.com> wrote:
>
> From: Colin Ian King <colin.king@canonical.com>
>
> Currently the null check logic on dwc->usb_psy is inverted as it allows
> calls to power_supply_put with a null dwc->usb_psy causing a null
> pointer dereference. Fix this by removing the ! operator.
>
> Addresses-Coverity: ("Dereference after null check")
> Fixes: 59fa3def35de ("usb: dwc3: add a power supply for current control")

Acked-by: Ray Chi <raychi@google.com>

> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  drivers/usb/dwc3/core.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
> index d15f065849cd..94fdbe502ce9 100644
> --- a/drivers/usb/dwc3/core.c
> +++ b/drivers/usb/dwc3/core.c
> @@ -1628,7 +1628,7 @@ static int dwc3_probe(struct platform_device *pdev)
>  assert_reset:
>         reset_control_assert(dwc->reset);
>
> -       if (!dwc->usb_psy)
> +       if (dwc->usb_psy)
>                 power_supply_put(dwc->usb_psy);
>
>         return ret;
> @@ -1653,7 +1653,7 @@ static int dwc3_remove(struct platform_device *pdev)
>         dwc3_free_event_buffers(dwc);
>         dwc3_free_scratch_buffers(dwc);
>
> -       if (!dwc->usb_psy)
> +       if (dwc->usb_psy)
>                 power_supply_put(dwc->usb_psy);
>
>         return 0;
> --
> 2.30.0
>

Thanks for fixing this bug!

Regards,
Ray

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

* Re: [PATCH] usb: dwc3: Fix dereferencing of null dwc->usb_psy
  2021-03-03 16:02 ` Ray Chi
@ 2021-03-03 21:29   ` Heiko Thiery
  2021-03-03 22:47     ` Colin Ian King
  0 siblings, 1 reply; 4+ messages in thread
From: Heiko Thiery @ 2021-03-03 21:29 UTC (permalink / raw)
  To: raychi
  Cc: balbi, colin.king, gregkh, kernel-janitors, linux-kernel,
	linux-usb, Heiko Thiery

Hi all,

> On Wed, Mar 3, 2021 at 6:00 PM Colin King <colin.king@canonical.com> wrote:
>>
>> From: Colin Ian King <colin.king@canonical.com>
>>
>> Currently the null check logic on dwc->usb_psy is inverted as it allows
>> calls to power_supply_put with a null dwc->usb_psy causing a null
>> pointer dereference. Fix this by removing the ! operator.
>>
>> Addresses-Coverity: ("Dereference after null check")
>> Fixes: 59fa3def35de ("usb: dwc3: add a power supply for current control")
>
> Acked-by: Ray Chi <raychi@google.com>
>
>> Signed-off-by: Colin Ian King <colin.king@canonical.com>

Tested-by: Heiko Thiery <heiko.thiery@gmail.com>

>> ---
>>  drivers/usb/dwc3/core.c | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
>> index d15f065849cd..94fdbe502ce9 100644
>> --- a/drivers/usb/dwc3/core.c
>> +++ b/drivers/usb/dwc3/core.c
>> @@ -1628,7 +1628,7 @@ static int dwc3_probe(struct platform_device *pdev)
>>  assert_reset:
>>         reset_control_assert(dwc->reset);
>>
>> -       if (!dwc->usb_psy)
>> +       if (dwc->usb_psy)
>>                 power_supply_put(dwc->usb_psy);
>>
>>         return ret;
>> @@ -1653,7 +1653,7 @@ static int dwc3_remove(struct platform_device *pdev)
>>         dwc3_free_event_buffers(dwc);
>>         dwc3_free_scratch_buffers(dwc);
>>
>> -       if (!dwc->usb_psy)
>> +       if (dwc->usb_psy)
>>                 power_supply_put(dwc->usb_psy);
>>
>>         return 0;
>> --
>> 2.30.0
>>

Thank you.

-- 
Heiko

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

* Re: [PATCH] usb: dwc3: Fix dereferencing of null dwc->usb_psy
  2021-03-03 21:29   ` Heiko Thiery
@ 2021-03-03 22:47     ` Colin Ian King
  0 siblings, 0 replies; 4+ messages in thread
From: Colin Ian King @ 2021-03-03 22:47 UTC (permalink / raw)
  To: Heiko Thiery, raychi
  Cc: balbi, gregkh, kernel-janitors, linux-kernel, linux-usb

On 03/03/2021 21:29, Heiko Thiery wrote:
> Hi all,
> 
>> On Wed, Mar 3, 2021 at 6:00 PM Colin King <colin.king@canonical.com> wrote:
>>>
>>> From: Colin Ian King <colin.king@canonical.com>
>>>
>>> Currently the null check logic on dwc->usb_psy is inverted as it allows
>>> calls to power_supply_put with a null dwc->usb_psy causing a null
>>> pointer dereference. Fix this by removing the ! operator.
>>>
>>> Addresses-Coverity: ("Dereference after null check")
>>> Fixes: 59fa3def35de ("usb: dwc3: add a power supply for current control")
>>
>> Acked-by: Ray Chi <raychi@google.com>
>>
>>> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> 
> Tested-by: Heiko Thiery <heiko.thiery@gmail.com>

Thanks for testing. Much appreciated.

Colin
> 
>>> ---
>>>  drivers/usb/dwc3/core.c | 4 ++--
>>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
>>> index d15f065849cd..94fdbe502ce9 100644
>>> --- a/drivers/usb/dwc3/core.c
>>> +++ b/drivers/usb/dwc3/core.c
>>> @@ -1628,7 +1628,7 @@ static int dwc3_probe(struct platform_device *pdev)
>>>  assert_reset:
>>>         reset_control_assert(dwc->reset);
>>>
>>> -       if (!dwc->usb_psy)
>>> +       if (dwc->usb_psy)
>>>                 power_supply_put(dwc->usb_psy);
>>>
>>>         return ret;
>>> @@ -1653,7 +1653,7 @@ static int dwc3_remove(struct platform_device *pdev)
>>>         dwc3_free_event_buffers(dwc);
>>>         dwc3_free_scratch_buffers(dwc);
>>>
>>> -       if (!dwc->usb_psy)
>>> +       if (dwc->usb_psy)
>>>                 power_supply_put(dwc->usb_psy);
>>>
>>>         return 0;
>>> --
>>> 2.30.0
>>>
> 
> Thank you.
> 


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

end of thread, other threads:[~2021-03-04  0:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-03  9:58 [PATCH] usb: dwc3: Fix dereferencing of null dwc->usb_psy Colin King
2021-03-03 16:02 ` Ray Chi
2021-03-03 21:29   ` Heiko Thiery
2021-03-03 22:47     ` Colin Ian King

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