diff mbox

[-next,2/4] treewide: Use DEVICE_ATTR_RW

Message ID cd38f14f06e1f447b3159ffe8c69c0df8241bb6e.1513706701.git.joe@perches.com (mailing list archive)
State New, archived
Headers show

Commit Message

Joe Perches Dec. 19, 2017, 6:15 p.m. UTC
Convert DEVICE_ATTR uses to DEVICE_ATTR_RW where possible.

Done with perl script:

$ git grep -w --name-only DEVICE_ATTR | \
  xargs perl -i -e 'local $/; while (<>) { s/\bDEVICE_ATTR\s*\(\s*(\w+)\s*,\s*\(?(\s*S_IRUGO\s*\|\s*S_IWUSR|\s*S_IWUSR\s*\|\s*S_IRUGO\s*|\s*0644\s*)\)?\s*,\s*\1_show\s*,\s*\1_store\s*\)/DEVICE_ATTR_RW(\1)/g; print;}'

Signed-off-by: Joe Perches <joe@perches.com>
---
 arch/s390/kernel/topology.c          |  3 +--
 arch/tile/kernel/sysfs.c             |  2 +-
 drivers/gpu/drm/i915/i915_sysfs.c    |  6 ++---
 drivers/platform/x86/compal-laptop.c | 18 +++++----------
 drivers/s390/cio/device.c            |  2 +-
 drivers/scsi/lpfc/lpfc_attr.c        | 43 ++++++++++++------------------------
 drivers/thermal/thermal_sysfs.c      |  9 ++++----
 drivers/tty/serial/sh-sci.c          |  2 +-
 drivers/usb/host/xhci-dbgcap.c       |  2 +-
 drivers/usb/phy/phy-tahvo.c          |  2 +-
 drivers/video/fbdev/auo_k190x.c      |  4 ++--
 drivers/video/fbdev/w100fb.c         |  4 ++--
 lib/test_firmware.c                  | 14 +++++-------
 lib/test_kmod.c                      | 14 +++++-------
 sound/soc/omap/mcbsp.c               |  4 ++--
 15 files changed, 49 insertions(+), 80 deletions(-)

Comments

Andy Shevchenko Dec. 19, 2017, 6:41 p.m. UTC | #1
On Tue, Dec 19, 2017 at 8:15 PM, Joe Perches <joe@perches.com> wrote:
> Convert DEVICE_ATTR uses to DEVICE_ATTR_RW where possible.
>
> Done with perl script:
>
> $ git grep -w --name-only DEVICE_ATTR | \
>   xargs perl -i -e 'local $/; while (<>) { s/\bDEVICE_ATTR\s*\(\s*(\w+)\s*,\s*\(?(\s*S_IRUGO\s*\|\s*S_IWUSR|\s*S_IWUSR\s*\|\s*S_IRUGO\s*|\s*0644\s*)\)?\s*,\s*\1_show\s*,\s*\1_store\s*\)/DEVICE_ATTR_RW(\1)/g; print;}'

>  drivers/platform/x86/compal-laptop.c | 18 +++++----------

> --- a/drivers/platform/x86/compal-laptop.c
> +++ b/drivers/platform/x86/compal-laptop.c
> @@ -679,18 +679,12 @@ static int bat_writeable_property(struct power_supply *psy,
>  /* ============== */
>  /* Driver Globals */
>  /* ============== */
> -static DEVICE_ATTR(wake_up_pme,
> -               0644, wake_up_pme_show,         wake_up_pme_store);
> -static DEVICE_ATTR(wake_up_modem,
> -               0644, wake_up_modem_show,       wake_up_modem_store);
> -static DEVICE_ATTR(wake_up_lan,
> -               0644, wake_up_lan_show, wake_up_lan_store);
> -static DEVICE_ATTR(wake_up_wlan,
> -               0644, wake_up_wlan_show,        wake_up_wlan_store);
> -static DEVICE_ATTR(wake_up_key,
> -               0644, wake_up_key_show, wake_up_key_store);
> -static DEVICE_ATTR(wake_up_mouse,
> -               0644, wake_up_mouse_show,       wake_up_mouse_store);
> +static DEVICE_ATTR_RW(wake_up_pme);
> +static DEVICE_ATTR_RW(wake_up_modem);
> +static DEVICE_ATTR_RW(wake_up_lan);
> +static DEVICE_ATTR_RW(wake_up_wlan);
> +static DEVICE_ATTR_RW(wake_up_key);
> +static DEVICE_ATTR_RW(wake_up_mouse);

Acked-by: Andy Shevchenko <andy.shevchenko@gmail.com>

for PDx86 bits.

Have to say that while it doesn't change the attributes here, it might
require still to be revisited by security people, if they wish.
Jidong Zhang Dec. 20, 2017, 7:19 a.m. UTC | #2
Does anyone know how to use Conexant CX20921 to develop our own application. I cannot find anywhere to download the software and manuals.

Thanks to all
J.D

-----Original Message-----
From: alsa-devel-bounces@alsa-project.org [mailto:alsa-devel-bounces@alsa-project.org] On Behalf Of Andy Shevchenko

Sent: 2017年12月20日 2:42
To: Joe Perches <joe@perches.com>
Cc: linux-fbdev@vger.kernel.org; David Airlie <airlied@linux.ie>; Joonas Lahtinen <joonas.lahtinen@linux.intel.com>; Heiko Carstens <heiko.carstens@de.ibm.com>; ALSA Development Mailing List <alsa-devel@alsa-project.org>; dri-devel@lists.freedesktop.org; Peter Ujfalusi <peter.ujfalusi@ti.com>; linux-s390@vger.kernel.org; Linux OMAP Mailing List <linux-omap@vger.kernel.org>; James E.J. Bottomley <jejb@linux.vnet.ibm.com>; linux-scsi <linux-scsi@vger.kernel.org>; Takashi Iwai <tiwai@suse.com>; Sebastian Ott <sebott@linux.vnet.ibm.com>; James Smart <james.smart@broadcom.com>; Cezary Jackiewicz <cezary.jackiewicz@gmail.com>; linux-serial@vger.kernel.org; Jiri Slaby <jslaby@suse.com>; Darren Hart <dvhart@infradead.org>; Zhang Rui <rui.zhang@intel.com>; Dick Kennedy <dick.kennedy@broadcom.com>; Mathias Nyman <mathias.nyman@intel.com>; Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>; Peter Oberparleiter <oberpar@linux.vnet.ibm.com>; intel-gfx@lists.freedesktop.org; Jani Nikula <jani.nikula@linux.intel.com>; Eduardo Valentin <edubezval@gmail.com>; Mark Brown <broonie@kernel.org>; Rodrigo Vivi <rodrigo.vivi@intel.com>; Platform Driver <platform-driver-x86@vger.kernel.org>; Felipe Balbi <balbi@kernel.org>; Martin K. Petersen <martin.petersen@oracle.com>; Greg Kroah-Hartman <gregkh@linuxfoundation.org>; linux-pm@vger.kernel.org; USB <linux-usb@vger.kernel.org>; Liam Girdwood <lgirdwood@gmail.com>; linux-kernel@vger.kernel.org; Luis R. Rodriguez <mcgrof@kernel.org>; Andy Shevchenko <andy@infradead.org>; Martin Schwidefsky <schwidefsky@de.ibm.com>; Jarkko Nikula <jarkko.nikula@bitmer.com>
Subject: Re: [alsa-devel] [-next PATCH 2/4] treewide: Use DEVICE_ATTR_RW

On Tue, Dec 19, 2017 at 8:15 PM, Joe Perches <joe@perches.com> wrote:
> Convert DEVICE_ATTR uses to DEVICE_ATTR_RW where possible.

>

> Done with perl script:

>

> $ git grep -w --name-only DEVICE_ATTR | \

>   xargs perl -i -e 'local $/; while (<>) { s/\bDEVICE_ATTR\s*\(\s*(\w+)\s*,\s*\(?(\s*S_IRUGO\s*\|\s*S_IWUSR|\s*S_IWUSR\s*\|\s*S_IRUGO\s*|\s*0644\s*)\)?\s*,\s*\1_show\s*,\s*\1_store\s*\)/DEVICE_ATTR_RW(\1)/g; print;}'


>  drivers/platform/x86/compal-laptop.c | 18 +++++----------


> --- a/drivers/platform/x86/compal-laptop.c

> +++ b/drivers/platform/x86/compal-laptop.c

> @@ -679,18 +679,12 @@ static int bat_writeable_property(struct 

> power_supply *psy,

>  /* ============== */

>  /* Driver Globals */

>  /* ============== */

> -static DEVICE_ATTR(wake_up_pme,

> -               0644, wake_up_pme_show,         wake_up_pme_store);

> -static DEVICE_ATTR(wake_up_modem,

> -               0644, wake_up_modem_show,       wake_up_modem_store);

> -static DEVICE_ATTR(wake_up_lan,

> -               0644, wake_up_lan_show, wake_up_lan_store);

> -static DEVICE_ATTR(wake_up_wlan,

> -               0644, wake_up_wlan_show,        wake_up_wlan_store);

> -static DEVICE_ATTR(wake_up_key,

> -               0644, wake_up_key_show, wake_up_key_store);

> -static DEVICE_ATTR(wake_up_mouse,

> -               0644, wake_up_mouse_show,       wake_up_mouse_store);

> +static DEVICE_ATTR_RW(wake_up_pme);

> +static DEVICE_ATTR_RW(wake_up_modem); static 

> +DEVICE_ATTR_RW(wake_up_lan); static DEVICE_ATTR_RW(wake_up_wlan); 

> +static DEVICE_ATTR_RW(wake_up_key); static 

> +DEVICE_ATTR_RW(wake_up_mouse);


Acked-by: Andy Shevchenko <andy.shevchenko@gmail.com>


for PDx86 bits.

Have to say that while it doesn't change the attributes here, it might require still to be revisited by security people, if they wish.

--
With Best Regards,
Andy Shevchenko
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Jarkko Nikula Dec. 20, 2017, 8:34 a.m. UTC | #3
On Tue, Dec 19, 2017 at 10:15:07AM -0800, Joe Perches wrote:
> Convert DEVICE_ATTR uses to DEVICE_ATTR_RW where possible.
> 
...
  
> diff --git a/sound/soc/omap/mcbsp.c b/sound/soc/omap/mcbsp.c
> index 7a54e3083203..79d4dc785e5c 100644
> --- a/sound/soc/omap/mcbsp.c
> +++ b/sound/soc/omap/mcbsp.c
> @@ -854,7 +854,7 @@ static ssize_t dma_op_mode_store(struct device *dev,
>  	return size;
>  }
>  
> -static DEVICE_ATTR(dma_op_mode, 0644, dma_op_mode_show, dma_op_mode_store);
> +static DEVICE_ATTR_RW(dma_op_mode);
>  
While I can ack this part here if it helps generic cleanup effort I
don't understart would it improve code readability in general? Mode 644
is clear and don't need any grepping but for DEVICE_ATTR_RW() I had to go
through all of these files in order to see what does it mean:

DEVICE_ATTR_RW: include/linux/device.h
__ATTR_RW: include/linux/sysfs.h
S_IWUSR: include/uapi/linux/stat.h
S_IRUGO: include/linux/stat.h

Jarkko Nikula <jarkko.nikula@bitmer.com>
Joe Perches Dec. 20, 2017, 9:24 a.m. UTC | #4
On Wed, 2017-12-20 at 10:34 +0200, Jarkko Nikula wrote:
> On Tue, Dec 19, 2017 at 10:15:07AM -0800, Joe Perches wrote:
> > Convert DEVICE_ATTR uses to DEVICE_ATTR_RW where possible.
[] 
> > diff --git a/sound/soc/omap/mcbsp.c b/sound/soc/omap/mcbsp.c
[]
> > @@ -854,7 +854,7 @@ static ssize_t dma_op_mode_store(struct device *dev,
> >  	return size;
> >  }
> >  
> > -static DEVICE_ATTR(dma_op_mode, 0644, dma_op_mode_show, dma_op_mode_store);
> > +static DEVICE_ATTR_RW(dma_op_mode);
> >  
> 
> While I can ack this part here if it helps generic cleanup effort I
> don't understart would it improve code readability in general? Mode 644
> is clear and don't need any grepping but for DEVICE_ATTR_RW() I had to go
> through all of these files in order to see what does it mean:

Are you suggesting that device.h (as that is where
DEVICE_ATTR and the other DEVICE_ATTR_<FOO> variants
are #defined) should have better comments for the
_<FOO> variants?

> DEVICE_ATTR_RW: include/linux/device.h
> __ATTR_RW: include/linux/sysfs.h
> S_IWUSR: include/uapi/linux/stat.h
> S_IRUGO: include/linux/stat.h

btw: patch 1/4 of the series does remove the uses of
S_<PERMS> from these macros in sysfs.h and converts
them to simple octal instead.
Greg Kroah-Hartman Dec. 20, 2017, 9:32 a.m. UTC | #5
On Wed, Dec 20, 2017 at 01:24:44AM -0800, Joe Perches wrote:
> On Wed, 2017-12-20 at 10:34 +0200, Jarkko Nikula wrote:
> > On Tue, Dec 19, 2017 at 10:15:07AM -0800, Joe Perches wrote:
> > > Convert DEVICE_ATTR uses to DEVICE_ATTR_RW where possible.
> [] 
> > > diff --git a/sound/soc/omap/mcbsp.c b/sound/soc/omap/mcbsp.c
> []
> > > @@ -854,7 +854,7 @@ static ssize_t dma_op_mode_store(struct device *dev,
> > >  	return size;
> > >  }
> > >  
> > > -static DEVICE_ATTR(dma_op_mode, 0644, dma_op_mode_show, dma_op_mode_store);
> > > +static DEVICE_ATTR_RW(dma_op_mode);
> > >  
> > 
> > While I can ack this part here if it helps generic cleanup effort I
> > don't understart would it improve code readability in general? Mode 644
> > is clear and don't need any grepping but for DEVICE_ATTR_RW() I had to go
> > through all of these files in order to see what does it mean:

Yeah, 644 is "clear", but _RW() is even more clear.  Ideally I want to
get rid of all of the "non-standard" users that set random modes of
sysfs files, as we get it wrong too many times.  Using the "defaults" is
much better.

> Are you suggesting that device.h (as that is where
> DEVICE_ATTR and the other DEVICE_ATTR_<FOO> variants
> are #defined) should have better comments for the
> _<FOO> variants?
> 
> > DEVICE_ATTR_RW: include/linux/device.h
> > __ATTR_RW: include/linux/sysfs.h
> > S_IWUSR: include/uapi/linux/stat.h
> > S_IRUGO: include/linux/stat.h
> 
> btw: patch 1/4 of the series does remove the uses of
> S_<PERMS> from these macros in sysfs.h and converts
> them to simple octal instead.

Why you didn't send that patch to the sysfs maintainer is a bit odd...  :)

I should be taking this whole series through my tree.  Joe, thanks for
doing this in an automated way, I've been wanting to see this done for a
long time.

thanks,

greg k-h
Joe Perches Dec. 20, 2017, 9:54 a.m. UTC | #6
On Wed, 2017-12-20 at 10:32 +0100, Greg Kroah-Hartman wrote:
> On Wed, Dec 20, 2017 at 01:24:44AM -0800, Joe Perches wrote:
> > On Wed, 2017-12-20 at 10:34 +0200, Jarkko Nikula wrote:
> > > On Tue, Dec 19, 2017 at 10:15:07AM -0800, Joe Perches wrote:
> > > > Convert DEVICE_ATTR uses to DEVICE_ATTR_RW where possible.
> > 
> > [] 
> > > > diff --git a/sound/soc/omap/mcbsp.c b/sound/soc/omap/mcbsp.c
> > 
> > []
> > > > @@ -854,7 +854,7 @@ static ssize_t dma_op_mode_store(struct device *dev,
> > > >  	return size;
> > > >  }
> > > >  
> > > > -static DEVICE_ATTR(dma_op_mode, 0644, dma_op_mode_show, dma_op_mode_store);
> > > > +static DEVICE_ATTR_RW(dma_op_mode);
> > > >  
> > > 
> > > While I can ack this part here if it helps generic cleanup effort I
> > > don't understart would it improve code readability in general? Mode 644
> > > is clear and don't need any grepping but for DEVICE_ATTR_RW() I had to go
> > > through all of these files in order to see what does it mean:
> 
> Yeah, 644 is "clear", but _RW() is even more clear.  Ideally I want to
> get rid of all of the "non-standard" users that set random modes of
> sysfs files, as we get it wrong too many times.  Using the "defaults" is
> much better.
> 
> > Are you suggesting that device.h (as that is where
> > DEVICE_ATTR and the other DEVICE_ATTR_<FOO> variants
> > are #defined) should have better comments for the
> > _<FOO> variants?
> > 
> > > DEVICE_ATTR_RW: include/linux/device.h
> > > __ATTR_RW: include/linux/sysfs.h
> > > S_IWUSR: include/uapi/linux/stat.h
> > > S_IRUGO: include/linux/stat.h
> > 
> > btw: patch 1/4 of the series does remove the uses of
> > S_<PERMS> from these macros in sysfs.h and converts
> > them to simple octal instead.
> 
> Why you didn't send that patch to the sysfs maintainer is a bit odd...  :)

So here's an opportunity for you:

The sysfs maintainer hasn't added include/linux/sysfs.h to
the list of maintained files...

DRIVER CORE, KOBJECTS, DEBUGFS AND SYSFS
M:	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
T:	git git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core.git
S:	Supported
F:	Documentation/kobject.txt
F:	drivers/base/
F:	fs/debugfs/
F:	fs/sysfs/
F:	include/linux/debugfs.h
F:	include/linux/kobj*
F:	lib/kobj*

> I should be taking this whole series through my tree.  Joe, thanks for
> doing this in an automated way, I've been wanting to see this done for a
> long time.

btw: there are many uses of a reversed declaration style of DEVICE_ATTR

Here's another thing that could be done for more DEVICE_ATTR_<FOO> uses.

===

Some DEVICE_ATTR definitions use a reversed static function form from
the typical.  Convert them to use the more common macro form so it is
easier to grep for the style.

i.e.:
        static ssize_t show_<foo>(...)
and
        static ssize_t store_<foo>(...)

where the static function names in the DEVICE_ATTR_RW macro are reversed

        static ssize_t <foo>_show(...)
and
        static ssize_t <foo>_store(...)

Done with perl script

$ cat dev_attr_rw_backwards.perl
local $/;
while (<>) {
    my $file = $_;
    while ($file =~ m/\bDEVICE_ATTR\s*\(\s*(\w+)\s*,/g) {
        my $var = $1;
        if ($file =~ s/\bDEVICE_ATTR\s*\(\s*${var}\s*,\s*\(?(\s*S_IRUGO\s*\|\s*S
            $file =~ s/\bshow_${var}\b/${var}_show/g;
            $file =~ s/\bstore_${var}\b/${var}_store/g;
        }
    }
    print $file;
}

$ git grep --name-only -w DEVICE_ATTR | \
  xargs perl -i dev_attr_rw_backwards.perl
Greg Kroah-Hartman Dec. 20, 2017, 9:59 a.m. UTC | #7
On Wed, Dec 20, 2017 at 01:54:41AM -0800, Joe Perches wrote:
> On Wed, 2017-12-20 at 10:32 +0100, Greg Kroah-Hartman wrote:
> > On Wed, Dec 20, 2017 at 01:24:44AM -0800, Joe Perches wrote:
> > > On Wed, 2017-12-20 at 10:34 +0200, Jarkko Nikula wrote:
> > > > On Tue, Dec 19, 2017 at 10:15:07AM -0800, Joe Perches wrote:
> > > > > Convert DEVICE_ATTR uses to DEVICE_ATTR_RW where possible.
> > > 
> > > [] 
> > > > > diff --git a/sound/soc/omap/mcbsp.c b/sound/soc/omap/mcbsp.c
> > > 
> > > []
> > > > > @@ -854,7 +854,7 @@ static ssize_t dma_op_mode_store(struct device *dev,
> > > > >  	return size;
> > > > >  }
> > > > >  
> > > > > -static DEVICE_ATTR(dma_op_mode, 0644, dma_op_mode_show, dma_op_mode_store);
> > > > > +static DEVICE_ATTR_RW(dma_op_mode);
> > > > >  
> > > > 
> > > > While I can ack this part here if it helps generic cleanup effort I
> > > > don't understart would it improve code readability in general? Mode 644
> > > > is clear and don't need any grepping but for DEVICE_ATTR_RW() I had to go
> > > > through all of these files in order to see what does it mean:
> > 
> > Yeah, 644 is "clear", but _RW() is even more clear.  Ideally I want to
> > get rid of all of the "non-standard" users that set random modes of
> > sysfs files, as we get it wrong too many times.  Using the "defaults" is
> > much better.
> > 
> > > Are you suggesting that device.h (as that is where
> > > DEVICE_ATTR and the other DEVICE_ATTR_<FOO> variants
> > > are #defined) should have better comments for the
> > > _<FOO> variants?
> > > 
> > > > DEVICE_ATTR_RW: include/linux/device.h
> > > > __ATTR_RW: include/linux/sysfs.h
> > > > S_IWUSR: include/uapi/linux/stat.h
> > > > S_IRUGO: include/linux/stat.h
> > > 
> > > btw: patch 1/4 of the series does remove the uses of
> > > S_<PERMS> from these macros in sysfs.h and converts
> > > them to simple octal instead.
> > 
> > Why you didn't send that patch to the sysfs maintainer is a bit odd...  :)
> 
> So here's an opportunity for you:
> 
> The sysfs maintainer hasn't added include/linux/sysfs.h to
> the list of maintained files...
> 
> DRIVER CORE, KOBJECTS, DEBUGFS AND SYSFS
> M:	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> T:	git git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core.git
> S:	Supported
> F:	Documentation/kobject.txt
> F:	drivers/base/
> F:	fs/debugfs/
> F:	fs/sysfs/
> F:	include/linux/debugfs.h
> F:	include/linux/kobj*
> F:	lib/kobj*

Heh, good point, but using get_maintainer.pl does put me at the top of
the list that you should be cc:ing:

$ ./scripts/get_maintainer.pl --file include/linux/sysfs.h
Greg Kroah-Hartman <gregkh@linuxfoundation.org> (commit_signer:3/3=100%,authored:2/3=67%,added_lines:7/8=88%)
Kate Stewart <kstewart@linuxfoundation.org> (commit_signer:1/3=33%)
Thomas Gleixner <tglx@linutronix.de> (commit_signer:1/3=33%)
Philippe Ombredanne <pombredanne@nexb.com> (commit_signer:1/3=33%)
Nick Desaulniers <nick.desaulniers@gmail.com> (commit_signer:1/3=33%,authored:1/3=33%,added_lines:1/8=12%,removed_lines:1/1=100%)
linux-kernel@vger.kernel.org (open list)

Anyway, I'll go add sysfs.h to the list, thanks for pointing it out.

> > I should be taking this whole series through my tree.  Joe, thanks for
> > doing this in an automated way, I've been wanting to see this done for a
> > long time.
> 
> btw: there are many uses of a reversed declaration style of DEVICE_ATTR
> 
> Here's another thing that could be done for more DEVICE_ATTR_<FOO> uses.
> 
> ===
> 
> Some DEVICE_ATTR definitions use a reversed static function form from
> the typical.  Convert them to use the more common macro form so it is
> easier to grep for the style.
> 
> i.e.:
>         static ssize_t show_<foo>(...)
> and
>         static ssize_t store_<foo>(...)
> 
> where the static function names in the DEVICE_ATTR_RW macro are reversed
> 
>         static ssize_t <foo>_show(...)
> and
>         static ssize_t <foo>_store(...)
> 
> Done with perl script
> 
> $ cat dev_attr_rw_backwards.perl
> local $/;
> while (<>) {
>     my $file = $_;
>     while ($file =~ m/\bDEVICE_ATTR\s*\(\s*(\w+)\s*,/g) {
>         my $var = $1;
>         if ($file =~ s/\bDEVICE_ATTR\s*\(\s*${var}\s*,\s*\(?(\s*S_IRUGO\s*\|\s*S
>             $file =~ s/\bshow_${var}\b/${var}_show/g;
>             $file =~ s/\bstore_${var}\b/${var}_store/g;
>         }
>     }
>     print $file;
> }
> 
> $ git grep --name-only -w DEVICE_ATTR | \
>   xargs perl -i dev_attr_rw_backwards.perl
> 

Ah, nice, I love perl :)

greg k-h
Jarkko Nikula Dec. 20, 2017, 10:54 a.m. UTC | #8
On Wed, Dec 20, 2017 at 10:32:11AM +0100, Greg Kroah-Hartman wrote:
> On Wed, Dec 20, 2017 at 01:24:44AM -0800, Joe Perches wrote:
> > On Wed, 2017-12-20 at 10:34 +0200, Jarkko Nikula wrote:
> > > On Tue, Dec 19, 2017 at 10:15:07AM -0800, Joe Perches wrote:
> > > > Convert DEVICE_ATTR uses to DEVICE_ATTR_RW where possible.
> > [] 
> > > > diff --git a/sound/soc/omap/mcbsp.c b/sound/soc/omap/mcbsp.c
> > []
> > > > @@ -854,7 +854,7 @@ static ssize_t dma_op_mode_store(struct device *dev,
> > > >  	return size;
> > > >  }
> > > >  
> > > > -static DEVICE_ATTR(dma_op_mode, 0644, dma_op_mode_show, dma_op_mode_store);
> > > > +static DEVICE_ATTR_RW(dma_op_mode);
> > > >  
> > > 
> > > While I can ack this part here if it helps generic cleanup effort I
> > > don't understart would it improve code readability in general? Mode 644
> > > is clear and don't need any grepping but for DEVICE_ATTR_RW() I had to go
> > > through all of these files in order to see what does it mean:
> 
> Yeah, 644 is "clear", but _RW() is even more clear.  Ideally I want to
> get rid of all of the "non-standard" users that set random modes of
> sysfs files, as we get it wrong too many times.  Using the "defaults" is
> much better.
> 
Fair enough. For the sound/soc/omap/ (Acked-by was missing from my
previous reply):

Acked-by: Jarkko Nikula <jarkko.nikula@bitmer.com>
Joe Perches Dec. 20, 2017, 10:55 a.m. UTC | #9
On Wed, 2017-12-20 at 10:59 +0100, Greg Kroah-Hartman wrote:
> > > Why you didn't send that patch to the sysfs maintainer is a bit odd...  :)
> > 
> > So here's an opportunity for you:
> > 
> > The sysfs maintainer hasn't added include/linux/sysfs.h to
> > the list of maintained files...
> > 
> > DRIVER CORE, KOBJECTS, DEBUGFS AND SYSFS
> > M:	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > T:	git git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core.git
> > S:	Supported
> > F:	Documentation/kobject.txt
> > F:	drivers/base/
> > F:	fs/debugfs/
> > F:	fs/sysfs/
> > F:	include/linux/debugfs.h
> > F:	include/linux/kobj*
> > F:	lib/kobj*
> 
> Heh, good point, but using get_maintainer.pl does put me at the top of
> the list that you should be cc:ing:
> 
> $ ./scripts/get_maintainer.pl --file include/linux/sysfs.h
> Greg Kroah-Hartman <gregkh@linuxfoundation.org> (commit_signer:3/3=100%,authored:2/3=67%,added_lines:7/8=88%)
> Kate Stewart <kstewart@linuxfoundation.org> (commit_signer:1/3=33%)
> Thomas Gleixner <tglx@linutronix.de> (commit_signer:1/3=33%)
> Philippe Ombredanne <pombredanne@nexb.com> (commit_signer:1/3=33%)
> Nick Desaulniers <nick.desaulniers@gmail.com> (commit_signer:1/3=33%,authored:1/3=33%,added_lines:1/8=12%,removed_lines:1/1=100%)
> linux-kernel@vger.kernel.org (open list)

The script I use to send patches adds --nogit --nogit-fallback
to copy only listed maintainers because people that send cleanup
patches don't generally like to get random patches.

> > btw: there are many uses of a reversed declaration style of DEVICE_ATTR
> > 
> > Here's another thing that could be done for more DEVICE_ATTR_<FOO> uses.
> > 
> > ===
> > 
> > Some DEVICE_ATTR definitions use a reversed static function form from
> > the typical.  Convert them to use the more common macro form so it is
> > easier to grep for the style.
[]
> > $ git grep --name-only -w DEVICE_ATTR | \
> >   xargs perl -i dev_attr_rw_backwards.perl
> Ah, nice, I love perl :

That was a bad copy/paste of the script.

The actual script for RW is:

$ cat dev_attr_rw_backwards.perl
local $/;
while (<>) {
    my $file = $_;
    while ($file =~ m/\bDEVICE_ATTR\s*\(\s*(\w+)\s*,/g) {
	my $var = $1;
	if ($file =~ s/\bDEVICE_ATTR\s*\(\s*${var}\s*,\s*\(?(\s*S_IRUGO\s*\|\s*S_IWUSR|\s*S_IWUSR\s*\|\s*S_IRUGO\s*|\s*0644\s*)\)?\s*,\s*show_${var}\s*,\s*store_${var}\s*\)/DEVICE_ATTR_RW(${var})/g) {
	    $file =~ s/\bshow_${var}\b/${var}_show/g;
	    $file =~ s/\bstore_${var}\b/${var}_store/g;
	}
    }
    print $file;
}

There are 3 different perl scripts for rw, ro, and wo.
and these scripts, because of function renaming and
possible reuse of the original function names by other
string concatenated macros, create some bad conversions
so they need some manual cleanups too.

Perhaps coccinelle could do a better job of it, but
likely string concatenation macro uses are going to
be hard to deal with in any case.
Julia Lawall Dec. 20, 2017, 1:26 p.m. UTC | #10
On Wed, 20 Dec 2017, Joe Perches wrote:

> On Wed, 2017-12-20 at 10:59 +0100, Greg Kroah-Hartman wrote:
> > > > Why you didn't send that patch to the sysfs maintainer is a bit odd...  :)
> > >
> > > So here's an opportunity for you:
> > >
> > > The sysfs maintainer hasn't added include/linux/sysfs.h to
> > > the list of maintained files...
> > >
> > > DRIVER CORE, KOBJECTS, DEBUGFS AND SYSFS
> > > M:	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > > T:	git git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core.git
> > > S:	Supported
> > > F:	Documentation/kobject.txt
> > > F:	drivers/base/
> > > F:	fs/debugfs/
> > > F:	fs/sysfs/
> > > F:	include/linux/debugfs.h
> > > F:	include/linux/kobj*
> > > F:	lib/kobj*
> >
> > Heh, good point, but using get_maintainer.pl does put me at the top of
> > the list that you should be cc:ing:
> >
> > $ ./scripts/get_maintainer.pl --file include/linux/sysfs.h
> > Greg Kroah-Hartman <gregkh@linuxfoundation.org> (commit_signer:3/3=100%,authored:2/3=67%,added_lines:7/8=88%)
> > Kate Stewart <kstewart@linuxfoundation.org> (commit_signer:1/3=33%)
> > Thomas Gleixner <tglx@linutronix.de> (commit_signer:1/3=33%)
> > Philippe Ombredanne <pombredanne@nexb.com> (commit_signer:1/3=33%)
> > Nick Desaulniers <nick.desaulniers@gmail.com> (commit_signer:1/3=33%,authored:1/3=33%,added_lines:1/8=12%,removed_lines:1/1=100%)
> > linux-kernel@vger.kernel.org (open list)
>
> The script I use to send patches adds --nogit --nogit-fallback
> to copy only listed maintainers because people that send cleanup
> patches don't generally like to get random patches.
>
> > > btw: there are many uses of a reversed declaration style of DEVICE_ATTR
> > >
> > > Here's another thing that could be done for more DEVICE_ATTR_<FOO> uses.
> > >
> > > ===
> > >
> > > Some DEVICE_ATTR definitions use a reversed static function form from
> > > the typical.  Convert them to use the more common macro form so it is
> > > easier to grep for the style.
> []
> > > $ git grep --name-only -w DEVICE_ATTR | \
> > >   xargs perl -i dev_attr_rw_backwards.perl
> > Ah, nice, I love perl :
>
> That was a bad copy/paste of the script.
>
> The actual script for RW is:
>
> $ cat dev_attr_rw_backwards.perl
> local $/;
> while (<>) {
>     my $file = $_;
>     while ($file =~ m/\bDEVICE_ATTR\s*\(\s*(\w+)\s*,/g) {
> 	my $var = $1;
> 	if ($file =~ s/\bDEVICE_ATTR\s*\(\s*${var}\s*,\s*\(?(\s*S_IRUGO\s*\|\s*S_IWUSR|\s*S_IWUSR\s*\|\s*S_IRUGO\s*|\s*0644\s*)\)?\s*,\s*show_${var}\s*,\s*store_${var}\s*\)/DEVICE_ATTR_RW(${var})/g) {
> 	    $file =~ s/\bshow_${var}\b/${var}_show/g;
> 	    $file =~ s/\bstore_${var}\b/${var}_store/g;
> 	}
>     }
>     print $file;
> }
>
> There are 3 different perl scripts for rw, ro, and wo.
> and these scripts, because of function renaming and
> possible reuse of the original function names by other
> string concatenated macros, create some bad conversions
> so they need some manual cleanups too.
>
> Perhaps coccinelle could do a better job of it, but
> likely string concatenation macro uses are going to
> be hard to deal with in any case.

I made a rule for this at one point, but there are cases where the
functions have the wrong names, and then these functions may be used
elsewhere.

julia
Zhang Rui Dec. 21, 2017, 12:47 a.m. UTC | #11
On Tue, 2017-12-19 at 10:15 -0800, Joe Perches wrote:
> Convert DEVICE_ATTR uses to DEVICE_ATTR_RW where possible.
> 
> Done with perl script:
> 
> $ git grep -w --name-only DEVICE_ATTR | \
>   xargs perl -i -e 'local $/; while (<>) {
> s/\bDEVICE_ATTR\s*\(\s*(\w+)\s*,\s*\(?(\s*S_IRUGO\s*\|\s*S_IWUSR|\s*S
> _IWUSR\s*\|\s*S_IRUGO\s*|\s*0644\s*)\)?\s*,\s*\1_show\s*,\s*\1_store\
> s*\)/DEVICE_ATTR_RW(\1)/g; print;}'
> 
> Signed-off-by: Joe Perches <joe@perches.com>
> ---
>  arch/s390/kernel/topology.c          |  3 +--
>  arch/tile/kernel/sysfs.c             |  2 +-
>  drivers/gpu/drm/i915/i915_sysfs.c    |  6 ++---
>  drivers/platform/x86/compal-laptop.c | 18 +++++----------
>  drivers/s390/cio/device.c            |  2 +-
>  drivers/scsi/lpfc/lpfc_attr.c        | 43 ++++++++++++------------
> ------------
>  drivers/thermal/thermal_sysfs.c      |  9 ++++----

For the thermal part,
ACK-by: Zhang Rui <rui.zhang@intel.com>

thanks,
rui

>  drivers/tty/serial/sh-sci.c          |  2 +-
>  drivers/usb/host/xhci-dbgcap.c       |  2 +-
>  drivers/usb/phy/phy-tahvo.c          |  2 +-
>  drivers/video/fbdev/auo_k190x.c      |  4 ++--
>  drivers/video/fbdev/w100fb.c         |  4 ++--
>  lib/test_firmware.c                  | 14 +++++-------
>  lib/test_kmod.c                      | 14 +++++-------
>  sound/soc/omap/mcbsp.c               |  4 ++--
>  15 files changed, 49 insertions(+), 80 deletions(-)
> 
> diff --git a/arch/s390/kernel/topology.c
> b/arch/s390/kernel/topology.c
> index 4d5b65e527b5..4b6e0397f66d 100644
> --- a/arch/s390/kernel/topology.c
> +++ b/arch/s390/kernel/topology.c
> @@ -404,8 +404,7 @@ static ssize_t dispatching_store(struct device
> *dev,
>  	put_online_cpus();
>  	return rc ? rc : count;
>  }
> -static DEVICE_ATTR(dispatching, 0644, dispatching_show,
> -			 dispatching_store);
> +static DEVICE_ATTR_RW(dispatching);
>  
>  static ssize_t cpu_polarization_show(struct device *dev,
>  				     struct device_attribute *attr,
> char *buf)
> diff --git a/arch/tile/kernel/sysfs.c b/arch/tile/kernel/sysfs.c
> index 825867c53853..af5024f0fb5a 100644
> --- a/arch/tile/kernel/sysfs.c
> +++ b/arch/tile/kernel/sysfs.c
> @@ -184,7 +184,7 @@ static ssize_t hv_stats_store(struct device *dev,
>  	return n < 0 ? n : count;
>  }
>  
> -static DEVICE_ATTR(hv_stats, 0644, hv_stats_show, hv_stats_store);
> +static DEVICE_ATTR_RW(hv_stats);
>  
>  static int hv_stats_device_add(struct device *dev, struct
> subsys_interface *sif)
>  {
> diff --git a/drivers/gpu/drm/i915/i915_sysfs.c
> b/drivers/gpu/drm/i915/i915_sysfs.c
> index c74a20b80182..1d0ab8ff5915 100644
> --- a/drivers/gpu/drm/i915/i915_sysfs.c
> +++ b/drivers/gpu/drm/i915/i915_sysfs.c
> @@ -447,9 +447,9 @@ static ssize_t gt_min_freq_mhz_store(struct
> device *kdev,
>  
>  static DEVICE_ATTR(gt_act_freq_mhz, S_IRUGO, gt_act_freq_mhz_show,
> NULL);
>  static DEVICE_ATTR(gt_cur_freq_mhz, S_IRUGO, gt_cur_freq_mhz_show,
> NULL);
> -static DEVICE_ATTR(gt_boost_freq_mhz, S_IRUGO | S_IWUSR,
> gt_boost_freq_mhz_show, gt_boost_freq_mhz_store);
> -static DEVICE_ATTR(gt_max_freq_mhz, S_IRUGO | S_IWUSR,
> gt_max_freq_mhz_show, gt_max_freq_mhz_store);
> -static DEVICE_ATTR(gt_min_freq_mhz, S_IRUGO | S_IWUSR,
> gt_min_freq_mhz_show, gt_min_freq_mhz_store);
> +static DEVICE_ATTR_RW(gt_boost_freq_mhz);
> +static DEVICE_ATTR_RW(gt_max_freq_mhz);
> +static DEVICE_ATTR_RW(gt_min_freq_mhz);
>  
>  static DEVICE_ATTR(vlv_rpe_freq_mhz, S_IRUGO, vlv_rpe_freq_mhz_show,
> NULL);
>  
> diff --git a/drivers/platform/x86/compal-laptop.c
> b/drivers/platform/x86/compal-laptop.c
> index 6bcb750e1865..4f9bc72f0584 100644
> --- a/drivers/platform/x86/compal-laptop.c
> +++ b/drivers/platform/x86/compal-laptop.c
> @@ -679,18 +679,12 @@ static int bat_writeable_property(struct
> power_supply *psy,
>  /* ============== */
>  /* Driver Globals */
>  /* ============== */
> -static DEVICE_ATTR(wake_up_pme,
> -		0644, wake_up_pme_show,		wake_up_pme_s
> tore);
> -static DEVICE_ATTR(wake_up_modem,
> -		0644, wake_up_modem_show,	wake_up_modem_store
> );
> -static DEVICE_ATTR(wake_up_lan,
> -		0644, wake_up_lan_show,	wake_up_lan_store);
> -static DEVICE_ATTR(wake_up_wlan,
> -		0644, wake_up_wlan_show,	wake_up_wlan_store);
> -static DEVICE_ATTR(wake_up_key,
> -		0644, wake_up_key_show,	wake_up_key_store);
> -static DEVICE_ATTR(wake_up_mouse,
> -		0644, wake_up_mouse_show,	wake_up_mouse_store
> );
> +static DEVICE_ATTR_RW(wake_up_pme);
> +static DEVICE_ATTR_RW(wake_up_modem);
> +static DEVICE_ATTR_RW(wake_up_lan);
> +static DEVICE_ATTR_RW(wake_up_wlan);
> +static DEVICE_ATTR_RW(wake_up_key);
> +static DEVICE_ATTR_RW(wake_up_mouse);
>  
>  static DEVICE_ATTR(fan1_input,  S_IRUGO, fan_show,          NULL);
>  static DEVICE_ATTR(temp1_input, S_IRUGO, temp_cpu,          NULL);
> diff --git a/drivers/s390/cio/device.c b/drivers/s390/cio/device.c
> index 75a245f38e2e..6eefb67b31f3 100644
> --- a/drivers/s390/cio/device.c
> +++ b/drivers/s390/cio/device.c
> @@ -600,7 +600,7 @@ static ssize_t vpm_show(struct device *dev,
> struct device_attribute *attr,
>  static DEVICE_ATTR(devtype, 0444, devtype_show, NULL);
>  static DEVICE_ATTR(cutype, 0444, cutype_show, NULL);
>  static DEVICE_ATTR(modalias, 0444, modalias_show, NULL);
> -static DEVICE_ATTR(online, 0644, online_show, online_store);
> +static DEVICE_ATTR_RW(online);
>  static DEVICE_ATTR(availability, 0444, available_show, NULL);
>  static DEVICE_ATTR(logging, 0200, NULL, initiate_logging);
>  static DEVICE_ATTR(vpm, 0444, vpm_show, NULL);
> diff --git a/drivers/scsi/lpfc/lpfc_attr.c
> b/drivers/scsi/lpfc/lpfc_attr.c
> index 797bb42a6306..95f7ba3c3f1a 100644
> --- a/drivers/scsi/lpfc/lpfc_attr.c
> +++ b/drivers/scsi/lpfc/lpfc_attr.c
> @@ -2519,8 +2519,7 @@ lpfc_soft_wwpn_store(struct device *dev, struct
> device_attribute *attr,
>  				"reinit adapter - %d\n", stat2);
>  	return (stat1 || stat2) ? -EIO : count;
>  }
> -static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,
> -		   lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
> +static DEVICE_ATTR_RW(lpfc_soft_wwpn);
>  
>  /**
>   * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the
> adapter
> @@ -2583,8 +2582,7 @@ lpfc_soft_wwnn_store(struct device *dev, struct
> device_attribute *attr,
>  
>  	return count;
>  }
> -static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,
> -		   lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
> +static DEVICE_ATTR_RW(lpfc_soft_wwnn);
>  
>  /**
>   * lpfc_oas_tgt_show - Return wwpn of target whose luns maybe
> enabled for
> @@ -3102,8 +3100,7 @@ MODULE_PARM_DESC(lpfc_poll, "FCP ring polling
> mode control:"
>  		 " 1 - poll with interrupts enabled"
>  		 " 3 - poll and disable FCP ring interrupts");
>  
> -static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
> -		   lpfc_poll_show, lpfc_poll_store);
> +static DEVICE_ATTR_RW(lpfc_poll);
>  
>  int lpfc_no_hba_reset_cnt;
>  unsigned long lpfc_no_hba_reset[MAX_HBAS_NO_RESET] = {
> @@ -3336,8 +3333,7 @@ lpfc_nodev_tmo_set(struct lpfc_vport *vport,
> int val)
>  
>  lpfc_vport_param_store(nodev_tmo)
>  
> -static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
> -		   lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
> +static DEVICE_ATTR_RW(lpfc_nodev_tmo);
>  
>  /*
>  # lpfc_devloss_tmo: If set, it will hold all I/O errors on devices
> that
> @@ -3386,8 +3382,7 @@ lpfc_devloss_tmo_set(struct lpfc_vport *vport,
> int val)
>  }
>  
>  lpfc_vport_param_store(devloss_tmo)
> -static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
> -		   lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
> +static DEVICE_ATTR_RW(lpfc_devloss_tmo);
>  
>  /*
>   * lpfc_suppress_rsp: Enable suppress rsp feature is firmware
> supports it
> @@ -3580,8 +3575,7 @@ lpfc_restrict_login_set(struct lpfc_vport
> *vport, int val)
>  	return 0;
>  }
>  lpfc_vport_param_store(restrict_login);
> -static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
> -		   lpfc_restrict_login_show,
> lpfc_restrict_login_store);
> +static DEVICE_ATTR_RW(lpfc_restrict_login);
>  
>  /*
>  # Some disk devices have a "select ID" or "select Target"
> capability.
> @@ -3695,8 +3689,7 @@ lpfc_topology_store(struct device *dev, struct
> device_attribute *attr,
>  }
>  
>  lpfc_param_show(topology)
> -static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
> -		lpfc_topology_show, lpfc_topology_store);
> +static DEVICE_ATTR_RW(lpfc_topology);
>  
>  /**
>   * lpfc_static_vport_show: Read callback function for
> @@ -3954,8 +3947,7 @@ lpfc_stat_data_ctrl_show(struct device *dev,
> struct device_attribute *attr,
>  /*
>   * Sysfs attribute to control the statistical data collection.
>   */
> -static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
> -		   lpfc_stat_data_ctrl_show,
> lpfc_stat_data_ctrl_store);
> +static DEVICE_ATTR_RW(lpfc_stat_data_ctrl);
>  
>  /*
>   * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
> @@ -4194,8 +4186,7 @@ lpfc_link_speed_init(struct lpfc_hba *phba, int
> val)
>  	return -EINVAL;
>  }
>  
> -static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
> -		   lpfc_link_speed_show, lpfc_link_speed_store);
> +static DEVICE_ATTR_RW(lpfc_link_speed);
>  
>  /*
>  # lpfc_aer_support: Support PCIe device Advanced Error Reporting
> (AER)
> @@ -4288,8 +4279,7 @@ lpfc_aer_support_store(struct device *dev,
> struct device_attribute *attr,
>  	return rc;
>  }
>  
> -static DEVICE_ATTR(lpfc_aer_support, S_IRUGO | S_IWUSR,
> -		   lpfc_aer_support_show, lpfc_aer_support_store);
> +static DEVICE_ATTR_RW(lpfc_aer_support);
>  
>  /**
>   * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled
> device
> @@ -4436,8 +4426,7 @@ LPFC_ATTR(sriov_nr_virtfn,
> LPFC_DEF_VFN_PER_PFN, 0, LPFC_MAX_VFN_PER_PFN,
>  	"Enable PCIe device SR-IOV virtual fn");
>  
>  lpfc_param_show(sriov_nr_virtfn)
> -static DEVICE_ATTR(lpfc_sriov_nr_virtfn, S_IRUGO | S_IWUSR,
> -		   lpfc_sriov_nr_virtfn_show,
> lpfc_sriov_nr_virtfn_store);
> +static DEVICE_ATTR_RW(lpfc_sriov_nr_virtfn);
>  
>  /**
>   * lpfc_request_firmware_store - Request for Linux generic firmware
> upgrade
> @@ -4611,8 +4600,7 @@ lpfc_fcp_imax_init(struct lpfc_hba *phba, int
> val)
>  	return 0;
>  }
>  
> -static DEVICE_ATTR(lpfc_fcp_imax, S_IRUGO | S_IWUSR,
> -		   lpfc_fcp_imax_show, lpfc_fcp_imax_store);
> +static DEVICE_ATTR_RW(lpfc_fcp_imax);
>  
>  /*
>   * lpfc_auto_imax: Controls Auto-interrupt coalescing values
> support.
> @@ -4772,8 +4760,7 @@ lpfc_fcp_cpu_map_init(struct lpfc_hba *phba,
> int val)
>  	return 0;
>  }
>  
> -static DEVICE_ATTR(lpfc_fcp_cpu_map, S_IRUGO | S_IWUSR,
> -		   lpfc_fcp_cpu_map_show, lpfc_fcp_cpu_map_store);
> +static DEVICE_ATTR_RW(lpfc_fcp_cpu_map);
>  
>  /*
>  # lpfc_fcp_class:  Determines FC class to use for the FCP protocol.
> @@ -4859,9 +4846,7 @@ lpfc_max_scsicmpl_time_set(struct lpfc_vport
> *vport, int val)
>  	return 0;
>  }
>  lpfc_vport_param_store(max_scsicmpl_time);
> -static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
> -		   lpfc_max_scsicmpl_time_show,
> -		   lpfc_max_scsicmpl_time_store);
> +static DEVICE_ATTR_RW(lpfc_max_scsicmpl_time);
>  
>  /*
>  # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement.
> Value
> diff --git a/drivers/thermal/thermal_sysfs.c
> b/drivers/thermal/thermal_sysfs.c
> index fb80c96d8f73..c008af7fb480 100644
> --- a/drivers/thermal/thermal_sysfs.c
> +++ b/drivers/thermal/thermal_sysfs.c
> @@ -398,14 +398,13 @@ create_s32_tzp_attr(offset);
>   */
>  static DEVICE_ATTR(type, 0444, type_show, NULL);
>  static DEVICE_ATTR(temp, 0444, temp_show, NULL);
> -static DEVICE_ATTR(policy, S_IRUGO | S_IWUSR, policy_show,
> policy_store);
> +static DEVICE_ATTR_RW(policy);
>  static DEVICE_ATTR(available_policies, S_IRUGO,
> available_policies_show, NULL);
> -static DEVICE_ATTR(sustainable_power, S_IWUSR | S_IRUGO,
> sustainable_power_show,
> -		   sustainable_power_store);
> +static DEVICE_ATTR_RW(sustainable_power);
>  
>  /* These thermal zone device attributes are created based on
> conditions */
> -static DEVICE_ATTR(mode, 0644, mode_show, mode_store);
> -static DEVICE_ATTR(passive, S_IRUGO | S_IWUSR, passive_show,
> passive_store);
> +static DEVICE_ATTR_RW(mode);
> +static DEVICE_ATTR_RW(passive);
>  
>  /* These attributes are unconditionally added to a thermal zone */
>  static struct attribute *thermal_zone_dev_attrs[] = {
> diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-
> sci.c
> index d9f399c4e90c..7257c078e155 100644
> --- a/drivers/tty/serial/sh-sci.c
> +++ b/drivers/tty/serial/sh-sci.c
> @@ -1144,7 +1144,7 @@ static ssize_t rx_fifo_timeout_store(struct
> device *dev,
>  	return count;
>  }
>  
> -static DEVICE_ATTR(rx_fifo_timeout, 0644, rx_fifo_timeout_show,
> rx_fifo_timeout_store);
> +static DEVICE_ATTR_RW(rx_fifo_timeout);
>  
>  
>  #ifdef CONFIG_SERIAL_SH_SCI_DMA
> diff --git a/drivers/usb/host/xhci-dbgcap.c b/drivers/usb/host/xhci-
> dbgcap.c
> index 452df0f87d6e..a1ab8acf39ba 100644
> --- a/drivers/usb/host/xhci-dbgcap.c
> +++ b/drivers/usb/host/xhci-dbgcap.c
> @@ -920,7 +920,7 @@ static ssize_t dbc_store(struct device *dev,
>  	return count;
>  }
>  
> -static DEVICE_ATTR(dbc, 0644, dbc_show, dbc_store);
> +static DEVICE_ATTR_RW(dbc);
>  
>  int xhci_dbc_init(struct xhci_hcd *xhci)
>  {
> diff --git a/drivers/usb/phy/phy-tahvo.c b/drivers/usb/phy/phy-
> tahvo.c
> index b3ce42edb373..7f7c5c82420d 100644
> --- a/drivers/usb/phy/phy-tahvo.c
> +++ b/drivers/usb/phy/phy-tahvo.c
> @@ -310,7 +310,7 @@ static ssize_t otg_mode_store(struct device
> *device,
>  
>  	return r;
>  }
> -static DEVICE_ATTR(otg_mode, 0644, otg_mode_show, otg_mode_store);
> +static DEVICE_ATTR_RW(otg_mode);
>  
>  static struct attribute *tahvo_attributes[] = {
>  	&dev_attr_vbus.attr,
> diff --git a/drivers/video/fbdev/auo_k190x.c
> b/drivers/video/fbdev/auo_k190x.c
> index 0d06038324e0..1e383c547633 100644
> --- a/drivers/video/fbdev/auo_k190x.c
> +++ b/drivers/video/fbdev/auo_k190x.c
> @@ -708,8 +708,8 @@ static ssize_t temp_show(struct device *dev,
> struct device_attribute *attr,
>  	return sprintf(buf, "%d\n", temp);
>  }
>  
> -static DEVICE_ATTR(update_mode, 0644, update_mode_show,
> update_mode_store);
> -static DEVICE_ATTR(flash, 0644, flash_show, flash_store);
> +static DEVICE_ATTR_RW(update_mode);
> +static DEVICE_ATTR_RW(flash);
>  static DEVICE_ATTR(temp, 0644, temp_show, NULL);
>  
>  static struct attribute *auok190x_attributes[] = {
> diff --git a/drivers/video/fbdev/w100fb.c
> b/drivers/video/fbdev/w100fb.c
> index d570e19a2864..035ff6e02894 100644
> --- a/drivers/video/fbdev/w100fb.c
> +++ b/drivers/video/fbdev/w100fb.c
> @@ -110,7 +110,7 @@ static ssize_t flip_store(struct device *dev,
> struct device_attribute *attr, con
>  	return count;
>  }
>  
> -static DEVICE_ATTR(flip, 0644, flip_show, flip_store);
> +static DEVICE_ATTR_RW(flip);
>  
>  static ssize_t w100fb_reg_read(struct device *dev, struct
> device_attribute *attr, const char *buf, size_t count)
>  {
> @@ -166,7 +166,7 @@ static ssize_t fastpllclk_store(struct device
> *dev, struct device_attribute *att
>  	return count;
>  }
>  
> -static DEVICE_ATTR(fastpllclk, 0644, fastpllclk_show,
> fastpllclk_store);
> +static DEVICE_ATTR_RW(fastpllclk);
>  
>  /*
>   * Some touchscreens need hsync information from the video driver to
> diff --git a/lib/test_firmware.c b/lib/test_firmware.c
> index 64a4c76cba2b..964784dc1602 100644
> --- a/lib/test_firmware.c
> +++ b/lib/test_firmware.c
> @@ -359,7 +359,7 @@ static ssize_t config_name_show(struct device
> *dev,
>  {
>  	return config_test_show_str(buf, test_fw_config->name);
>  }
> -static DEVICE_ATTR(config_name, 0644, config_name_show,
> config_name_store);
> +static DEVICE_ATTR_RW(config_name);
>  
>  static ssize_t config_num_requests_store(struct device *dev,
>  					 struct device_attribute
> *attr,
> @@ -388,8 +388,7 @@ static ssize_t config_num_requests_show(struct
> device *dev,
>  {
>  	return test_dev_config_show_u8(buf, test_fw_config-
> >num_requests);
>  }
> -static DEVICE_ATTR(config_num_requests, 0644,
> config_num_requests_show,
> -		   config_num_requests_store);
> +static DEVICE_ATTR_RW(config_num_requests);
>  
>  static ssize_t config_sync_direct_store(struct device *dev,
>  					struct device_attribute
> *attr,
> @@ -411,8 +410,7 @@ static ssize_t config_sync_direct_show(struct
> device *dev,
>  {
>  	return test_dev_config_show_bool(buf, test_fw_config-
> >sync_direct);
>  }
> -static DEVICE_ATTR(config_sync_direct, 0644,
> config_sync_direct_show,
> -		   config_sync_direct_store);
> +static DEVICE_ATTR_RW(config_sync_direct);
>  
>  static ssize_t config_send_uevent_store(struct device *dev,
>  					struct device_attribute
> *attr,
> @@ -428,8 +426,7 @@ static ssize_t config_send_uevent_show(struct
> device *dev,
>  {
>  	return test_dev_config_show_bool(buf, test_fw_config-
> >send_uevent);
>  }
> -static DEVICE_ATTR(config_send_uevent, 0644,
> config_send_uevent_show,
> -		   config_send_uevent_store);
> +static DEVICE_ATTR_RW(config_send_uevent);
>  
>  static ssize_t config_read_fw_idx_store(struct device *dev,
>  					struct device_attribute
> *attr,
> @@ -445,8 +442,7 @@ static ssize_t config_read_fw_idx_show(struct
> device *dev,
>  {
>  	return test_dev_config_show_u8(buf, test_fw_config-
> >read_fw_idx);
>  }
> -static DEVICE_ATTR(config_read_fw_idx, 0644,
> config_read_fw_idx_show,
> -		   config_read_fw_idx_store);
> +static DEVICE_ATTR_RW(config_read_fw_idx);
>  
>  
>  static ssize_t trigger_request_store(struct device *dev,
> diff --git a/lib/test_kmod.c b/lib/test_kmod.c
> index 337f408b4de6..e372b97eee13 100644
> --- a/lib/test_kmod.c
> +++ b/lib/test_kmod.c
> @@ -694,8 +694,7 @@ static ssize_t config_test_driver_show(struct
> device *dev,
>  	return config_test_show_str(&test_dev->config_mutex, buf,
>  				    config->test_driver);
>  }
> -static DEVICE_ATTR(config_test_driver, 0644,
> config_test_driver_show,
> -		   config_test_driver_store);
> +static DEVICE_ATTR_RW(config_test_driver);
>  
>  static ssize_t config_test_fs_store(struct device *dev,
>  				    struct device_attribute *attr,
> @@ -726,8 +725,7 @@ static ssize_t config_test_fs_show(struct device
> *dev,
>  	return config_test_show_str(&test_dev->config_mutex, buf,
>  				    config->test_fs);
>  }
> -static DEVICE_ATTR(config_test_fs, 0644, config_test_fs_show,
> -		   config_test_fs_store);
> +static DEVICE_ATTR_RW(config_test_fs);
>  
>  static int trigger_config_run_type(struct kmod_test_device
> *test_dev,
>  				   enum kmod_test_case test_case,
> @@ -1012,8 +1010,7 @@ static ssize_t config_num_threads_show(struct
> device *dev,
>  
>  	return test_dev_config_show_int(test_dev, buf, config-
> >num_threads);
>  }
> -static DEVICE_ATTR(config_num_threads, 0644,
> config_num_threads_show,
> -		   config_num_threads_store);
> +static DEVICE_ATTR_RW(config_num_threads);
>  
>  static ssize_t config_test_case_store(struct device *dev,
>  				      struct device_attribute *attr,
> @@ -1037,8 +1034,7 @@ static ssize_t config_test_case_show(struct
> device *dev,
>  
>  	return test_dev_config_show_uint(test_dev, buf, config-
> >test_case);
>  }
> -static DEVICE_ATTR(config_test_case, 0644, config_test_case_show,
> -		   config_test_case_store);
> +static DEVICE_ATTR_RW(config_test_case);
>  
>  static ssize_t test_result_show(struct device *dev,
>  				struct device_attribute *attr,
> @@ -1049,7 +1045,7 @@ static ssize_t test_result_show(struct device
> *dev,
>  
>  	return test_dev_config_show_int(test_dev, buf, config-
> >test_result);
>  }
> -static DEVICE_ATTR(test_result, 0644, test_result_show,
> test_result_store);
> +static DEVICE_ATTR_RW(test_result);
>  
>  #define TEST_KMOD_DEV_ATTR(name)		&dev_attr_##name.att
> r
>  
> diff --git a/sound/soc/omap/mcbsp.c b/sound/soc/omap/mcbsp.c
> index 7a54e3083203..79d4dc785e5c 100644
> --- a/sound/soc/omap/mcbsp.c
> +++ b/sound/soc/omap/mcbsp.c
> @@ -854,7 +854,7 @@ static ssize_t dma_op_mode_store(struct device
> *dev,
>  	return size;
>  }
>  
> -static DEVICE_ATTR(dma_op_mode, 0644, dma_op_mode_show,
> dma_op_mode_store);
> +static DEVICE_ATTR_RW(dma_op_mode);
>  
>  static const struct attribute *additional_attrs[] = {
>  	&dev_attr_max_tx_thres.attr,
> @@ -923,7 +923,7 @@ static ssize_t st_taps_store(struct device *dev,
>  	return size;
>  }
>  
> -static DEVICE_ATTR(st_taps, 0644, st_taps_show, st_taps_store);
> +static DEVICE_ATTR_RW(st_taps);
>  
>  static const struct attribute *sidetone_attrs[] = {
>  	&dev_attr_st_taps.attr,
Bartlomiej Zolnierkiewicz Jan. 3, 2018, 3:16 p.m. UTC | #12
On Tuesday, December 19, 2017 10:15:07 AM Joe Perches wrote:
> Convert DEVICE_ATTR uses to DEVICE_ATTR_RW where possible.
> 
> Done with perl script:
> 
> $ git grep -w --name-only DEVICE_ATTR | \
>   xargs perl -i -e 'local $/; while (<>) { s/\bDEVICE_ATTR\s*\(\s*(\w+)\s*,\s*\(?(\s*S_IRUGO\s*\|\s*S_IWUSR|\s*S_IWUSR\s*\|\s*S_IRUGO\s*|\s*0644\s*)\)?\s*,\s*\1_show\s*,\s*\1_store\s*\)/DEVICE_ATTR_RW(\1)/g; print;}'
> 
> Signed-off-by: Joe Perches <joe@perches.com>
> ---
>  arch/s390/kernel/topology.c          |  3 +--
>  arch/tile/kernel/sysfs.c             |  2 +-
>  drivers/gpu/drm/i915/i915_sysfs.c    |  6 ++---
>  drivers/platform/x86/compal-laptop.c | 18 +++++----------
>  drivers/s390/cio/device.c            |  2 +-
>  drivers/scsi/lpfc/lpfc_attr.c        | 43 ++++++++++++------------------------
>  drivers/thermal/thermal_sysfs.c      |  9 ++++----
>  drivers/tty/serial/sh-sci.c          |  2 +-
>  drivers/usb/host/xhci-dbgcap.c       |  2 +-
>  drivers/usb/phy/phy-tahvo.c          |  2 +-
>  drivers/video/fbdev/auo_k190x.c      |  4 ++--
>  drivers/video/fbdev/w100fb.c         |  4 ++--
>  lib/test_firmware.c                  | 14 +++++-------
>  lib/test_kmod.c                      | 14 +++++-------
>  sound/soc/omap/mcbsp.c               |  4 ++--
>  15 files changed, 49 insertions(+), 80 deletions(-)

For fbdev changes:

Acked-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>

Best regards,
--
Bartlomiej Zolnierkiewicz
Samsung R&D Institute Poland
Samsung Electronics
Peter Ujfalusi Jan. 10, 2018, 2:43 p.m. UTC | #13
On 2017-12-20 12:54, Jarkko Nikula wrote:
> On Wed, Dec 20, 2017 at 10:32:11AM +0100, Greg Kroah-Hartman wrote:
>> On Wed, Dec 20, 2017 at 01:24:44AM -0800, Joe Perches wrote:
>>> On Wed, 2017-12-20 at 10:34 +0200, Jarkko Nikula wrote:
>>>> On Tue, Dec 19, 2017 at 10:15:07AM -0800, Joe Perches wrote:
>>>>> Convert DEVICE_ATTR uses to DEVICE_ATTR_RW where possible.
>>> [] 
>>>>> diff --git a/sound/soc/omap/mcbsp.c b/sound/soc/omap/mcbsp.c
>>> []
>>>>> @@ -854,7 +854,7 @@ static ssize_t dma_op_mode_store(struct device *dev,
>>>>>  	return size;
>>>>>  }
>>>>>  
>>>>> -static DEVICE_ATTR(dma_op_mode, 0644, dma_op_mode_show, dma_op_mode_store);
>>>>> +static DEVICE_ATTR_RW(dma_op_mode);
>>>>>  
>>>>
>>>> While I can ack this part here if it helps generic cleanup effort I
>>>> don't understart would it improve code readability in general? Mode 644
>>>> is clear and don't need any grepping but for DEVICE_ATTR_RW() I had to go
>>>> through all of these files in order to see what does it mean:
>>
>> Yeah, 644 is "clear", but _RW() is even more clear.  Ideally I want to
>> get rid of all of the "non-standard" users that set random modes of
>> sysfs files, as we get it wrong too many times.  Using the "defaults" is
>> much better.
>>
> Fair enough. For the sound/soc/omap/ (Acked-by was missing from my
> previous reply):
> 
> Acked-by: Jarkko Nikula <jarkko.nikula@bitmer.com>

And from me to the same file (sound/soc/omap/mcbsp.c):

Acked-by: Peter Ujfalusi <peter.ujfalusi@ti.com>


- Péter

Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki
diff mbox

Patch

diff --git a/arch/s390/kernel/topology.c b/arch/s390/kernel/topology.c
index 4d5b65e527b5..4b6e0397f66d 100644
--- a/arch/s390/kernel/topology.c
+++ b/arch/s390/kernel/topology.c
@@ -404,8 +404,7 @@  static ssize_t dispatching_store(struct device *dev,
 	put_online_cpus();
 	return rc ? rc : count;
 }
-static DEVICE_ATTR(dispatching, 0644, dispatching_show,
-			 dispatching_store);
+static DEVICE_ATTR_RW(dispatching);
 
 static ssize_t cpu_polarization_show(struct device *dev,
 				     struct device_attribute *attr, char *buf)
diff --git a/arch/tile/kernel/sysfs.c b/arch/tile/kernel/sysfs.c
index 825867c53853..af5024f0fb5a 100644
--- a/arch/tile/kernel/sysfs.c
+++ b/arch/tile/kernel/sysfs.c
@@ -184,7 +184,7 @@  static ssize_t hv_stats_store(struct device *dev,
 	return n < 0 ? n : count;
 }
 
-static DEVICE_ATTR(hv_stats, 0644, hv_stats_show, hv_stats_store);
+static DEVICE_ATTR_RW(hv_stats);
 
 static int hv_stats_device_add(struct device *dev, struct subsys_interface *sif)
 {
diff --git a/drivers/gpu/drm/i915/i915_sysfs.c b/drivers/gpu/drm/i915/i915_sysfs.c
index c74a20b80182..1d0ab8ff5915 100644
--- a/drivers/gpu/drm/i915/i915_sysfs.c
+++ b/drivers/gpu/drm/i915/i915_sysfs.c
@@ -447,9 +447,9 @@  static ssize_t gt_min_freq_mhz_store(struct device *kdev,
 
 static DEVICE_ATTR(gt_act_freq_mhz, S_IRUGO, gt_act_freq_mhz_show, NULL);
 static DEVICE_ATTR(gt_cur_freq_mhz, S_IRUGO, gt_cur_freq_mhz_show, NULL);
-static DEVICE_ATTR(gt_boost_freq_mhz, S_IRUGO | S_IWUSR, gt_boost_freq_mhz_show, gt_boost_freq_mhz_store);
-static DEVICE_ATTR(gt_max_freq_mhz, S_IRUGO | S_IWUSR, gt_max_freq_mhz_show, gt_max_freq_mhz_store);
-static DEVICE_ATTR(gt_min_freq_mhz, S_IRUGO | S_IWUSR, gt_min_freq_mhz_show, gt_min_freq_mhz_store);
+static DEVICE_ATTR_RW(gt_boost_freq_mhz);
+static DEVICE_ATTR_RW(gt_max_freq_mhz);
+static DEVICE_ATTR_RW(gt_min_freq_mhz);
 
 static DEVICE_ATTR(vlv_rpe_freq_mhz, S_IRUGO, vlv_rpe_freq_mhz_show, NULL);
 
diff --git a/drivers/platform/x86/compal-laptop.c b/drivers/platform/x86/compal-laptop.c
index 6bcb750e1865..4f9bc72f0584 100644
--- a/drivers/platform/x86/compal-laptop.c
+++ b/drivers/platform/x86/compal-laptop.c
@@ -679,18 +679,12 @@  static int bat_writeable_property(struct power_supply *psy,
 /* ============== */
 /* Driver Globals */
 /* ============== */
-static DEVICE_ATTR(wake_up_pme,
-		0644, wake_up_pme_show,		wake_up_pme_store);
-static DEVICE_ATTR(wake_up_modem,
-		0644, wake_up_modem_show,	wake_up_modem_store);
-static DEVICE_ATTR(wake_up_lan,
-		0644, wake_up_lan_show,	wake_up_lan_store);
-static DEVICE_ATTR(wake_up_wlan,
-		0644, wake_up_wlan_show,	wake_up_wlan_store);
-static DEVICE_ATTR(wake_up_key,
-		0644, wake_up_key_show,	wake_up_key_store);
-static DEVICE_ATTR(wake_up_mouse,
-		0644, wake_up_mouse_show,	wake_up_mouse_store);
+static DEVICE_ATTR_RW(wake_up_pme);
+static DEVICE_ATTR_RW(wake_up_modem);
+static DEVICE_ATTR_RW(wake_up_lan);
+static DEVICE_ATTR_RW(wake_up_wlan);
+static DEVICE_ATTR_RW(wake_up_key);
+static DEVICE_ATTR_RW(wake_up_mouse);
 
 static DEVICE_ATTR(fan1_input,  S_IRUGO, fan_show,          NULL);
 static DEVICE_ATTR(temp1_input, S_IRUGO, temp_cpu,          NULL);
diff --git a/drivers/s390/cio/device.c b/drivers/s390/cio/device.c
index 75a245f38e2e..6eefb67b31f3 100644
--- a/drivers/s390/cio/device.c
+++ b/drivers/s390/cio/device.c
@@ -600,7 +600,7 @@  static ssize_t vpm_show(struct device *dev, struct device_attribute *attr,
 static DEVICE_ATTR(devtype, 0444, devtype_show, NULL);
 static DEVICE_ATTR(cutype, 0444, cutype_show, NULL);
 static DEVICE_ATTR(modalias, 0444, modalias_show, NULL);
-static DEVICE_ATTR(online, 0644, online_show, online_store);
+static DEVICE_ATTR_RW(online);
 static DEVICE_ATTR(availability, 0444, available_show, NULL);
 static DEVICE_ATTR(logging, 0200, NULL, initiate_logging);
 static DEVICE_ATTR(vpm, 0444, vpm_show, NULL);
diff --git a/drivers/scsi/lpfc/lpfc_attr.c b/drivers/scsi/lpfc/lpfc_attr.c
index 797bb42a6306..95f7ba3c3f1a 100644
--- a/drivers/scsi/lpfc/lpfc_attr.c
+++ b/drivers/scsi/lpfc/lpfc_attr.c
@@ -2519,8 +2519,7 @@  lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
 				"reinit adapter - %d\n", stat2);
 	return (stat1 || stat2) ? -EIO : count;
 }
-static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,
-		   lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
+static DEVICE_ATTR_RW(lpfc_soft_wwpn);
 
 /**
  * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
@@ -2583,8 +2582,7 @@  lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
 
 	return count;
 }
-static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,
-		   lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
+static DEVICE_ATTR_RW(lpfc_soft_wwnn);
 
 /**
  * lpfc_oas_tgt_show - Return wwpn of target whose luns maybe enabled for
@@ -3102,8 +3100,7 @@  MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
 		 " 1 - poll with interrupts enabled"
 		 " 3 - poll and disable FCP ring interrupts");
 
-static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
-		   lpfc_poll_show, lpfc_poll_store);
+static DEVICE_ATTR_RW(lpfc_poll);
 
 int lpfc_no_hba_reset_cnt;
 unsigned long lpfc_no_hba_reset[MAX_HBAS_NO_RESET] = {
@@ -3336,8 +3333,7 @@  lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
 
 lpfc_vport_param_store(nodev_tmo)
 
-static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
-		   lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
+static DEVICE_ATTR_RW(lpfc_nodev_tmo);
 
 /*
 # lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
@@ -3386,8 +3382,7 @@  lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
 }
 
 lpfc_vport_param_store(devloss_tmo)
-static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
-		   lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
+static DEVICE_ATTR_RW(lpfc_devloss_tmo);
 
 /*
  * lpfc_suppress_rsp: Enable suppress rsp feature is firmware supports it
@@ -3580,8 +3575,7 @@  lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
 	return 0;
 }
 lpfc_vport_param_store(restrict_login);
-static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
-		   lpfc_restrict_login_show, lpfc_restrict_login_store);
+static DEVICE_ATTR_RW(lpfc_restrict_login);
 
 /*
 # Some disk devices have a "select ID" or "select Target" capability.
@@ -3695,8 +3689,7 @@  lpfc_topology_store(struct device *dev, struct device_attribute *attr,
 }
 
 lpfc_param_show(topology)
-static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
-		lpfc_topology_show, lpfc_topology_store);
+static DEVICE_ATTR_RW(lpfc_topology);
 
 /**
  * lpfc_static_vport_show: Read callback function for
@@ -3954,8 +3947,7 @@  lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
 /*
  * Sysfs attribute to control the statistical data collection.
  */
-static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
-		   lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
+static DEVICE_ATTR_RW(lpfc_stat_data_ctrl);
 
 /*
  * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
@@ -4194,8 +4186,7 @@  lpfc_link_speed_init(struct lpfc_hba *phba, int val)
 	return -EINVAL;
 }
 
-static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
-		   lpfc_link_speed_show, lpfc_link_speed_store);
+static DEVICE_ATTR_RW(lpfc_link_speed);
 
 /*
 # lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
@@ -4288,8 +4279,7 @@  lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
 	return rc;
 }
 
-static DEVICE_ATTR(lpfc_aer_support, S_IRUGO | S_IWUSR,
-		   lpfc_aer_support_show, lpfc_aer_support_store);
+static DEVICE_ATTR_RW(lpfc_aer_support);
 
 /**
  * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
@@ -4436,8 +4426,7 @@  LPFC_ATTR(sriov_nr_virtfn, LPFC_DEF_VFN_PER_PFN, 0, LPFC_MAX_VFN_PER_PFN,
 	"Enable PCIe device SR-IOV virtual fn");
 
 lpfc_param_show(sriov_nr_virtfn)
-static DEVICE_ATTR(lpfc_sriov_nr_virtfn, S_IRUGO | S_IWUSR,
-		   lpfc_sriov_nr_virtfn_show, lpfc_sriov_nr_virtfn_store);
+static DEVICE_ATTR_RW(lpfc_sriov_nr_virtfn);
 
 /**
  * lpfc_request_firmware_store - Request for Linux generic firmware upgrade
@@ -4611,8 +4600,7 @@  lpfc_fcp_imax_init(struct lpfc_hba *phba, int val)
 	return 0;
 }
 
-static DEVICE_ATTR(lpfc_fcp_imax, S_IRUGO | S_IWUSR,
-		   lpfc_fcp_imax_show, lpfc_fcp_imax_store);
+static DEVICE_ATTR_RW(lpfc_fcp_imax);
 
 /*
  * lpfc_auto_imax: Controls Auto-interrupt coalescing values support.
@@ -4772,8 +4760,7 @@  lpfc_fcp_cpu_map_init(struct lpfc_hba *phba, int val)
 	return 0;
 }
 
-static DEVICE_ATTR(lpfc_fcp_cpu_map, S_IRUGO | S_IWUSR,
-		   lpfc_fcp_cpu_map_show, lpfc_fcp_cpu_map_store);
+static DEVICE_ATTR_RW(lpfc_fcp_cpu_map);
 
 /*
 # lpfc_fcp_class:  Determines FC class to use for the FCP protocol.
@@ -4859,9 +4846,7 @@  lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
 	return 0;
 }
 lpfc_vport_param_store(max_scsicmpl_time);
-static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
-		   lpfc_max_scsicmpl_time_show,
-		   lpfc_max_scsicmpl_time_store);
+static DEVICE_ATTR_RW(lpfc_max_scsicmpl_time);
 
 /*
 # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c
index fb80c96d8f73..c008af7fb480 100644
--- a/drivers/thermal/thermal_sysfs.c
+++ b/drivers/thermal/thermal_sysfs.c
@@ -398,14 +398,13 @@  create_s32_tzp_attr(offset);
  */
 static DEVICE_ATTR(type, 0444, type_show, NULL);
 static DEVICE_ATTR(temp, 0444, temp_show, NULL);
-static DEVICE_ATTR(policy, S_IRUGO | S_IWUSR, policy_show, policy_store);
+static DEVICE_ATTR_RW(policy);
 static DEVICE_ATTR(available_policies, S_IRUGO, available_policies_show, NULL);
-static DEVICE_ATTR(sustainable_power, S_IWUSR | S_IRUGO, sustainable_power_show,
-		   sustainable_power_store);
+static DEVICE_ATTR_RW(sustainable_power);
 
 /* These thermal zone device attributes are created based on conditions */
-static DEVICE_ATTR(mode, 0644, mode_show, mode_store);
-static DEVICE_ATTR(passive, S_IRUGO | S_IWUSR, passive_show, passive_store);
+static DEVICE_ATTR_RW(mode);
+static DEVICE_ATTR_RW(passive);
 
 /* These attributes are unconditionally added to a thermal zone */
 static struct attribute *thermal_zone_dev_attrs[] = {
diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index d9f399c4e90c..7257c078e155 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -1144,7 +1144,7 @@  static ssize_t rx_fifo_timeout_store(struct device *dev,
 	return count;
 }
 
-static DEVICE_ATTR(rx_fifo_timeout, 0644, rx_fifo_timeout_show, rx_fifo_timeout_store);
+static DEVICE_ATTR_RW(rx_fifo_timeout);
 
 
 #ifdef CONFIG_SERIAL_SH_SCI_DMA
diff --git a/drivers/usb/host/xhci-dbgcap.c b/drivers/usb/host/xhci-dbgcap.c
index 452df0f87d6e..a1ab8acf39ba 100644
--- a/drivers/usb/host/xhci-dbgcap.c
+++ b/drivers/usb/host/xhci-dbgcap.c
@@ -920,7 +920,7 @@  static ssize_t dbc_store(struct device *dev,
 	return count;
 }
 
-static DEVICE_ATTR(dbc, 0644, dbc_show, dbc_store);
+static DEVICE_ATTR_RW(dbc);
 
 int xhci_dbc_init(struct xhci_hcd *xhci)
 {
diff --git a/drivers/usb/phy/phy-tahvo.c b/drivers/usb/phy/phy-tahvo.c
index b3ce42edb373..7f7c5c82420d 100644
--- a/drivers/usb/phy/phy-tahvo.c
+++ b/drivers/usb/phy/phy-tahvo.c
@@ -310,7 +310,7 @@  static ssize_t otg_mode_store(struct device *device,
 
 	return r;
 }
-static DEVICE_ATTR(otg_mode, 0644, otg_mode_show, otg_mode_store);
+static DEVICE_ATTR_RW(otg_mode);
 
 static struct attribute *tahvo_attributes[] = {
 	&dev_attr_vbus.attr,
diff --git a/drivers/video/fbdev/auo_k190x.c b/drivers/video/fbdev/auo_k190x.c
index 0d06038324e0..1e383c547633 100644
--- a/drivers/video/fbdev/auo_k190x.c
+++ b/drivers/video/fbdev/auo_k190x.c
@@ -708,8 +708,8 @@  static ssize_t temp_show(struct device *dev, struct device_attribute *attr,
 	return sprintf(buf, "%d\n", temp);
 }
 
-static DEVICE_ATTR(update_mode, 0644, update_mode_show, update_mode_store);
-static DEVICE_ATTR(flash, 0644, flash_show, flash_store);
+static DEVICE_ATTR_RW(update_mode);
+static DEVICE_ATTR_RW(flash);
 static DEVICE_ATTR(temp, 0644, temp_show, NULL);
 
 static struct attribute *auok190x_attributes[] = {
diff --git a/drivers/video/fbdev/w100fb.c b/drivers/video/fbdev/w100fb.c
index d570e19a2864..035ff6e02894 100644
--- a/drivers/video/fbdev/w100fb.c
+++ b/drivers/video/fbdev/w100fb.c
@@ -110,7 +110,7 @@  static ssize_t flip_store(struct device *dev, struct device_attribute *attr, con
 	return count;
 }
 
-static DEVICE_ATTR(flip, 0644, flip_show, flip_store);
+static DEVICE_ATTR_RW(flip);
 
 static ssize_t w100fb_reg_read(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
 {
@@ -166,7 +166,7 @@  static ssize_t fastpllclk_store(struct device *dev, struct device_attribute *att
 	return count;
 }
 
-static DEVICE_ATTR(fastpllclk, 0644, fastpllclk_show, fastpllclk_store);
+static DEVICE_ATTR_RW(fastpllclk);
 
 /*
  * Some touchscreens need hsync information from the video driver to
diff --git a/lib/test_firmware.c b/lib/test_firmware.c
index 64a4c76cba2b..964784dc1602 100644
--- a/lib/test_firmware.c
+++ b/lib/test_firmware.c
@@ -359,7 +359,7 @@  static ssize_t config_name_show(struct device *dev,
 {
 	return config_test_show_str(buf, test_fw_config->name);
 }
-static DEVICE_ATTR(config_name, 0644, config_name_show, config_name_store);
+static DEVICE_ATTR_RW(config_name);
 
 static ssize_t config_num_requests_store(struct device *dev,
 					 struct device_attribute *attr,
@@ -388,8 +388,7 @@  static ssize_t config_num_requests_show(struct device *dev,
 {
 	return test_dev_config_show_u8(buf, test_fw_config->num_requests);
 }
-static DEVICE_ATTR(config_num_requests, 0644, config_num_requests_show,
-		   config_num_requests_store);
+static DEVICE_ATTR_RW(config_num_requests);
 
 static ssize_t config_sync_direct_store(struct device *dev,
 					struct device_attribute *attr,
@@ -411,8 +410,7 @@  static ssize_t config_sync_direct_show(struct device *dev,
 {
 	return test_dev_config_show_bool(buf, test_fw_config->sync_direct);
 }
-static DEVICE_ATTR(config_sync_direct, 0644, config_sync_direct_show,
-		   config_sync_direct_store);
+static DEVICE_ATTR_RW(config_sync_direct);
 
 static ssize_t config_send_uevent_store(struct device *dev,
 					struct device_attribute *attr,
@@ -428,8 +426,7 @@  static ssize_t config_send_uevent_show(struct device *dev,
 {
 	return test_dev_config_show_bool(buf, test_fw_config->send_uevent);
 }
-static DEVICE_ATTR(config_send_uevent, 0644, config_send_uevent_show,
-		   config_send_uevent_store);
+static DEVICE_ATTR_RW(config_send_uevent);
 
 static ssize_t config_read_fw_idx_store(struct device *dev,
 					struct device_attribute *attr,
@@ -445,8 +442,7 @@  static ssize_t config_read_fw_idx_show(struct device *dev,
 {
 	return test_dev_config_show_u8(buf, test_fw_config->read_fw_idx);
 }
-static DEVICE_ATTR(config_read_fw_idx, 0644, config_read_fw_idx_show,
-		   config_read_fw_idx_store);
+static DEVICE_ATTR_RW(config_read_fw_idx);
 
 
 static ssize_t trigger_request_store(struct device *dev,
diff --git a/lib/test_kmod.c b/lib/test_kmod.c
index 337f408b4de6..e372b97eee13 100644
--- a/lib/test_kmod.c
+++ b/lib/test_kmod.c
@@ -694,8 +694,7 @@  static ssize_t config_test_driver_show(struct device *dev,
 	return config_test_show_str(&test_dev->config_mutex, buf,
 				    config->test_driver);
 }
-static DEVICE_ATTR(config_test_driver, 0644, config_test_driver_show,
-		   config_test_driver_store);
+static DEVICE_ATTR_RW(config_test_driver);
 
 static ssize_t config_test_fs_store(struct device *dev,
 				    struct device_attribute *attr,
@@ -726,8 +725,7 @@  static ssize_t config_test_fs_show(struct device *dev,
 	return config_test_show_str(&test_dev->config_mutex, buf,
 				    config->test_fs);
 }
-static DEVICE_ATTR(config_test_fs, 0644, config_test_fs_show,
-		   config_test_fs_store);
+static DEVICE_ATTR_RW(config_test_fs);
 
 static int trigger_config_run_type(struct kmod_test_device *test_dev,
 				   enum kmod_test_case test_case,
@@ -1012,8 +1010,7 @@  static ssize_t config_num_threads_show(struct device *dev,
 
 	return test_dev_config_show_int(test_dev, buf, config->num_threads);
 }
-static DEVICE_ATTR(config_num_threads, 0644, config_num_threads_show,
-		   config_num_threads_store);
+static DEVICE_ATTR_RW(config_num_threads);
 
 static ssize_t config_test_case_store(struct device *dev,
 				      struct device_attribute *attr,
@@ -1037,8 +1034,7 @@  static ssize_t config_test_case_show(struct device *dev,
 
 	return test_dev_config_show_uint(test_dev, buf, config->test_case);
 }
-static DEVICE_ATTR(config_test_case, 0644, config_test_case_show,
-		   config_test_case_store);
+static DEVICE_ATTR_RW(config_test_case);
 
 static ssize_t test_result_show(struct device *dev,
 				struct device_attribute *attr,
@@ -1049,7 +1045,7 @@  static ssize_t test_result_show(struct device *dev,
 
 	return test_dev_config_show_int(test_dev, buf, config->test_result);
 }
-static DEVICE_ATTR(test_result, 0644, test_result_show, test_result_store);
+static DEVICE_ATTR_RW(test_result);
 
 #define TEST_KMOD_DEV_ATTR(name)		&dev_attr_##name.attr
 
diff --git a/sound/soc/omap/mcbsp.c b/sound/soc/omap/mcbsp.c
index 7a54e3083203..79d4dc785e5c 100644
--- a/sound/soc/omap/mcbsp.c
+++ b/sound/soc/omap/mcbsp.c
@@ -854,7 +854,7 @@  static ssize_t dma_op_mode_store(struct device *dev,
 	return size;
 }
 
-static DEVICE_ATTR(dma_op_mode, 0644, dma_op_mode_show, dma_op_mode_store);
+static DEVICE_ATTR_RW(dma_op_mode);
 
 static const struct attribute *additional_attrs[] = {
 	&dev_attr_max_tx_thres.attr,
@@ -923,7 +923,7 @@  static ssize_t st_taps_store(struct device *dev,
 	return size;
 }
 
-static DEVICE_ATTR(st_taps, 0644, st_taps_show, st_taps_store);
+static DEVICE_ATTR_RW(st_taps);
 
 static const struct attribute *sidetone_attrs[] = {
 	&dev_attr_st_taps.attr,