Re: [patch 1/16] s390: klist bus_find_device & driver_find_device callback.

From: Greg KH
Date: Wed Jun 22 2005 - 03:34:44 EST

On Wed, Jun 22, 2005 at 09:48:02AM +0200, Cornelia Huck wrote:
> Greg KH <greg@xxxxxxxxx> wrote on 22.06.2005 08:26:27:
> > What's wrong with just using bus_for_each_dev() instead? You have to
> > supply a "match" type function anyway, so the caller doesn't have an
> > easier time using this function instead.
> Maybe it's just too early in the morning, but I don't see how I could
> achive what I want to do with bus_for_each_dev(). The idea behind
> bus_find_device() is to scan the bus for a device matching some
> criterium and to return a pointer to it with which the caller can
> continue to work. bus_for_each_dev() calls the match function for
> every device until we abort, but I don't see how I can grab a reference
> to a specific device for later use.

Ah, now I get it. "later use" is the key point here. I was thinking
you could do whatever you want within the callback. But if you want to
do something later on with this pointer, that would be very tough.

Hm, I could use this kind of function, as I had to jump through a few
hoops when iterating over all devices on a bus, when I just wanted to
find a specific device (it involved creating a temp structure on the
stack and doing my logic in the callback function itself, for details
for a patch that adds manual binding of drivers to devices from
userspace through sysfs. With this function it should get even smaller.)

> > You also don't increment the reference properly when you return the
> > pointer, so you better document that... :(
> You're right, this should be done in the base code and not by the
> caller...

Care to fix this up and resend it?

Sorry for the misunderstanding.


greg k-h
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at
Please read the FAQ at