Linux PCI subsystem development
 help / color / mirror / Atom feed
* [PATCH 00/15] use permission-specific DEVICE_ATTR variants
@ 2016-10-29 19:36 Julia Lawall
  2016-10-29 19:37 ` [PATCH 13/15] PCI/ASPM: " Julia Lawall
  0 siblings, 1 reply; 4+ messages in thread
From: Julia Lawall @ 2016-10-29 19:36 UTC (permalink / raw)
  To: netdev
  Cc: kernel-janitors, linux-omap, alsa-devel, linuxppc-dev, linux-mips,
	linux-pm, patches, linux-kernel, linux-usb, linux-arm-kernel,
	linux-fbdev, linux-pci, linux-atm-general


Use DEVICE_ATTR_RO etc. for read only attributes etc.  This simplifies the
source code, improves readbility, and reduces the chance of
inconsistencies.

The complete semantic patch is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@ro@
declarer name DEVICE_ATTR;
identifier x,x_show;
@@

DEVICE_ATTR(x, \(0444\|S_IRUGO\), x_show, NULL);

@wo@
declarer name DEVICE_ATTR;
identifier x,x_store;
@@

DEVICE_ATTR(x, \(0200\|S_IWUSR\), NULL, x_store);

@rw@
declarer name DEVICE_ATTR;
identifier x,x_show,x_store;
@@

DEVICE_ATTR(x, \(0644\|S_IRUGO|S_IWUSR\), x_show, x_store);

@script:ocaml@
x << ro.x;
x_show << ro.x_show;
@@

if not (x^"_show" = x_show) then Coccilib.include_match false

@script:ocaml@
x << wo.x;
x_store << wo.x_store;
@@

if not (x^"_store" = x_store) then Coccilib.include_match false

@script:ocaml@
x << rw.x;
x_show << rw.x_show;
x_store << rw.x_store;
@@

if not (x^"_show" = x_show && x^"_store" = x_store)
then Coccilib.include_match false

@@
declarer name DEVICE_ATTR_RO;
identifier ro.x,ro.x_show;
@@

- DEVICE_ATTR(x, \(0444\|S_IRUGO\), x_show, NULL);
+ DEVICE_ATTR_RO(x);

@@
declarer name DEVICE_ATTR_WO;
identifier wo.x,wo.x_store;
@@

- DEVICE_ATTR(x, \(0200\|S_IWUSR\), NULL, x_store);
+ DEVICE_ATTR_WO(x);

@@
declarer name DEVICE_ATTR_RW;
identifier rw.x,rw.x_show,rw.x_store;
@@

- DEVICE_ATTR(x, \(0644\|S_IRUGO|S_IWUSR\), x_show, x_store);
+ DEVICE_ATTR_RW(x);
// </smpl>

---

 arch/mips/txx9/generic/7segled.c                  |    4 ++--
 arch/powerpc/kernel/iommu.c                       |    3 +--
 arch/tile/kernel/sysfs.c                          |   14 +++++++-------
 drivers/atm/solos-pci.c                           |    2 +-
 drivers/pci/pcie/aspm.c                           |    4 ++--
 drivers/power/supply/wm8350_power.c               |    2 +-
 drivers/ptp/ptp_sysfs.c                           |    2 +-
 drivers/thermal/int340x_thermal/int3400_thermal.c |    2 +-
 drivers/thermal/thermal_hwmon.c                   |    2 +-
 drivers/tty/nozomi.c                              |    4 ++--
 drivers/usb/wusbcore/dev-sysfs.c                  |    6 +++---
 drivers/usb/wusbcore/wusbhc.c                     |   13 +++++--------
 drivers/video/fbdev/wm8505fb.c                    |    2 +-
 sound/soc/omap/mcbsp.c                            |    4 ++--
 sound/soc/soc-dapm.c                              |    2 +-
 15 files changed, 31 insertions(+), 35 deletions(-)

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

* [PATCH 13/15] PCI/ASPM: use permission-specific DEVICE_ATTR variants
  2016-10-29 19:36 [PATCH 00/15] use permission-specific DEVICE_ATTR variants Julia Lawall
@ 2016-10-29 19:37 ` Julia Lawall
  2016-11-14 21:40   ` Bjorn Helgaas
  0 siblings, 1 reply; 4+ messages in thread
From: Julia Lawall @ 2016-10-29 19:37 UTC (permalink / raw)
  To: Bjorn Helgaas; +Cc: kernel-janitors, linux-pci, linux-kernel

Use DEVICE_ATTR_RW for read-write attributes.  This simplifies the
source code, improves readbility, and reduces the chance of
inconsistencies.

The semantic patch that makes this change is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@rw@
declarer name DEVICE_ATTR;
identifier x,x_show,x_store;
@@

DEVICE_ATTR(x, \(0644\|S_IRUGO|S_IWUSR\), x_show, x_store);

@script:ocaml@
x << rw.x;
x_show << rw.x_show;
x_store << rw.x_store;
@@

if not (x^"_show" = x_show && x^"_store" = x_store)
then Coccilib.include_match false

@@
declarer name DEVICE_ATTR_RW;
identifier rw.x,rw.x_show,rw.x_store;
@@

- DEVICE_ATTR(x, \(0644\|S_IRUGO|S_IWUSR\), x_show, x_store);
+ DEVICE_ATTR_RW(x);
// </smpl>

Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>

---
 drivers/pci/pcie/aspm.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
index 0ec649d..3b14d9e 100644
--- a/drivers/pci/pcie/aspm.c
+++ b/drivers/pci/pcie/aspm.c
@@ -886,8 +886,8 @@ static ssize_t clk_ctl_store(struct device *dev,
 	return n;
 }
 
-static DEVICE_ATTR(link_state, 0644, link_state_show, link_state_store);
-static DEVICE_ATTR(clk_ctl, 0644, clk_ctl_show, clk_ctl_store);
+static DEVICE_ATTR_RW(link_state);
+static DEVICE_ATTR_RW(clk_ctl);
 
 static char power_group[] = "power";
 void pcie_aspm_create_sysfs_dev_files(struct pci_dev *pdev)

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

* Re: [PATCH 13/15] PCI/ASPM: use permission-specific DEVICE_ATTR variants
  2016-10-29 19:37 ` [PATCH 13/15] PCI/ASPM: " Julia Lawall
@ 2016-11-14 21:40   ` Bjorn Helgaas
  2016-11-14 21:52     ` Julia Lawall
  0 siblings, 1 reply; 4+ messages in thread
From: Bjorn Helgaas @ 2016-11-14 21:40 UTC (permalink / raw)
  To: Julia Lawall; +Cc: Bjorn Helgaas, kernel-janitors, linux-pci, linux-kernel

On Sat, Oct 29, 2016 at 09:37:07PM +0200, Julia Lawall wrote:
> Use DEVICE_ATTR_RW for read-write attributes.  This simplifies the
> source code, improves readbility, and reduces the chance of
> inconsistencies.
> 
> The semantic patch that makes this change is as follows:
> (http://coccinelle.lip6.fr/)
> 
> // <smpl>
> @rw@
> declarer name DEVICE_ATTR;
> identifier x,x_show,x_store;
> @@
> 
> DEVICE_ATTR(x, \(0644\|S_IRUGO|S_IWUSR\), x_show, x_store);
> 
> @script:ocaml@
> x << rw.x;
> x_show << rw.x_show;
> x_store << rw.x_store;
> @@
> 
> if not (x^"_show" = x_show && x^"_store" = x_store)
> then Coccilib.include_match false
> 
> @@
> declarer name DEVICE_ATTR_RW;
> identifier rw.x,rw.x_show,rw.x_store;
> @@
> 
> - DEVICE_ATTR(x, \(0644\|S_IRUGO|S_IWUSR\), x_show, x_store);
> + DEVICE_ATTR_RW(x);
> // </smpl>
> 
> Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>

I applied this to pci/aspm to follow the herd, although it looks
pretty similar to the ill-fated "Replace numeric parameter like 0444
with macro" series (http://lwn.net/Articles/696229/).  Maybe this is
different because everybody except me knows what ATTR_RW means?  To
me, "0644" contained more information than "_RW" does.

I do certainly like the removal of the "_show" and "_store"
redundancy.

> ---
>  drivers/pci/pcie/aspm.c |    4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
> index 0ec649d..3b14d9e 100644
> --- a/drivers/pci/pcie/aspm.c
> +++ b/drivers/pci/pcie/aspm.c
> @@ -886,8 +886,8 @@ static ssize_t clk_ctl_store(struct device *dev,
>  	return n;
>  }
>  
> -static DEVICE_ATTR(link_state, 0644, link_state_show, link_state_store);
> -static DEVICE_ATTR(clk_ctl, 0644, clk_ctl_show, clk_ctl_store);
> +static DEVICE_ATTR_RW(link_state);
> +static DEVICE_ATTR_RW(clk_ctl);
>  
>  static char power_group[] = "power";
>  void pcie_aspm_create_sysfs_dev_files(struct pci_dev *pdev)
> 

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

* Re: [PATCH 13/15] PCI/ASPM: use permission-specific DEVICE_ATTR variants
  2016-11-14 21:40   ` Bjorn Helgaas
@ 2016-11-14 21:52     ` Julia Lawall
  0 siblings, 0 replies; 4+ messages in thread
From: Julia Lawall @ 2016-11-14 21:52 UTC (permalink / raw)
  To: Bjorn Helgaas; +Cc: Bjorn Helgaas, kernel-janitors, linux-pci, linux-kernel



On Mon, 14 Nov 2016, Bjorn Helgaas wrote:

> On Sat, Oct 29, 2016 at 09:37:07PM +0200, Julia Lawall wrote:
> > Use DEVICE_ATTR_RW for read-write attributes.  This simplifies the
> > source code, improves readbility, and reduces the chance of
> > inconsistencies.
> >
> > The semantic patch that makes this change is as follows:
> > (http://coccinelle.lip6.fr/)
> >
> > // <smpl>
> > @rw@
> > declarer name DEVICE_ATTR;
> > identifier x,x_show,x_store;
> > @@
> >
> > DEVICE_ATTR(x, \(0644\|S_IRUGO|S_IWUSR\), x_show, x_store);
> >
> > @script:ocaml@
> > x << rw.x;
> > x_show << rw.x_show;
> > x_store << rw.x_store;
> > @@
> >
> > if not (x^"_show" = x_show && x^"_store" = x_store)
> > then Coccilib.include_match false
> >
> > @@
> > declarer name DEVICE_ATTR_RW;
> > identifier rw.x,rw.x_show,rw.x_store;
> > @@
> >
> > - DEVICE_ATTR(x, \(0644\|S_IRUGO|S_IWUSR\), x_show, x_store);
> > + DEVICE_ATTR_RW(x);
> > // </smpl>
> >
> > Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
>
> I applied this to pci/aspm to follow the herd, although it looks
> pretty similar to the ill-fated "Replace numeric parameter like 0444
> with macro" series (http://lwn.net/Articles/696229/).  Maybe this is
> different because everybody except me knows what ATTR_RW means?  To
> me, "0644" contained more information than "_RW" does.
>
> I do certainly like the removal of the "_show" and "_store"
> redundancy.

I think that the point is the latter.  There were also a couple of cases
where the permissions didn't match with the set of provided functions.

julia

>
> > ---
> >  drivers/pci/pcie/aspm.c |    4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
> > index 0ec649d..3b14d9e 100644
> > --- a/drivers/pci/pcie/aspm.c
> > +++ b/drivers/pci/pcie/aspm.c
> > @@ -886,8 +886,8 @@ static ssize_t clk_ctl_store(struct device *dev,
> >  	return n;
> >  }
> >
> > -static DEVICE_ATTR(link_state, 0644, link_state_show, link_state_store);
> > -static DEVICE_ATTR(clk_ctl, 0644, clk_ctl_show, clk_ctl_store);
> > +static DEVICE_ATTR_RW(link_state);
> > +static DEVICE_ATTR_RW(clk_ctl);
> >
> >  static char power_group[] = "power";
> >  void pcie_aspm_create_sysfs_dev_files(struct pci_dev *pdev)
> >
>

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

end of thread, other threads:[~2016-11-14 21:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-10-29 19:36 [PATCH 00/15] use permission-specific DEVICE_ATTR variants Julia Lawall
2016-10-29 19:37 ` [PATCH 13/15] PCI/ASPM: " Julia Lawall
2016-11-14 21:40   ` Bjorn Helgaas
2016-11-14 21:52     ` Julia Lawall

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox