Re: [PATCH 1/6] driver-core : add class iteration api

From: David Brownell
Date: Tue Jan 22 2008 - 01:24:31 EST


On Monday 21 January 2008, Dave Young wrote:
>
> +/**
> + * class_for_each_device - device iterator
> + * @class: the class we're iterating
> + * @data: data for the callback
> + * @fn: function to be called for each device
> + *
> + * Iterate over @class's list of devices, and call @fn for each,
> + * passing it @data.
> + *
> + * We check the return of @fn each time. If it returns anything
> + * other than 0, we break out and return that value.

I have a suggestion for better documentation, which
applies to all these utilities:


> + */
> +int class_for_each_device(struct class *class, void *data,
> + int (*fn)(struct device *, void *))
> +{
> + struct device *dev;
> + int error = 0;
> +
> + if (!class)
> + return -EINVAL;
> + down(&class->sem);
> + list_for_each_entry(dev, &class->devices, node) {
> + dev = get_device(dev);
> + if (dev) {
> + error = fn(dev, data);

This is called with class->sem held. So fn() has a
constraint to not re-acquire that ... else it'd be
self-deadlocking. I'd like to see docs at least
mention that; calls to add or remove class members
would be verboten, for example, which isn't an issue
with most other driver model iterators.


> + put_device(dev);
> + } else
> + error = -ENODEV;
> + if (error)
> + break;
> + }
> + up(&class->sem);
> +
> + return error;
> +}
> +EXPORT_SYMBOL_GPL(class_for_each_device);
--
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/