Standard handling of boolean attributes in sysfs.
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
Quoted 11 lines · Jonathan Cameron
Hi All,
Just wondering what the feeling would be about having a utility function similar to
sysfs_streqto provide a consistent option for all those sysfs attributes out there where1, on, true -> 1
0, off, false -> 0Or 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
Quoted 8 lines · Greg KH
Quoted 7 lines · Jonathan Cameron
Hi All,
Just wondering what the feeling would be about having a utility function similar to
sysfs_streqto provide a consistent option for all those sysfs attributes out there where
Quoted 8 lines
Quoted 4 lines
1, on, true -> 1
0, off, false -> 0Or 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
Quoted 40 lines · Jonathan Cameron
Quoted 8 lines · Greg KH
Quoted 7 lines · Jonathan Cameron
Hi All,
Just wondering what the feeling would be about having a utility function similar to
sysfs_streqto provide a consistent option for all those sysfs attributes out there whereQuoted 8 lines
Quoted 4 lines
1, on, true -> 1
0, off, false -> 0Or 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_boolinfs/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; }
Quoted 6 lines
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
Quoted 44 lines · Greg KH
Quoted 43 lines · Jonathan Cameron
Quoted 8 lines · Greg KH
Quoted 7 lines · Jonathan Cameron
Hi All,
Just wondering what the feeling would be about having a utility function similar to
sysfs_streqto provide a consistent option for all those sysfs attributes out there whereQuoted 8 lines
Quoted 4 lines
1, on, true -> 1
0, off, false -> 0Or 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_boolinfs/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 :).
Quoted 7 lines
Quoted 3 lines
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