All of lore.kernel.org
 help / color / mirror / Atom feed
* bus_add_device() losing an error return from the probe() method
@ 2006-03-24  5:32 Rene Herman
  2006-03-26  1:53 ` Andrew Morton
                   ` (3 more replies)
  0 siblings, 4 replies; 47+ messages in thread
From: Rene Herman @ 2006-03-24  5:32 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: Takashi Iwai, ALSA devel, Linux Kernel

[-- Attachment #1: Type: text/plain, Size: 1197 bytes --]

Hi Greg, Takashi.

ALSA moved all ISA drivers over to the platform_driver interface in
2.6.16, using this code structure in the module_inits:

    cards = 0;
    for (i = 0; i < SNDRV_CARDS; i++) {
	  struct platform_device *device;
	  device = platform_device_register_simple(
			SND_FOO_DRIVER, i, NULL, 0);
	  if (IS_ERR(device)) {
		  err = PTR_ERR(device);
		  goto errout;
	  }
	  devices[i] = device;
	  cards++;
    }
    if (!cards) {
	  printk(KERN_ERR "FOO soundcard not found or device busy\n");
	  err = -ENODEV;
	  goto errout;
    }
    return 0;
errout:
    snd_foo_unregister_all();
    return err;

Unfortunately, the snd_foo_unregister_all() part here is unreachable
under normal circumstances, since platform_device_register_simple()
returns !IS_ERR, regardless of what the driver probe method returned.
The driver then never fails to load, even when no cards were found.

An error return from the driver probe() method is carried up through
device_attach, but is then dropped on the floor in bus_add_device(). If
I apply the attached patch, things work as I (and ALSA it seems) expect.
Is it correct?

(the printk still isn't reached, but see next message for that).

Rene.



[-- Attachment #2: bus_add_device.diff --]
[-- Type: text/plain, Size: 1055 bytes --]

Index: local/drivers/base/bus.c
===================================================================
--- local.orig/drivers/base/bus.c	2006-02-27 19:22:08.000000000 +0100
+++ local/drivers/base/bus.c	2006-03-24 04:27:02.000000000 +0100
@@ -363,19 +363,21 @@ static void device_remove_attrs(struct b
 int bus_add_device(struct device * dev)
 {
 	struct bus_type * bus = get_bus(dev->bus);
-	int error = 0;
+	int error;
 
 	if (bus) {
 		pr_debug("bus %s: add device %s\n", bus->name, dev->bus_id);
-		device_attach(dev);
+		error = device_attach(dev);
+		if (error < 0)
+			return error;
 		klist_add_tail(&dev->knode_bus, &bus->klist_devices);
 		error = device_add_attrs(bus, dev);
-		if (!error) {
-			sysfs_create_link(&bus->devices.kobj, &dev->kobj, dev->bus_id);
-			sysfs_create_link(&dev->kobj, &dev->bus->subsys.kset.kobj, "bus");
-		}
+		if (error)
+			return error;
+		sysfs_create_link(&bus->devices.kobj, &dev->kobj, dev->bus_id);
+		sysfs_create_link(&dev->kobj, &dev->bus->subsys.kset.kobj, "bus");
 	}
-	return error;
+	return 0;
 }
 
 /**


^ permalink raw reply	[flat|nested] 47+ messages in thread

end of thread, other threads:[~2006-04-06  1:06 UTC | newest]

Thread overview: 47+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-03-24  5:32 bus_add_device() losing an error return from the probe() method Rene Herman
2006-03-26  1:53 ` Andrew Morton
2006-03-26  1:53 ` Andrew Morton
2006-03-26 22:30   ` Rene Herman
2006-03-26 22:30   ` Rene Herman
2006-04-04 19:10 ` patch bus_add_device-losing-an-error-return-from-the-probe-method.patch added to gregkh-2.6 tree gregkh
2006-04-04 20:23   ` Dmitry Torokhov
2006-04-04 21:00     ` Greg KH
2006-04-04 21:15       ` Greg KH
2006-04-04 21:15         ` Greg KH
2006-04-04 21:22         ` Andrew Morton
2006-04-04 21:22         ` Andrew Morton
2006-04-04 21:28       ` Dmitry Torokhov
2006-04-04 21:45         ` Greg KH
2006-04-05  1:35           ` Dmitry Torokhov
2006-04-05  1:35             ` Dmitry Torokhov
2006-04-05  7:36             ` Russell King
2006-04-06  1:05               ` Greg KH
2006-04-06  1:05               ` Greg KH
2006-04-05  7:36             ` Russell King
2006-04-05  1:59           ` Dmitry Torokhov
2006-04-05  1:59           ` Dmitry Torokhov
2006-04-04 21:45         ` Greg KH
2006-04-04 21:28       ` Dmitry Torokhov
2006-04-04 22:12       ` Rene Herman
2006-04-05  0:23         ` Rene Herman
2006-04-05  0:23         ` Rene Herman
2006-04-05  1:45           ` Dmitry Torokhov
2006-04-05  1:45             ` Dmitry Torokhov
2006-04-05 18:36             ` Rene Herman
2006-04-05 18:44               ` Dmitry Torokhov
2006-04-05 18:44               ` Dmitry Torokhov
2006-04-05 18:36             ` Rene Herman
2006-04-05  1:48         ` Dmitry Torokhov
2006-04-05  1:48         ` Dmitry Torokhov
2006-04-05 13:50           ` Rene Herman
2006-04-05 14:59             ` Dmitry Torokhov
2006-04-05 14:59             ` Dmitry Torokhov
2006-04-05 21:22               ` Rene Herman
2006-04-05 21:22               ` Rene Herman
2006-04-05 13:50           ` Rene Herman
2006-04-05 13:55           ` Rene Herman
2006-04-05 13:55           ` Rene Herman
2006-04-04 22:12       ` Rene Herman
2006-04-04 21:00     ` Greg KH
2006-04-04 20:23   ` Dmitry Torokhov
2006-04-04 19:10 ` gregkh

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.