linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Standard handling of boolean attributes in sysfs.
@ 2011-03-21 20:02 Jonathan Cameron
  2011-03-21 20:14 ` Greg KH
  0 siblings, 1 reply; 5+ messages in thread
From: Jonathan Cameron @ 2011-03-21 20:02 UTC (permalink / raw)
  To: LKML, Greg KH, David Brownell

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?

Jonathan

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Standard handling of boolean attributes in sysfs.
  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
  0 siblings, 1 reply; 5+ messages in thread
From: Greg KH @ 2011-03-21 20:14 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: LKML, David Brownell

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,

greg k-h

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Standard handling of boolean attributes in sysfs.
  2011-03-21 20:14 ` Greg KH
@ 2011-03-22 10:59   ` Jonathan Cameron
  2011-03-22 22:30     ` Greg KH
  0 siblings, 1 reply; 5+ messages in thread
From: Jonathan Cameron @ 2011-03-22 10:59 UTC (permalink / raw)
  To: Greg KH; +Cc: LKML, David Brownell

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Standard handling of boolean attributes in sysfs.
  2011-03-22 10:59   ` Jonathan Cameron
@ 2011-03-22 22:30     ` Greg KH
  2011-03-23 10:53       ` Jonathan Cameron
  0 siblings, 1 reply; 5+ messages in thread
From: Greg KH @ 2011-03-22 22:30 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: LKML, David Brownell

On Tue, Mar 22, 2011 at 10:59:43AM +0000, Jonathan Cameron wrote:
> 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.

The other function that does this, and is what I was thinking of, is
param_set_bool().  Care to merge both of these functions together into
something "sane" and have everyone use it?

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Standard handling of boolean attributes in sysfs.
  2011-03-22 22:30     ` Greg KH
@ 2011-03-23 10:53       ` Jonathan Cameron
  0 siblings, 0 replies; 5+ messages in thread
From: Jonathan Cameron @ 2011-03-23 10:53 UTC (permalink / raw)
  To: Greg KH; +Cc: LKML, David Brownell

On 03/22/11 22:30, Greg KH wrote:
> On Tue, Mar 22, 2011 at 10:59:43AM +0000, Jonathan Cameron wrote:
>> 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.
> 
> The other function that does this, and is what I was thinking of, is
> param_set_bool().  Care to merge both of these functions together into
> something "sane" and have everyone use it?
Will put out an RFC labeled patch on this and see how it goes down.

Jonathan


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2011-03-23 10:52 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2011-03-22 22:30     ` Greg KH
2011-03-23 10:53       ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).