Received: by 10.192.165.148 with SMTP id m20csp3659800imm; Mon, 7 May 2018 16:45:13 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqJRBwO4Jy81K9uxBSr0/UtLTbs4UpdL1WqU5DF1ktDMHerM/RCfDKOVeX9PYpqiApi/Rpb X-Received: by 2002:a17:902:bf08:: with SMTP id bi8-v6mr38796865plb.353.1525736713093; Mon, 07 May 2018 16:45:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525736713; cv=none; d=google.com; s=arc-20160816; b=V8HSp2uP+wnF9Jwd3tMPmEsdXBDH0lfrPoHH33jpcdpTrWF5uUiQ0jrsZfV+HFgU09 2VcZBxKY/t/rFfMPNTc5TtftYCyyeGu2mpbgEz093qd3LheSF0q60uZpG9eKpMRg83mB h4AsrKBgURRY9KRUAHCJnlZ1hfXrMAP0R1aCXgaSIYITJFtkg0yC1JzxkiS8tAXFLqz2 8MHsWR4HhPks/3VqiFPX0sUJ1d6WDXBI6hgifOV68PBLmh2HJfdLAJ5DNOdCmfuzxfg5 l2JFX+jGkeVvzdphXQUasX5qS7XNi5HtFQ9Au0M2F1+Ob7oxD0UNYMrqEI/ajusp9xfa lX2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:message-id :in-reply-to:subject:cc:to:from:date:arc-authentication-results; bh=wtLBaQDQHNlkIE0cTANzDIVkZH8f0FEkHNj5EiyTawQ=; b=TPC9cgUE4y/Wd2PXjyzH9wLZOBV0uXgsLb/QHcjqLojWtKc1Ysm/EoLgaGpksyc7RP NcpxjQaDZqXqGBmvnXyOteHY3dAaOxWFeNBhAbxTLXhKZxQFVBD3aM/iT7uhfQncrwi2 nb1DbDsJWv2Gos6bDpP/hqWVCuvKFHoP9+gm1ppKmWB+/dEoqwdbh6O0uuEu4NdljYzs BENueuCV5IRAiSuqlZBIcBYjY3osLKSvoN8cZsyDEHZGmO/Wvbb0qsBgi4AxqjYbe1Md rpkqBq3o5bO/CXPNpGoKRaGWk143NR4pJGiUPFYJSFn2lksz3brBrmSIwsTQHg5C80xj BEbQ== 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 c9-v6si18873041pgw.657.2018.05.07.16.44.58; Mon, 07 May 2018 16:45:13 -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 S1753512AbeEGXod (ORCPT + 99 others); Mon, 7 May 2018 19:44:33 -0400 Received: from kvm5.telegraphics.com.au ([98.124.60.144]:36820 "EHLO kvm5.telegraphics.com.au" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753213AbeEGXoc (ORCPT ); Mon, 7 May 2018 19:44:32 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by kvm5.telegraphics.com.au (Postfix) with ESMTP id 5F76A28E42; Mon, 7 May 2018 19:44:28 -0400 (EDT) Date: Tue, 8 May 2018 09:44:33 +1000 (AEST) From: Finn Thain To: Greg Kroah-Hartman cc: Geert Uytterhoeven , linux-m68k@lists.linux-m68k.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] nubus: Unconditionally register bus type In-Reply-To: Message-ID: References: <5aee5ed3.1c69fb81.19d98.ef06SMTPIN_ADDED_MISSING@mx.google.com> <20180506045530.GA5328@kroah.com> <20180506202018.GC8924@kroah.com> 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, 7 May 2018, I wrote: > On Sun, 6 May 2018, Greg Kroah-Hartman wrote: > > > > > Why not just have an "bus is registered" flag in your driver > > > > register function that refuses to let drivers register with the > > > > driver core if it isn't set? > > > > > > Perhaps that should happen in the core driver_register() function. > > > BUG_ON is frowned upon, after all. Would that be acceptable? > > > > I don't understand what you mean here, perhaps make a patch to show it? > > > > As an alternative to your suggestion (add flag to avoid the BUG_ON): > > --- a/drivers/base/driver.c > +++ b/drivers/base/driver.c > @@ -148,7 +148,10 @@ int driver_register(struct device_driver *drv) > int ret; > struct device_driver *other; > > - BUG_ON(!drv->bus->p); > + if (!drv->bus->p) { > + WARN_ONCE(1, "Cannot register driver with invalid bus\n"); > + return -EPROBE_DEFER; > + } > > if ((drv->bus->probe && drv->probe) || > (drv->bus->remove && drv->remove) || > That rushed example I gave above seems to be confusing the issue. Sorry about that. (See sioux-core.c for the code that motivated it.) This example is the sort of flag removal that I had in mind -- diff --git a/drivers/base/driver.c b/drivers/base/driver.c index ba912558a510..4ee22fb3db92 100644 --- a/drivers/base/driver.c +++ b/drivers/base/driver.c @@ -148,7 +148,8 @@ int driver_register(struct device_driver *drv) int ret; struct device_driver *other; - BUG_ON(!drv->bus->p); + if (!drv->bus->p) + return -ENODEV; if ((drv->bus->probe && drv->probe) || (drv->bus->remove && drv->remove) || diff --git a/drivers/visorbus/visorbus_main.c b/drivers/visorbus/visorbus_main.c index 0b2434cc4ecd..73ff294fd449 100644 --- a/drivers/visorbus/visorbus_main.c +++ b/drivers/visorbus/visorbus_main.c @@ -19,8 +19,6 @@ static const guid_t visor_vbus_channel_guid = VISOR_VBUS_CHANNEL_GUID; #define LINESIZE 99 #define POLLJIFFIES_NORMALCHANNEL 10 -/* stores whether bus_registration was successful */ -static bool initialized; static struct dentry *visorbus_debugfs_dir; /* @@ -965,9 +963,6 @@ static int visordriver_probe_device(struct device *xdev) */ int visorbus_register_visor_driver(struct visor_driver *drv) { - /* can't register on a nonexistent bus */ - if (!initialized) - return -ENODEV; if (!drv->probe) return -EINVAL; if (!drv->remove) @@ -1212,7 +1207,6 @@ int visorbus_init(void) err = bus_register(&visorbus_type); if (err < 0) return err; - initialized = true; bus_device_info_init(&chipset_driverinfo, "chipset", "visorchipset"); return 0; } @@ -1229,6 +1223,5 @@ void visorbus_exit(void) visorbus_remove_instance(dev); } bus_unregister(&visorbus_type); - initialized = false; debugfs_remove_recursive(visorbus_debugfs_dir); } It's very hard to find examples of this pattern, where a flag is used to inhibit driver_register() calls. As a method of avoiding the BUG_ON this pattern is not popular. Hence, the opportunities for flag removal that I mentioned are similarly rare. So this kind of change is not something I would propose. Instead I would prefer either of the two solution I've previously sent, though any one of the 3 would actually resolve the bug reported by Michael. In anycase, I'm happy to work on a new solution if it would be more acceptable. Would you please explain how changing the link order would avoid the modprobe crash? I still can't figure it out. --