Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp1061537ybn; Wed, 25 Sep 2019 11:46:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqxGpf6h6N/mfg+a1xhLlu8FUHKqfKxH8yE3XMtUu+gPLz6JIxOzLsgLp5rtqvJNPh3i8NHg X-Received: by 2002:a17:906:6805:: with SMTP id k5mr693259ejr.50.1569437184876; Wed, 25 Sep 2019 11:46:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569437184; cv=none; d=google.com; s=arc-20160816; b=BCdYov9HowoqwS/ooKC27GGjW63h3iflqtp7P92qR0XX9Pj4bRRY5Xkn/9XwevuyUI iGukw1Nt5LzTWEVI9MqEiEbVXHuqrZotJ0ffL1knQYWA1H9c5Llk1MTgRjQYZr9c63kh jPraVBqWyIADl22JHYeYRPOMYD85oDVbtxODehbz+BHDuoULcb0b8eHb/WpwKTmluOaU vOxp5G94KlE1kdD7XuAeOh/uQKkXJ1IjjinJiIef6c391k17H4JIxppUX9NzafMItLpD SvxwhF1aKlLOFxYh20GNttexJqZGTFlVS6B3pgZ+1jCieFnOGSdXWaSLTHmpeufH0P0+ KA4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:in-reply-to :subject:cc:to:from:date; bh=SmDQ7x9Zq7mkQsHwUCUwlkoJEZ2Yh2DVq6+DpNyYDH8=; b=CwTYjE6LNiPwWDDyPUshGMaX7LYl3apidxPhqSK628sUEb4lshZvN3lWQx8OAHYGxN wxQojUNZyxrisci7B/ij08OcRc1i/0ExrUZkHB2HoLOPtg87nmQ6/4oNxUiKbOum+jHt 1oXtfbZ86tW5357+eamZWX2YBe4i9NUZGjPf3zt8IG5KZaHEo2tH6AyShVvXc//5firt VmZKo8OeAyXicH9j6efkBXMrEzthe8B7A1MG4N1Uc0jmstThLWzAqeIWlVBrAK4DBcm5 OHb/YAMBKb0zl0ubpoIRes0kaBKZ9rgjkeKte2p58c2k/w/UgwdgNblDbWerTeMx9bVD L45g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q1si4374778edj.354.2019.09.25.11.46.01; Wed, 25 Sep 2019 11:46:24 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728779AbfIWO6w (ORCPT + 99 others); Mon, 23 Sep 2019 10:58:52 -0400 Received: from netrider.rowland.org ([192.131.102.5]:33515 "HELO netrider.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1727164AbfIWO6v (ORCPT ); Mon, 23 Sep 2019 10:58:51 -0400 Received: (qmail 27342 invoked by uid 500); 23 Sep 2019 10:58:50 -0400 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 23 Sep 2019 10:58:50 -0400 Date: Mon, 23 Sep 2019 10:58:50 -0400 (EDT) From: Alan Stern X-X-Sender: stern@netrider.rowland.org To: Greg KH cc: Austin Kim , , , , , , , , Subject: Re: [PATCH] usb: hub: Minor refactoring in usb_hub_init() In-Reply-To: <20190923071145.GB2746429@kroah.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 23 Sep 2019, Greg KH wrote: > 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 > > --- > > 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. Indeed. In fact, I suspect that this change would make the code less understandable, because the reader would wonder why anybody would go to the trouble of jumping over a return statement. After all, this: if (!test) jump error; return 0; error: just looks like a strange and inefficient way of writing: if (test) return 0; Anyone reading it would wonder what the original author was thinking. If you really want to fix up this subroutine, you could change the two "return -1" statements. They should return an appropriate error code, not just -1. Alan Stern