Re: led_class: storing a value can act but return -EINVAL

From: Richard Purdie
Date: Sun Apr 30 2006 - 07:59:09 EST


On Sun, 2006-04-30 at 13:01 +0200, Johannes Berg wrote:
> Hi,
>
> > Well, I'd argue current behaviour is okay... can you strace it? It
> > should accept the number (return 3) then return -EINVAL.
>
> That's exactly what happens.
>
> Which is totally bogus, because userspace will think that the setting
> didn't succeed. Or application authors will ignore the return value
> assuming that it always succeeded. Or read the value back to see if it
> succeeded. All icky, when we can well have a good return value.
>
> > > There are two possible ways to handle this:
> > > a) accept anything that begins with a valid number.
> > > b) reject anything that isn't *only* a number
> >
> > c) accept anything that is number, ignore newlines.

echo 255> brightness works, returns success.
echo 255 > brightness works but then returns -EINVAL.

So we currently do b, quite strictly. Its the trailing space thats the
problem. It also shouldn't have altered the brightness value if it ends
up returning -EINVAL.

I've looked around other implementations and it would appear we should
accept an optional space. Most sysfs attributes seem to handle this
differently, each with its own "bugs".

I've some fixes in mind both for the led and backlight classes which
I'll post once I've done a little more testing. I'd be interested to
know the official view on what the attributes should/shouldn't accept
is.

Cheers,

Richard

-
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/