lkml.org 
[lkml]   [2008]   [Jan]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    Date
    From
    SubjectRe: [PATCH 1/7] driver-core : add class iteration api
    On Sat, 12 Jan 2008 17:47:54 +0800,
    Dave Young <hidave.darkstar@gmail.com> wrote:

    Minor style suggestion (same for class_find_child):

    > +struct device *class_find_device(struct class *class, void *data,
    > + int (*match)(struct device *, void *))
    > +{
    > + struct device *dev;
    > + int error = 1;

    How about using inverse logic here (e.g., start with int found = 0)...

    > +
    > + if (!class)
    > + return NULL;
    > +
    > + down(&class->sem);
    > + list_for_each_entry(dev, &class->devices, node) {
    > + dev = get_device(dev);
    > + if (dev) {
    > + if (match(dev, data)) {
    > + error = 0;

    ...and set found = 1 here...

    > + break;
    > + } else
    > + put_device(dev);
    > + } else
    > + break;
    > + }
    > + up(&class->sem);
    > +
    > + if (error)
    > + return NULL;
    > + return dev;

    ...and do
    return found ? dev : NULL;
    in the end?

    Especially since not finding the device is not really an error.

    > +}

    Otherwise this looks fine to me.


    \
     
     \ /
      Last update: 2008-01-14 13:17    [W:0.025 / U:60.564 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site