public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* about probing a device
@ 2007-10-10  1:39 wit
  2007-10-10  4:46 ` Greg KH
  2007-10-10 12:09 ` Alan Cox
  0 siblings, 2 replies; 7+ messages in thread
From: wit @ 2007-10-10  1:39 UTC (permalink / raw)
  To: linux-kernel

Hi,
I found these routines in the kernel, does this means only one driver
can be matched to a device? What if two drivers both can drive the
device, like sd & sg in scsi subsystem?

static int device_attach(struct device * dev)
{
 	struct bus_type * bus = dev->bus;
	struct list_head * entry;
	int error;

	if (dev->driver) {
		device_bind_driver(dev);
		return 1;
	}

	if (bus->match) {
		list_for_each(entry, &bus->drivers.list) {
			struct device_driver * drv = to_drv(entry);
			error = bus_match(dev, drv);
			if (!error)
				/* success, driver matched */
				return 1;
			if (error != -ENODEV && error != -ENXIO)
				/* driver matched but the probe failed */
				printk(KERN_WARNING
				    "%s: probe of %s failed with error %d\n",
				    drv->name, dev->bus_id, error);
		}
	}

	return 0;
}

void driver_attach(struct device_driver * drv)
{
	struct bus_type * bus = drv->bus;
	struct list_head * entry;
	int error;

	if (!bus->match)
		return;

	list_for_each(entry, &bus->devices.list) {
		struct device * dev = container_of(entry, struct device, bus_list);
		if (!dev->driver) {
			error = bus_match(dev, drv);
			if (error && (error != -ENODEV))
				/* driver matched but the probe failed */
				printk(KERN_WARNING
				    "%s: probe of %s failed with error %d\n",
				    drv->name, dev->bus_id, error);
		}
	}
}

Thanks

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

end of thread, other threads:[~2007-10-11 10:44 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-10-10  1:39 about probing a device wit
2007-10-10  4:46 ` Greg KH
     [not found]   ` <105610bf0710100841t1c9463c1q9742534c8bb0dfe5@mail.gmail.com>
2007-10-10 15:59     ` Greg KH
2007-10-10 12:09 ` Alan Cox
2007-10-10 15:50   ` wit
2007-10-10 16:26     ` Cornelia Huck
2007-10-11 10:44       ` wit

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox