Re: kobj_to_dev ?

From: Hollis Blanchard
Date: Mon Jan 19 2004 - 22:20:46 EST


On Jan 19, 2004, at 6:53 PM, Greg KH wrote:

> I don't know. If you enable debugging for kobjects (in kobject.c) do
> you see any kobjects getting added to your bus with no name?

Sigh, that took too long.

c000000001d29828 -- address of the struct device I register
c000000001d29818 -- address present in vio_bus_type.devices.list

I think the problem is that bus_add_device() adds a struct device to bus_type.devices.list, but that's a a kset! So it contains a list of kobjects, not devices. The obvious fix doesn't work because driver_attach() got it wrong too. However it seems bus_for_each_dev() got it right.

This patch compiles but I haven't tested the driver_attach() part yet. Oh also to_dev is different in bus.c than in core.c, so I don't think it will work here. I'm going home... I have a vague feeling that some other language might work better for all this list stuff..

--
Hollis Blanchard
IBM Linux Technology Center

===== drivers/base/bus.c 1.52 vs edited =====
--- 1.52/drivers/base/bus.c Tue Sep 30 10:59:35 2003
+++ edited/drivers/base/bus.c Mon Jan 19 21:19:18 2004
@@ -337,7 +337,12 @@
return;

list_for_each(entry,&bus->devices.list) {
- struct device * dev = container_of(entry,struct device,bus_list);
+ struct kobject * kobj = container_of(entry,struct kobject,entry);
+ struct device * dev;
+
+ if (!kobj)
+ return;
+ dev = container_of(kobj,struct device,kobj);
if (!dev->driver) {
error = bus_match(dev,drv);
if (error && (error != -ENODEV))
@@ -405,7 +410,7 @@
if (bus) {
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);
+ list_add_tail(&dev->kobj.entry,&dev->bus->devices.list);
device_attach(dev);
up_write(&dev->bus->subsys.rwsem);

sysfs_create_link(&bus->devices.kobj,&dev->kobj,dev->bus_id);

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/