All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hannes Reinecke <hare@suse.de>
To: Greg KH <greg@kroah.com>
Cc: Andrew Morton <akpm@osdl.org>,
	Linux Kernel <linux-kernel@vger.kernel.org>,
	Kay Sievers <Kay.Sievers@vrfy.org>
Subject: [PATCH] fix error handling in bus_add_device
Date: Thu, 12 May 2005 16:19:24 +0200	[thread overview]
Message-ID: <428365EC.80906@suse.de> (raw)

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

Hi Greg,

this patch fixes the error handling in bus_add_device() and
device_attach(). Previously it was 'interesting'.
And totally confusing to boot.

Please apply.

Cheers,

Hannes
-- 
Dr. Hannes Reinecke			hare@suse.de
SuSE Linux AG				S390 & zSeries
Maxfeldstraße 5				+49 911 74053 688
90409 Nürnberg				http://www.suse.de

[-- Attachment #2: sysfs-core-bus-check-error.patch --]
[-- Type: text/x-patch, Size: 2275 bytes --]

From: Hannes Reinecke <hare@suse.de>
Subject: Fix error handling in bus_add_device()

The error handling in bus_add_device() and device_attach() is simply
non-existing. This patch updates both function to align with the default
driver core convention to return '0' on success and an error code otherwise.
Note that '-ENODEV' is not an error for device_attach and driver_probe_device
as it is quite possible that no matching device was found.

Signed-off-by: Kay Sievers <kay.sievers@vrfy.org>

diff -pur linux-2.6.12-rc4.orig/drivers/base/bus.c linux-2.6.12-rc4/drivers/base/bus.c
--- linux-2.6.12-rc4.orig/drivers/base/bus.c	2005-05-06 23:20:31.000000000 -0600
+++ linux-2.6.12-rc4/drivers/base/bus.c	2005-05-12 08:05:02.000000000 -0600
@@ -312,11 +312,11 @@ int device_attach(struct device * dev)
 {
  	struct bus_type * bus = dev->bus;
 	struct list_head * entry;
-	int error;
+	int error = -ENODEV;
 
 	if (dev->driver) {
 		device_bind_driver(dev);
-		return 1;
+		return 0;
 	}
 
 	if (bus->match) {
@@ -325,7 +325,7 @@ int device_attach(struct device * dev)
 			error = driver_probe_device(drv, dev);
 			if (!error)
 				/* success, driver matched */
-				return 1;
+				return 0;
 			if (error != -ENODEV && error != -ENXIO)
 				/* driver matched but the probe failed */
 				printk(KERN_WARNING
@@ -334,7 +334,7 @@ int device_attach(struct device * dev)
 		}
 	}
 
-	return 0;
+	return error;
 }
 
 
@@ -460,11 +460,17 @@ int bus_add_device(struct device * dev)
 		down_write(&dev->bus->subsys.rwsem);
 		pr_debug("bus %s: add device %s\n", bus->name, dev->bus_id);
 		list_add_tail(&dev->bus_list, &dev->bus->devices.list);
-		device_attach(dev);
+		error = device_attach(dev);
 		up_write(&dev->bus->subsys.rwsem);
-		device_add_attrs(bus, dev);
-		sysfs_create_link(&bus->devices.kobj, &dev->kobj, dev->bus_id);
-		sysfs_create_link(&dev->kobj, &dev->bus->subsys.kset.kobj, "bus");
+		if (!error || error == -ENODEV)
+			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");
+		} else {
+			pr_debug("bus %s: attach device %s failed with %d\n", bus->name, dev->bus_id, error);
+			put_bus(bus);
+		}
 	}
 	return error;
 }

             reply	other threads:[~2005-05-12 14:19 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-05-12 14:19 Hannes Reinecke [this message]
2005-05-18  5:56 ` [PATCH] fix error handling in bus_add_device Greg KH
2005-05-18  7:19   ` Hannes Reinecke
2005-05-18  7:32     ` Greg KH
2005-05-18  8:42       ` Hannes Reinecke

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=428365EC.80906@suse.de \
    --to=hare@suse.de \
    --cc=Kay.Sievers@vrfy.org \
    --cc=akpm@osdl.org \
    --cc=greg@kroah.com \
    --cc=linux-kernel@vger.kernel.org \
    /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 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.