public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@cam.ac.uk>
To: Greg KH <greg@kroah.com>
Cc: LKML <linux-kernel@vger.kernel.org>,
	David Brownell <david-b@pacbell.net>
Subject: Re: Standard handling of boolean attributes in sysfs.
Date: Tue, 22 Mar 2011 10:59:43 +0000	[thread overview]
Message-ID: <4D88811F.7060901@cam.ac.uk> (raw)
In-Reply-To: <20110321201411.GA1704@kroah.com>

On 03/21/11 20:14, Greg KH wrote:
> On Mon, Mar 21, 2011 at 08:02:40PM +0000, Jonathan Cameron wrote:
>> Hi All,
>>
>> Just wondering what the feeling would be about having
>> a utility function similar to sysfs_streq to provide a
>> consistent option for all those sysfs attributes out there
>> where
>>
>> 1, on, true -> 1
>> 0, off, false -> 0
>>
>> Or does such a beast already exist and I'm just being unobservant?
> 
> We have the one in debugfs that I think people use for sysfs.  Have you
> looked at that?
> 
Thanks for the pointer...

write_file_bool in fs/debugfs/file.c?  

What is there is pretty much what is needed, but it's not a general
use function like sysfs_streq. Clearly it would make sense to use
what is there as a basis of such a function. 

To save others looking it up, the relevant bit is:

	switch (buf[0]) {
	case 'y':
	case 'Y':
	case '1':
		*val = 1;
		break;
	case 'n':
	case 'N':
	case '0':
		*val = 0;
		break;
	}

There are a few cut and paste copies of this about (mostly in IIO drivers actually
hence why I asking if there is a better way :).

Unless there is demand for it elsewhere I'll just add a utility function to the IIO
core to do this and we can revisit the case for a general function when the need
turns up elsewhere.

Jonathan

  reply	other threads:[~2011-03-22 10:58 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-21 20:02 Standard handling of boolean attributes in sysfs Jonathan Cameron
2011-03-21 20:14 ` Greg KH
2011-03-22 10:59   ` Jonathan Cameron [this message]
2011-03-22 22:30     ` Greg KH
2011-03-23 10:53       ` Jonathan Cameron

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=4D88811F.7060901@cam.ac.uk \
    --to=jic23@cam.ac.uk \
    --cc=david-b@pacbell.net \
    --cc=greg@kroah.com \
    --cc=linux-kernel@vger.kernel.org \
    /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