lkml.org 
[lkml]   [2019]   [Sep]   [23]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] usb: hub: Minor refactoring in usb_hub_init()
On Mon, Sep 23, 2019 at 03:19:21PM +0900, Austin Kim wrote:
> Normally when creation of workqueue fails, exception handling takes place
> after the call to alloc_workqueue() is made.
>
> But looking into usb_hub_init() function, 'return 0' statement is executed,
> when alloc_workqueue() returns valid workqueue pointer.
> if (hub_wq)
> return 0;
>
> This might make other Linux driver developers get confused
> because they could deduce that this is exceptional handling routine.
>
> So perform minor refactoring by adding NULL pointer dereference check
> routine right after the call to alloc_workqueue() is made.
>
> Signed-off-by: Austin Kim <austindh.kim@gmail.com>
> ---
> drivers/usb/core/hub.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
> index e8ebacc..0ddbfe6 100644
> --- a/drivers/usb/core/hub.c
> +++ b/drivers/usb/core/hub.c
> @@ -5530,9 +5530,12 @@ int usb_hub_init(void)
> * over to the companion full-speed controller.
> */
> hub_wq = alloc_workqueue("usb_hub_wq", WQ_FREEZABLE, 0);
> - if (hub_wq)
> - return 0;
> + if (unlikely(!hub_wq))

Only ever use likely/unlikely if you can measure the difference without
it. Otherwise the compiler and cpu will almost always do this better
than you.

So please remove this.

> + goto err_workqueue;
> +
> + return 0;
>
> +err_workqueue:
> /* Fall through if kernel_thread failed */

This comment is now incorrect.

But really, there is nothing wrong with the original code here. It
works properly, and while it is not identical to normal code "style"
here, there's nothing wrong with it that I can see.

thanks,

greg k-h

\
 
 \ /
  Last update: 2019-09-23 09:12    [W:0.044 / U:0.032 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site