lkml.org 
[lkml]   [2009]   [Sep]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH V6 1/2] introduce ALS sysfs class
Hi!

> Introduce ALS sysfs class.
>
> ALS sysfs class provides a standard sysfs interface for
> Ambient Light Sensor devices.
>
> please read Documentation/ABI/testing/sysfs-class-als for
> detailed sysfs designs.

Thanks for fixing the interface!

> +static ssize_t
> +illuminance_show(struct device *dev, struct device_attribute *attr, char *buf)
> +{
> + struct als_device *als = to_als_device(dev);
> + int illuminance;
> + int result;
> +
> + result = als->ops->get_illuminance(als, &illuminance);
> + if (result)
> + return result;
> +
> + if (!illuminance)
> + return sprintf(buf, "Illuminance below the supported range\n");
> + else if (illuminance == -1)
> + return sprintf(buf, "Illuminance above the supported range\n");
> + else if (illuminance < -1)
> + return -ERANGE;
> + else
> + return sprintf(buf, "%d\n", illuminance);
> +}

that's nor particulary clean. One value per file and all that. Could
we simply return errnos in _all_ the error cases? (Docs would suggest
this contains integer so string is definitely unexpected).


> +static ssize_t
> +adjustment_show(struct device *dev, struct device_attribute *attr, char *buf)
> +{
> + struct als_device *als = to_als_device(dev);
> + int illuminance, adjustment;
> + int result;
> +
> + result = als->ops->get_illuminance(als, &illuminance);
> + if (result)
> + return result;
> +
> + if (illuminance < 0 && illuminance != -1)
> + return sprintf(buf, "Current illuminance invalid\n");
> +
> + result = als_get_adjustment(als, illuminance, &adjustment);
> + if (result)
> + return result;
> +
> + return sprintf(buf, "%d%%\n", adjustment);
> +}

You should not return strings... and in this case it is not clear how
the code works. You fill the buf, but then return...? Better stick to
integers.
Pavel

--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html


\
 
 \ /
  Last update: 2009-09-01 10:13    [W:0.087 / U:1.252 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site