linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] usb: u132-hcd: fix potential NULL pointer dereference
@ 2019-03-14  7:27 Kangjie Lu
  2019-03-19 13:56 ` Greg Kroah-Hartman
  0 siblings, 1 reply; 6+ messages in thread
From: Kangjie Lu @ 2019-03-14  7:27 UTC (permalink / raw)
  To: kjlu
  Cc: pakki001, Greg Kroah-Hartman, Colin Ian King, Jia-Ju Bai,
	linux-usb, linux-kernel

In case create_singlethread_workqueue fails, the fix notifies
callers the error to avoid potential NULL pointer dereferences.

Signed-off-by: Kangjie Lu <kjlu@umn.edu>
---
 drivers/usb/host/u132-hcd.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/usb/host/u132-hcd.c b/drivers/usb/host/u132-hcd.c
index 934584f0a20a..6d5b532b03f8 100644
--- a/drivers/usb/host/u132-hcd.c
+++ b/drivers/usb/host/u132-hcd.c
@@ -3203,6 +3203,8 @@ static int __init u132_hcd_init(void)
 		return -ENODEV;
 	printk(KERN_INFO "driver %s\n", hcd_name);
 	workqueue = create_singlethread_workqueue("u132");
+	if (unlikely(!workqueue))
+		return -ENOMEM;
 	retval = platform_driver_register(&u132_platform_driver);
 	return retval;
 }
-- 
2.17.1


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

* Re: [PATCH] usb: u132-hcd: fix potential NULL pointer dereference
  2019-03-14  7:27 [PATCH] usb: u132-hcd: fix potential NULL pointer dereference Kangjie Lu
@ 2019-03-19 13:56 ` Greg Kroah-Hartman
  2019-03-19 17:20   ` Kangjie Lu
  2019-03-19 17:34   ` Kangjie Lu
  0 siblings, 2 replies; 6+ messages in thread
From: Greg Kroah-Hartman @ 2019-03-19 13:56 UTC (permalink / raw)
  To: Kangjie Lu; +Cc: pakki001, Colin Ian King, Jia-Ju Bai, linux-usb, linux-kernel

On Thu, Mar 14, 2019 at 02:27:11AM -0500, Kangjie Lu wrote:
> In case create_singlethread_workqueue fails, the fix notifies
> callers the error to avoid potential NULL pointer dereferences.
> 
> Signed-off-by: Kangjie Lu <kjlu@umn.edu>
> ---
>  drivers/usb/host/u132-hcd.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/usb/host/u132-hcd.c b/drivers/usb/host/u132-hcd.c
> index 934584f0a20a..6d5b532b03f8 100644
> --- a/drivers/usb/host/u132-hcd.c
> +++ b/drivers/usb/host/u132-hcd.c
> @@ -3203,6 +3203,8 @@ static int __init u132_hcd_init(void)
>  		return -ENODEV;
>  	printk(KERN_INFO "driver %s\n", hcd_name);
>  	workqueue = create_singlethread_workqueue("u132");
> +	if (unlikely(!workqueue))

You only ever use unlikely/likely if you can actually measure the
difference with and without it.  For stuff like this, it is not needed
at all, and in fact, the compiler and CPU already know this type of
thing, so it is going to be faster without it.

And are you sure you properly unwound from anything that was
created/initialized above these lines?

thanks,

greg k-h

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

* Re: [PATCH] usb: u132-hcd: fix potential NULL pointer dereference
  2019-03-19 13:56 ` Greg Kroah-Hartman
@ 2019-03-19 17:20   ` Kangjie Lu
  2019-03-19 17:34   ` Kangjie Lu
  1 sibling, 0 replies; 6+ messages in thread
From: Kangjie Lu @ 2019-03-19 17:20 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: pakki001, Colin Ian King, Jia-Ju Bai, linux-usb, linux-kernel


On 3/19/19 8:56 AM, Greg Kroah-Hartman wrote:
> On Thu, Mar 14, 2019 at 02:27:11AM -0500, Kangjie Lu wrote:
>> In case create_singlethread_workqueue fails, the fix notifies
>> callers the error to avoid potential NULL pointer dereferences.
>>
>> Signed-off-by: Kangjie Lu <kjlu@umn.edu>
>> ---
>>   drivers/usb/host/u132-hcd.c | 2 ++
>>   1 file changed, 2 insertions(+)
>>
>> diff --git a/drivers/usb/host/u132-hcd.c b/drivers/usb/host/u132-hcd.c
>> index 934584f0a20a..6d5b532b03f8 100644
>> --- a/drivers/usb/host/u132-hcd.c
>> +++ b/drivers/usb/host/u132-hcd.c
>> @@ -3203,6 +3203,8 @@ static int __init u132_hcd_init(void)
>>   		return -ENODEV;
>>   	printk(KERN_INFO "driver %s\n", hcd_name);
>>   	workqueue = create_singlethread_workqueue("u132");
>> +	if (unlikely(!workqueue))
> You only ever use unlikely/likely if you can actually measure the
> difference with and without it.  For stuff like this, it is not needed
> at all, and in fact, the compiler and CPU already know this type of
> thing, so it is going to be faster without it.
>
> And are you sure you properly unwound from anything that was
> created/initialized above these lines?
I didn't see what resources require release in this
case.
Given the existing error paths for usb_disabled() and
platform_driver_register(), returning -ENOMEM looks
like a consistent error handling. Let me know if it
isn't.


>
> thanks,
>
> greg k-h

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

* [PATCH] usb: u132-hcd: fix potential NULL pointer dereference
  2019-03-19 13:56 ` Greg Kroah-Hartman
  2019-03-19 17:20   ` Kangjie Lu
@ 2019-03-19 17:34   ` Kangjie Lu
  2019-03-26  4:41     ` Greg Kroah-Hartman
  1 sibling, 1 reply; 6+ messages in thread
From: Kangjie Lu @ 2019-03-19 17:34 UTC (permalink / raw)
  To: kjlu
  Cc: pakki001, Greg Kroah-Hartman, Colin Ian King, Jia-Ju Bai,
	linux-usb, linux-kernel

In case create_singlethread_workqueue fails, the fix notifies
callers the error to avoid potential NULL pointer dereferences.

Signed-off-by: Kangjie Lu <kjlu@umn.edu>
---
removed "unlikely"
---
 drivers/usb/host/u132-hcd.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/usb/host/u132-hcd.c b/drivers/usb/host/u132-hcd.c
index 934584f0a20a..6d5b532b03f8 100644
--- a/drivers/usb/host/u132-hcd.c
+++ b/drivers/usb/host/u132-hcd.c
@@ -3203,6 +3203,8 @@ static int __init u132_hcd_init(void)
 		return -ENODEV;
 	printk(KERN_INFO "driver %s\n", hcd_name);
 	workqueue = create_singlethread_workqueue("u132");
+	if (!workqueue)
+		return -ENOMEM;
 	retval = platform_driver_register(&u132_platform_driver);
 	return retval;
 }
-- 
2.17.1


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

* Re: [PATCH] usb: u132-hcd: fix potential NULL pointer dereference
  2019-03-19 17:34   ` Kangjie Lu
@ 2019-03-26  4:41     ` Greg Kroah-Hartman
  2019-03-27 13:57       ` Mukesh Ojha
  0 siblings, 1 reply; 6+ messages in thread
From: Greg Kroah-Hartman @ 2019-03-26  4:41 UTC (permalink / raw)
  To: Kangjie Lu; +Cc: pakki001, Colin Ian King, Jia-Ju Bai, linux-usb, linux-kernel

On Tue, Mar 19, 2019 at 12:34:06PM -0500, Kangjie Lu wrote:
> In case create_singlethread_workqueue fails, the fix notifies
> callers the error to avoid potential NULL pointer dereferences.
> 
> Signed-off-by: Kangjie Lu <kjlu@umn.edu>
> ---
> removed "unlikely"
> ---
>  drivers/usb/host/u132-hcd.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/usb/host/u132-hcd.c b/drivers/usb/host/u132-hcd.c
> index 934584f0a20a..6d5b532b03f8 100644
> --- a/drivers/usb/host/u132-hcd.c
> +++ b/drivers/usb/host/u132-hcd.c
> @@ -3203,6 +3203,8 @@ static int __init u132_hcd_init(void)
>  		return -ENODEV;
>  	printk(KERN_INFO "driver %s\n", hcd_name);
>  	workqueue = create_singlethread_workqueue("u132");
> +	if (!workqueue)
> +		return -ENOMEM;
>  	retval = platform_driver_register(&u132_platform_driver);
>  	return retval;

if platform_driver_register() fails, shouldn't you clean up the
workqueue?  That can be a separate patch, that's not your fault here :)

thanks,

greg k-h

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

* Re: [PATCH] usb: u132-hcd: fix potential NULL pointer dereference
  2019-03-26  4:41     ` Greg Kroah-Hartman
@ 2019-03-27 13:57       ` Mukesh Ojha
  0 siblings, 0 replies; 6+ messages in thread
From: Mukesh Ojha @ 2019-03-27 13:57 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Kangjie Lu
  Cc: pakki001, Colin Ian King, Jia-Ju Bai, linux-usb, linux-kernel

Please change the patch version in subject while sending patch.

On 3/26/2019 10:11 AM, Greg Kroah-Hartman wrote:
> On Tue, Mar 19, 2019 at 12:34:06PM -0500, Kangjie Lu wrote:
>> In case create_singlethread_workqueue fails, the fix notifies
>> callers the error to avoid potential NULL pointer dereferences.
>>
>> Signed-off-by: Kangjie Lu <kjlu@umn.edu>


Reviewed-by: Mukesh Ojha <mojha@codeaurora.org>

-Mukesh

>> ---
>> removed "unlikely"
>> ---
>>   drivers/usb/host/u132-hcd.c | 2 ++
>>   1 file changed, 2 insertions(+)
>>
>> diff --git a/drivers/usb/host/u132-hcd.c b/drivers/usb/host/u132-hcd.c
>> index 934584f0a20a..6d5b532b03f8 100644
>> --- a/drivers/usb/host/u132-hcd.c
>> +++ b/drivers/usb/host/u132-hcd.c
>> @@ -3203,6 +3203,8 @@ static int __init u132_hcd_init(void)
>>   		return -ENODEV;
>>   	printk(KERN_INFO "driver %s\n", hcd_name);
>>   	workqueue = create_singlethread_workqueue("u132");
>> +	if (!workqueue)
>> +		return -ENOMEM;
>>   	retval = platform_driver_register(&u132_platform_driver);
>>   	return retval;
> if platform_driver_register() fails, shouldn't you clean up the
> workqueue?  That can be a separate patch, that's not your fault here :)

I have taken care of it.

https://lore.kernel.org/patchwork/patch/1054800/



>
> thanks,
>
> greg k-h

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

end of thread, other threads:[~2019-03-27 13:57 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-14  7:27 [PATCH] usb: u132-hcd: fix potential NULL pointer dereference Kangjie Lu
2019-03-19 13:56 ` Greg Kroah-Hartman
2019-03-19 17:20   ` Kangjie Lu
2019-03-19 17:34   ` Kangjie Lu
2019-03-26  4:41     ` Greg Kroah-Hartman
2019-03-27 13:57       ` Mukesh Ojha

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