linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Austin Kim <austindh.kim@gmail.com>
To: gregkh@linuxfoundation.org, stern@rowland.harvard.edu
Cc: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org,
	mathias.nyman@linux.intel.com, Thinh.Nguyen@synopsys.com,
	nsaenzjulienne@suse.de, jflat@chromium.org, malat@debian.org,
	dianders@chromium.org, austindh.kim@gmail.com
Subject: [PATCH] usb: hub: Minor refactoring in usb_hub_init()
Date: Mon, 23 Sep 2019 15:19:21 +0900	[thread overview]
Message-ID: <20190923061921.GA96726@LGEARND20B15> (raw)

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))
+		goto err_workqueue;
+
+	return 0;
 
+err_workqueue:
 	/* Fall through if kernel_thread failed */
 	usb_deregister(&hub_driver);
 	pr_err("%s: can't allocate workqueue for usb hub\n", usbcore_name);
-- 
2.6.2


             reply	other threads:[~2019-09-23  6:19 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-23  6:19 Austin Kim [this message]
2019-09-23  7:11 ` [PATCH] usb: hub: Minor refactoring in usb_hub_init() Greg KH
2019-09-23 14:58   ` Alan Stern
2019-09-25 10:10     ` Austin Kim

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190923061921.GA96726@LGEARND20B15 \
    --to=austindh.kim@gmail.com \
    --cc=Thinh.Nguyen@synopsys.com \
    --cc=dianders@chromium.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jflat@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=malat@debian.org \
    --cc=mathias.nyman@linux.intel.com \
    --cc=nsaenzjulienne@suse.de \
    --cc=stern@rowland.harvard.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).