Re: [PATCH 1/7] driver-core : add class iteration api
From: Stefan Richter
Date: Sat Jan 12 2008 - 05:51:49 EST
Dave Young wrote:
> Add the following class iteration functions for driver use:
Thanks Dave. I will check the ieee1394 part in detail later.
...
> +/**
> + * class_find_device - device iterator for locating a particular device
> + * @class: the class we're iterating
> + * @data: data for the match function
> + * @match: function to check device
> + *
> + * This is similar to the class_for_each_dev() function above, but it
> + * returns a reference to a device that is 'found' for later use, as
> + * determined by the @match callback.
Maybe add "Drop the reference with put_device() after use." for the
really slow driver programmers like me?
> + *
> + * The callback should return 0 if the device doesn't match and non-zero
> + * if it does. If the callback returns non-zero, this function will
> + * return to the caller and not iterate over any more devices.
> + */
> +struct device *class_find_device(struct class *class, void *data,
> + int (*match)(struct device *, void *))
> +{
A general comment on the linux/device.h API (not a direct comment on
your patch):
The match argument in bus_find_device(), driver_find_device(),
device_find_child(), class_find_device(), class_find_child() could be
changed to
bool (*match)(struct device *, void *)).
Then the semantics are IMO a little bit clearer. Ditto for the
dr_match_t type and the struct bus_type.match member.
I don't know though whether the churn of doing such a change everywhere
would be justified by the result.
A comment on patch 2/7...6/7:
You can bring most or all of the various __match implementations into a
slightly terser but IMO easy to read form, like this:
static int __match_ne(struct device *dev, void *data)
{
struct unit_directory *ud;
struct node_entry *ne = (struct node_entry *)data;
ud = container_of(dev, struct unit_directory, unit_dev);
- if (ud->ne == ne)
- return 1;
- return 0;
+ return ud->ne == ne;
}
Here it is also easy to see that readability would improve if the return
type was bool rather than int.
--
Stefan Richter
-=====-==--- ---= -==--
http://arcgraph.de/sr/
--
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/