diff mbox series

sysfs: add BIN_ATTR_WO() macro

Message ID 20190826150153.GD18418@kroah.com (mailing list archive)
State New, archived
Headers show
Series sysfs: add BIN_ATTR_WO() macro | expand

Commit Message

Greg KH Aug. 26, 2019, 3:01 p.m. UTC
This variant was missing from sysfs.h, I guess no one noticed it before.

Turns out the powerpc secure variable code can use it, so add it to the
tree for it, and potentially others to take advantage of, instead of
open-coding it.

Reported-by: Nayna Jain <nayna@linux.ibm.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---

I'll queue this up to my tree for 5.4-rc1, but if you want to take this
in your tree earlier, feel free to do so.

 include/linux/sysfs.h | 9 +++++++++
 1 file changed, 9 insertions(+)

Comments

Michael Ellerman Sept. 3, 2019, 3:37 a.m. UTC | #1
Greg Kroah-Hartman <gregkh@linuxfoundation.org> writes:
> This variant was missing from sysfs.h, I guess no one noticed it before.
>
> Turns out the powerpc secure variable code can use it, so add it to the
> tree for it, and potentially others to take advantage of, instead of
> open-coding it.
>
> Reported-by: Nayna Jain <nayna@linux.ibm.com>
> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> ---
>
> I'll queue this up to my tree for 5.4-rc1, but if you want to take this
> in your tree earlier, feel free to do so.

OK. This series is blocked on the firmware support going in, so at the
moment it might miss v5.4 anyway. So this going via your tree is no
problem.

If it does make it into v5.4 we can do a fixup patch to use the new
macro once everything's in Linus' tree.

cheers

> diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
> index 965236795750..5420817ed317 100644
> --- a/include/linux/sysfs.h
> +++ b/include/linux/sysfs.h
> @@ -196,6 +196,12 @@ struct bin_attribute {
>  	.size	= _size,						\
>  }
>  
> +#define __BIN_ATTR_WO(_name) {						\
> +	.attr	= { .name = __stringify(_name), .mode = 0200 },		\
> +	.store	= _name##_store,					\
> +	.size	= _size,						\
> +}
> +
>  #define __BIN_ATTR_RW(_name, _size)					\
>  	__BIN_ATTR(_name, 0644, _name##_read, _name##_write, _size)
>  
> @@ -208,6 +214,9 @@ struct bin_attribute bin_attr_##_name = __BIN_ATTR(_name, _mode, _read,	\
>  #define BIN_ATTR_RO(_name, _size)					\
>  struct bin_attribute bin_attr_##_name = __BIN_ATTR_RO(_name, _size)
>  
> +#define BIN_ATTR_WO(_name, _size)					\
> +struct bin_attribute bin_attr_##_name = __BIN_ATTR_WO(_name, _size)
> +
>  #define BIN_ATTR_RW(_name, _size)					\
>  struct bin_attribute bin_attr_##_name = __BIN_ATTR_RW(_name, _size)
>  
> -- 
> 2.23.0
Greg KH Sept. 4, 2019, 11:36 a.m. UTC | #2
On Tue, Sep 03, 2019 at 01:37:02PM +1000, Michael Ellerman wrote:
> Greg Kroah-Hartman <gregkh@linuxfoundation.org> writes:
> > This variant was missing from sysfs.h, I guess no one noticed it before.
> >
> > Turns out the powerpc secure variable code can use it, so add it to the
> > tree for it, and potentially others to take advantage of, instead of
> > open-coding it.
> >
> > Reported-by: Nayna Jain <nayna@linux.ibm.com>
> > Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > ---
> >
> > I'll queue this up to my tree for 5.4-rc1, but if you want to take this
> > in your tree earlier, feel free to do so.
> 
> OK. This series is blocked on the firmware support going in, so at the
> moment it might miss v5.4 anyway. So this going via your tree is no
> problem.

Ok, will queue it up now, thanks!

greg k-h
Nayna Oct. 1, 2019, 6:08 p.m. UTC | #3
Hi Greg,


On 08/26/2019 11:01 AM, Greg Kroah-Hartman wrote:
> This variant was missing from sysfs.h, I guess no one noticed it before.
>
> Turns out the powerpc secure variable code can use it, so add it to the
> tree for it, and potentially others to take advantage of, instead of
> open-coding it.
>
> Reported-by: Nayna Jain <nayna@linux.ibm.com>
> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> ---
>
> I'll queue this up to my tree for 5.4-rc1, but if you want to take this
> in your tree earlier, feel free to do so.
>
>   include/linux/sysfs.h | 9 +++++++++
>   1 file changed, 9 insertions(+)
>
> diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
> index 965236795750..5420817ed317 100644
> --- a/include/linux/sysfs.h
> +++ b/include/linux/sysfs.h
> @@ -196,6 +196,12 @@ struct bin_attribute {
>   	.size	= _size,						\
>   }
>   
> +#define __BIN_ATTR_WO(_name) {						\
> +	.attr	= { .name = __stringify(_name), .mode = 0200 },		\
> +	.store	= _name##_store,					\
> +	.size	= _size,						\
> +}
> +
>   #define __BIN_ATTR_RW(_name, _size)					\
>   	__BIN_ATTR(_name, 0644, _name##_read, _name##_write, _size)
>   
> @@ -208,6 +214,9 @@ struct bin_attribute bin_attr_##_name = __BIN_ATTR(_name, _mode, _read,	\
>   #define BIN_ATTR_RO(_name, _size)					\
>   struct bin_attribute bin_attr_##_name = __BIN_ATTR_RO(_name, _size)
>   
> +#define BIN_ATTR_WO(_name, _size)					\
> +struct bin_attribute bin_attr_##_name = __BIN_ATTR_WO(_name, _size)
> +
>   #define BIN_ATTR_RW(_name, _size)					\
>   struct bin_attribute bin_attr_##_name = __BIN_ATTR_RW(_name, _size)
>   

I am sorry. I didn't notice it via inspection but there is a bug in this 
macro. When I actually try using it, compilation fails. Here's a likely 
patch:

diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
index 5420817ed317..fa7ee503fb76 100644
--- a/include/linux/sysfs.h
+++ b/include/linux/sysfs.h
@@ -196,9 +196,9 @@ struct bin_attribute {
         .size   = _size,                                                \
  }
  
-#define __BIN_ATTR_WO(_name) {                                         \
+#define __BIN_ATTR_WO(_name, _size) {                                  \
         .attr   = { .name = __stringify(_name), .mode = 0200 },         \
-       .store  = _name##_store,                                        \
+       .write  = _name##_write,                                        \
         .size   = _size,                                                \
  }


Thanks & Regards,
     - Nayna
Greg KH Oct. 1, 2019, 6:16 p.m. UTC | #4
On Tue, Oct 01, 2019 at 02:08:53PM -0400, Nayna wrote:
> Hi Greg,
> 
> 
> On 08/26/2019 11:01 AM, Greg Kroah-Hartman wrote:
> > This variant was missing from sysfs.h, I guess no one noticed it before.
> > 
> > Turns out the powerpc secure variable code can use it, so add it to the
> > tree for it, and potentially others to take advantage of, instead of
> > open-coding it.
> > 
> > Reported-by: Nayna Jain <nayna@linux.ibm.com>
> > Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > ---
> > 
> > I'll queue this up to my tree for 5.4-rc1, but if you want to take this
> > in your tree earlier, feel free to do so.
> > 
> >   include/linux/sysfs.h | 9 +++++++++
> >   1 file changed, 9 insertions(+)
> > 
> > diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
> > index 965236795750..5420817ed317 100644
> > --- a/include/linux/sysfs.h
> > +++ b/include/linux/sysfs.h
> > @@ -196,6 +196,12 @@ struct bin_attribute {
> >   	.size	= _size,						\
> >   }
> > +#define __BIN_ATTR_WO(_name) {						\
> > +	.attr	= { .name = __stringify(_name), .mode = 0200 },		\
> > +	.store	= _name##_store,					\
> > +	.size	= _size,						\
> > +}
> > +
> >   #define __BIN_ATTR_RW(_name, _size)					\
> >   	__BIN_ATTR(_name, 0644, _name##_read, _name##_write, _size)
> > @@ -208,6 +214,9 @@ struct bin_attribute bin_attr_##_name = __BIN_ATTR(_name, _mode, _read,	\
> >   #define BIN_ATTR_RO(_name, _size)					\
> >   struct bin_attribute bin_attr_##_name = __BIN_ATTR_RO(_name, _size)
> > +#define BIN_ATTR_WO(_name, _size)					\
> > +struct bin_attribute bin_attr_##_name = __BIN_ATTR_WO(_name, _size)
> > +
> >   #define BIN_ATTR_RW(_name, _size)					\
> >   struct bin_attribute bin_attr_##_name = __BIN_ATTR_RW(_name, _size)
> 
> I am sorry. I didn't notice it via inspection but there is a bug in this
> macro. When I actually try using it, compilation fails. Here's a likely
> patch:
> 
> diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
> index 5420817ed317..fa7ee503fb76 100644
> --- a/include/linux/sysfs.h
> +++ b/include/linux/sysfs.h
> @@ -196,9 +196,9 @@ struct bin_attribute {
>         .size   = _size,                                                \
>  }
> -#define __BIN_ATTR_WO(_name) {                                         \
> +#define __BIN_ATTR_WO(_name, _size) {                                  \
>         .attr   = { .name = __stringify(_name), .mode = 0200 },         \
> -       .store  = _name##_store,                                        \
> +       .write  = _name##_write,                                        \
>         .size   = _size,                                                \
>  }
> 

Heh, good catch.  Can you send a real patch for this that I can apply to
give you the proper credit for finding and fixing this?

thanks,

greg k-h
Nayna Oct. 1, 2019, 6:55 p.m. UTC | #5
On 10/01/2019 02:16 PM, Greg Kroah-Hartman wrote:
> On Tue, Oct 01, 2019 at 02:08:53PM -0400, Nayna wrote:
>> Hi Greg,
>>
>>
>> On 08/26/2019 11:01 AM, Greg Kroah-Hartman wrote:
>>> This variant was missing from sysfs.h, I guess no one noticed it before.
>>>
>>> Turns out the powerpc secure variable code can use it, so add it to the
>>> tree for it, and potentially others to take advantage of, instead of
>>> open-coding it.
>>>
>>> Reported-by: Nayna Jain <nayna@linux.ibm.com>
>>> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
>>> ---
>>>
>>> I'll queue this up to my tree for 5.4-rc1, but if you want to take this
>>> in your tree earlier, feel free to do so.
>>>
>>>    include/linux/sysfs.h | 9 +++++++++
>>>    1 file changed, 9 insertions(+)
>>>
>>> diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
>>> index 965236795750..5420817ed317 100644
>>> --- a/include/linux/sysfs.h
>>> +++ b/include/linux/sysfs.h
>>> @@ -196,6 +196,12 @@ struct bin_attribute {
>>>    	.size	= _size,						\
>>>    }
>>> +#define __BIN_ATTR_WO(_name) {						\
>>> +	.attr	= { .name = __stringify(_name), .mode = 0200 },		\
>>> +	.store	= _name##_store,					\
>>> +	.size	= _size,						\
>>> +}
>>> +
>>>    #define __BIN_ATTR_RW(_name, _size)					\
>>>    	__BIN_ATTR(_name, 0644, _name##_read, _name##_write, _size)
>>> @@ -208,6 +214,9 @@ struct bin_attribute bin_attr_##_name = __BIN_ATTR(_name, _mode, _read,	\
>>>    #define BIN_ATTR_RO(_name, _size)					\
>>>    struct bin_attribute bin_attr_##_name = __BIN_ATTR_RO(_name, _size)
>>> +#define BIN_ATTR_WO(_name, _size)					\
>>> +struct bin_attribute bin_attr_##_name = __BIN_ATTR_WO(_name, _size)
>>> +
>>>    #define BIN_ATTR_RW(_name, _size)					\
>>>    struct bin_attribute bin_attr_##_name = __BIN_ATTR_RW(_name, _size)
>> I am sorry. I didn't notice it via inspection but there is a bug in this
>> macro. When I actually try using it, compilation fails. Here's a likely
>> patch:
>>
>> diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
>> index 5420817ed317..fa7ee503fb76 100644
>> --- a/include/linux/sysfs.h
>> +++ b/include/linux/sysfs.h
>> @@ -196,9 +196,9 @@ struct bin_attribute {
>>          .size   = _size,                                                \
>>   }
>> -#define __BIN_ATTR_WO(_name) {                                         \
>> +#define __BIN_ATTR_WO(_name, _size) {                                  \
>>          .attr   = { .name = __stringify(_name), .mode = 0200 },         \
>> -       .store  = _name##_store,                                        \
>> +       .write  = _name##_write,                                        \
>>          .size   = _size,                                                \
>>   }
>>
> Heh, good catch.  Can you send a real patch for this that I can apply to
> give you the proper credit for finding and fixing this?

Sure.. Thanks Greg !!

Thanks & Regards,
       - Nayna
diff mbox series

Patch

diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
index 965236795750..5420817ed317 100644
--- a/include/linux/sysfs.h
+++ b/include/linux/sysfs.h
@@ -196,6 +196,12 @@  struct bin_attribute {
 	.size	= _size,						\
 }
 
+#define __BIN_ATTR_WO(_name) {						\
+	.attr	= { .name = __stringify(_name), .mode = 0200 },		\
+	.store	= _name##_store,					\
+	.size	= _size,						\
+}
+
 #define __BIN_ATTR_RW(_name, _size)					\
 	__BIN_ATTR(_name, 0644, _name##_read, _name##_write, _size)
 
@@ -208,6 +214,9 @@  struct bin_attribute bin_attr_##_name = __BIN_ATTR(_name, _mode, _read,	\
 #define BIN_ATTR_RO(_name, _size)					\
 struct bin_attribute bin_attr_##_name = __BIN_ATTR_RO(_name, _size)
 
+#define BIN_ATTR_WO(_name, _size)					\
+struct bin_attribute bin_attr_##_name = __BIN_ATTR_WO(_name, _size)
+
 #define BIN_ATTR_RW(_name, _size)					\
 struct bin_attribute bin_attr_##_name = __BIN_ATTR_RW(_name, _size)