lkml.org 
[lkml]   [2008]   [Jan]   [10]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    Date
    From
    SubjectRe: [PATCH 0/7] convert semaphore to mutex in struct class
    On Jan 10, 2008 9:23 PM, Cornelia Huck <cornelia.huck@de.ibm.com> wrote:
    > On Thu, 10 Jan 2008 17:48:43 +0800,
    > Dave Young <hidave.darkstar@gmail.com> wrote:
    >
    > Please add a kerneldoc comment for each of the new interfaces.
    Will do.
    >
    > > +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;
    > > + mutex_lock(&class->mutex);
    > > + list_for_each_entry(dev, &class->devices, node) {
    > > + error = fn(dev, data);
    >
    > Hm, the equivalent _for_each_device() functions all elevate the
    > device's refcount while calling fn(). I wonder whether we want this
    > here as well?

    Thanks for comment.
    Hm, I'm not sure about this. Greg, what's your opinion?

    >
    > > + if (error)
    > > + break;
    > > + }
    > > + mutex_unlock(&class->mutex);
    > > +
    > > + return error;
    > > +}
    > > +EXPORT_SYMBOL_GPL(class_for_each_device);
    > > +
    > > +struct device *class_find_device(struct class *class, void *data,
    > > + int (*match)(struct device *, void *))
    > > +{
    > > + struct device *dev;
    > > +
    > > + if (!class)
    > > + return NULL;
    > > +
    > > + mutex_lock(&class->mutex);
    > > + list_for_each_entry(dev, &class->devices, node)
    > > + if (match(dev, data) && get_device(dev))
    >
    > First get the reference and then drop it if the match function returns
    > 0 to make this analogous to the other _find_device() functions?

    It's just like other _find_device() functions. Are these more get/put
    really needed?

    >
    > > + break;
    > > + mutex_unlock(&class->mutex);
    > > +
    > > + return dev;
    > > +}
    > > +EXPORT_SYMBOL_GPL(class_find_device);
    > > +
    > > +int class_for_each_child(struct class *class, void *data,
    > > + int (*fn)(struct class_device *, void *))
    >
    > Haven't looked at the callers, but isn't it better to convert them to
    > use struct device instead so we don't need to introduce new
    > class_device api?

    The drivers/scsi/hosts.c need it.

    >
    > > +{
    > > + struct class_device *dev;
    > > + int error = 0;
    > > +
    > > + if (!class)
    > > + return -EINVAL;
    > > + mutex_lock(&class->mutex);
    > > + list_for_each_entry(dev, &class->children, node) {
    > > + error = fn(dev, data);
    >
    > Same comment as above concerning reference counts.
    >
    > > + if (error)
    > > + break;
    > > + }
    > > + mutex_unlock(&class->mutex);
    > > +
    > > + return error;
    > > +}
    > > +EXPORT_SYMBOL_GPL(class_for_each_child);
    > > +
    > > +struct class_device *class_find_child(struct class *class, void *data,
    > > + int (*match)(struct class_device *, void *))
    > > +{
    > > + struct class_device *dev;
    > > +
    > > + if (!class)
    > > + return NULL;
    > > +
    > > + mutex_lock(&class->mutex);
    > > + list_for_each_entry(dev, &class->children, node)
    > > + if (match(dev, data) && class_device_get(dev))
    >
    > And here.
    >
    >
    > > + break;
    > > + mutex_unlock(&class->mutex);
    > > +
    > > + return dev;
    > > +}
    > > +EXPORT_SYMBOL_GPL(class_find_child);
    > > +
    >


    \
     
     \ /
      Last update: 2008-01-11 03:35    [from the cache]
    ©2003-2014 Jasper Spaans. Advertise on this site