about probing a device

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: wit
Date: Tuesday, October 9, 2007 - 6:39 pm

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
-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
about probing a device, wit, (Tue Oct 9, 6:39 pm)
Re: about probing a device, Greg KH, (Tue Oct 9, 9:46 pm)
Re: about probing a device, Alan Cox, (Wed Oct 10, 5:09 am)
Re: about probing a device, wit, (Wed Oct 10, 8:50 am)
Re: about probing a device, Cornelia Huck, (Wed Oct 10, 9:26 am)
Re: about probing a device, wit, (Thu Oct 11, 3:44 am)