From: Pavel Machek <pavel@ucw.cz>
To: Zhang Rui <rui.zhang@intel.com>
Cc: Len Brown <lenb@kernel.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
linux-acpi <linux-acpi@vger.kernel.org>, Greg KH <greg@kroah.com>
Subject: Re: [PATCH V6 1/2] introduce ALS sysfs class
Date: Tue, 1 Sep 2009 10:43:06 +0200 [thread overview]
Message-ID: <20090901084306.GD9942@elf.ucw.cz> (raw)
In-Reply-To: <1251793844.3483.228.camel@rzhang-dt>
On Tue 2009-09-01 16:30:44, Zhang Rui wrote:
> On Tue, 2009-09-01 at 16:11 +0800, Pavel Machek wrote:
> > 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).
> >
> IMO, 0 and -1 are not errors. they just suggest that the Ambient Light
> illuminance is beyond the device support range, while the device is
> still working normally.
> what about exporting these values (0 and -1) to user space directly?
Returning 0 for "below" range and 99999999 for "above" range would be
nice, yes.
> >
> > > +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...?
>
> As the adjustment is a percentage value, I added a '%' postfix so that
> users won't be confused.
> yes, it's okay to just export the integer, e.g. "100" instead of "100%".
The "%" postfix is okay, but returning "Current illuminance invalid"
is ugly. Better return -EINVAL or -EIO or something.
Pavel
--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
next prev parent reply other threads:[~2009-09-01 8:43 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-09-01 7:25 [PATCH V6 1/2] introduce ALS sysfs class Zhang Rui
2009-09-01 8:11 ` Pavel Machek
2009-09-01 8:30 ` Zhang Rui
2009-09-01 8:43 ` Pavel Machek [this message]
2009-09-01 18:47 ` Rafael J. Wysocki
2009-09-01 13:41 ` Pavel Machek
2009-09-02 21:12 ` Rafael J. Wysocki
2009-09-02 21:14 ` Pavel Machek
2009-09-02 21:46 ` Rafael J. Wysocki
2009-09-02 21:51 ` Pavel Machek
2009-09-03 0:16 ` Rafael J. Wysocki
2009-09-03 2:35 ` Zhang Rui
2009-09-03 8:45 ` Pavel Machek
2009-09-03 21:13 ` Rafael J. Wysocki
2009-09-03 8:43 ` Pavel Machek
2009-09-03 21:10 ` Rafael J. Wysocki
2009-09-02 19:22 ` Alan Jenkins
2009-09-03 2:45 ` Zhang Rui
2009-09-03 8:35 ` Alan Jenkins
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20090901084306.GD9942@elf.ucw.cz \
--to=pavel@ucw.cz \
--cc=greg@kroah.com \
--cc=lenb@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rui.zhang@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox