public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Johannes Berg <johannes@sipsolutions.net>
To: Linux Kernel list <linux-kernel@vger.kernel.org>,
	John Lenz <lenz@cs.wisc.edu>,
	Richard Purdie <rpurdie@openedhand.com>
Subject: led_class: storing a value can act but return -EINVAL
Date: Sat, 29 Apr 2006 13:33:52 +0200	[thread overview]
Message-ID: <1146310432.5019.45.camel@localhost> (raw)

When I store something into the brightness sysfs attribute of an LED, it
will accept the value but return -EINVAL:

johannes:/sys/class/leds/pmu-front-led# echo 255 > brightness
bash: echo: write error: Invalid argument

(yet the LED turns on)

This happens because the store callback doesn't consume all the input.

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

The following patch implements a), for b) you'd have to make the if
statement have ' && after-buf == size' instead of this patch.

I don't know which approach is generally preferred, but acting and then
returning an error value doesn't seem nice.
Maybe b) should be implemented instead to stop people from storing
things like '0 hahaha stupid kernel ignores this' into the attribute :)

johannes

--- linux-2.6.orig/drivers/leds/led-class.c	2006-04-29 13:23:49.013288994 +0200
+++ linux-2.6/drivers/leds/led-class.c	2006-04-29 13:28:14.183288994 +0200
@@ -45,7 +45,7 @@ static ssize_t led_brightness_store(stru
 	unsigned long state = simple_strtoul(buf, &after, 10);
 
 	if (after - buf > 0) {
-		ret = after - buf;
+		ret = size;
 		led_set_brightness(led_cdev, state);
 	}
 



             reply	other threads:[~2006-04-29 11:34 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-04-29 11:33 Johannes Berg [this message]
2006-04-30 10:02 ` led_class: storing a value can act but return -EINVAL Pavel Machek
2006-04-30 11:01   ` Johannes Berg
2006-04-30 11:57     ` Richard Purdie
2006-04-30 12:05       ` Johannes Berg
2006-04-30 12:10     ` Pavel Machek

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=1146310432.5019.45.camel@localhost \
    --to=johannes@sipsolutions.net \
    --cc=lenz@cs.wisc.edu \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rpurdie@openedhand.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