LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Finn Thain <fthain@telegraphics.com.au>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>,
	linux-m68k@lists.linux-m68k.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] nubus: Unconditionally register bus type
Date: Tue, 8 May 2018 09:44:33 +1000 (AEST)	[thread overview]
Message-ID: <alpine.LNX.2.21.1805080904460.8@nippy.intranet> (raw)
In-Reply-To: <alpine.LNX.2.21.1805070930240.8@nippy.intranet>

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.

-- 

  parent reply	other threads:[~2018-05-07 23:44 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-06  1:47 Finn Thain
2018-05-06  4:55 ` Greg Kroah-Hartman
2018-05-06  6:00   ` Finn Thain
2018-05-06 20:20     ` Greg Kroah-Hartman
2018-05-06 21:51       ` Michael Schmitz
2018-05-08  7:00         ` Greg Kroah-Hartman
2018-05-08  7:07           ` Geert Uytterhoeven
2018-05-08  7:25             ` Greg Kroah-Hartman
2018-05-08  7:35               ` Geert Uytterhoeven
2018-05-08  7:41                 ` Greg Kroah-Hartman
2018-05-08  8:01               ` Michael Schmitz
2018-05-06 23:57       ` Finn Thain
2018-05-07 12:53         ` Geert Uytterhoeven
2018-05-07 14:45           ` Greg Kroah-Hartman
2018-05-08  6:28             ` Geert Uytterhoeven
2018-05-07 23:44         ` Finn Thain [this message]
2018-05-08  6:32           ` Geert Uytterhoeven
2018-05-08  7:59             ` Finn Thain
2018-05-08  7:01         ` Greg Kroah-Hartman
2018-05-06  1:47 Finn Thain
     [not found] <5aee5ede.1c69fb81.353b4.5021SMTPIN_ADDED_MISSING@mx.google.com>
2018-05-08  7:39 ` Geert Uytterhoeven
2018-05-08  8:27   ` Finn Thain

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=alpine.LNX.2.21.1805080904460.8@nippy.intranet \
    --to=fthain@telegraphics.com.au \
    --cc=geert@linux-m68k.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-m68k@lists.linux-m68k.org \
    --subject='Re: [PATCH] nubus: Unconditionally register bus type' \
    /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

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