Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1511876 > unrolled thread

[PATCH 10/15] ASoC: omap-mcbsp: use permission-specific DEVICE_ATTR variants

Started byJulia Lawall <Julia.Lawall@lip6.fr>
First post2016-10-29 22:00 +0200
Last post2016-10-30 13:00 +0100
Articles 3 — 3 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH 10/15] ASoC: omap-mcbsp: use permission-specific DEVICE_ATTR variants Julia Lawall <Julia.Lawall@lip6.fr> - 2016-10-29 22:00 +0200
    Re: [PATCH 10/15] ASoC: omap-mcbsp: use permission-specific  DEVICE_ATTR variants Jarkko Nikula <jarkko.nikula@bitmer.com> - 2016-10-30 12:40 +0100
      Re: [PATCH 10/15] ASoC: omap-mcbsp: use permission-specific DEVICE_ATTR  variants Julia Lawall <julia.lawall@lip6.fr> - 2016-10-30 13:00 +0100

#1511876 — [PATCH 10/15] ASoC: omap-mcbsp: use permission-specific DEVICE_ATTR variants

FromJulia Lawall <Julia.Lawall@lip6.fr>
Date2016-10-29 22:00 +0200
Subject[PATCH 10/15] ASoC: omap-mcbsp: use permission-specific DEVICE_ATTR variants
Message-ID<sxHXj-2qm-7@gated-at.bofh.it>
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>

---
 sound/soc/omap/mcbsp.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sound/soc/omap/mcbsp.c b/sound/soc/omap/mcbsp.c
index 06fec56..0b363d1 100644
--- a/sound/soc/omap/mcbsp.c
+++ b/sound/soc/omap/mcbsp.c
@@ -858,7 +858,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,
@@ -927,7 +927,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,

[toc] | [next] | [standalone]


#1512046 — Re: [PATCH 10/15] ASoC: omap-mcbsp: use permission-specific DEVICE_ATTR variants

FromJarkko Nikula <jarkko.nikula@bitmer.com>
Date2016-10-30 12:40 +0100
SubjectRe: [PATCH 10/15] ASoC: omap-mcbsp: use permission-specific DEVICE_ATTR variants
Message-ID<sxWD0-42a-3@gated-at.bofh.it>
In reply to#1511876
Hi

On Sat, 29 Oct 2016 21:37:04 +0200
Julia Lawall <Julia.Lawall@lip6.fr> wrote:

> Use DEVICE_ATTR_RW for read-write attributes.  This simplifies the
> source code, improves readbility, and reduces the chance of
> inconsistencies.
> 
...
> 
> - DEVICE_ATTR(x, \(0644\|S_IRUGO|S_IWUSR\), x_show, x_store);
> + DEVICE_ATTR_RW(x);

I'm not so sure does this improve readability. 644 is pretty obvious but for DEVICE_ATTR_RW() one has to dive into include/linux/device.h and include/linux/sysfs.h to see for what users it grants the write access.

-- 
Jarkko

[toc] | [prev] | [next] | [standalone]


#1512050 — Re: [PATCH 10/15] ASoC: omap-mcbsp: use permission-specific DEVICE_ATTR variants

FromJulia Lawall <julia.lawall@lip6.fr>
Date2016-10-30 13:00 +0100
SubjectRe: [PATCH 10/15] ASoC: omap-mcbsp: use permission-specific DEVICE_ATTR variants
Message-ID<sxWWl-48W-7@gated-at.bofh.it>
In reply to#1512046

On Sun, 30 Oct 2016, Jarkko Nikula wrote:

> Hi
>
> On Sat, 29 Oct 2016 21:37:04 +0200
> Julia Lawall <Julia.Lawall@lip6.fr> wrote:
>
> > Use DEVICE_ATTR_RW for read-write attributes.  This simplifies the
> > source code, improves readbility, and reduces the chance of
> > inconsistencies.
> >
> ...
> >
> > - DEVICE_ATTR(x, \(0644\|S_IRUGO|S_IWUSR\), x_show, x_store);
> > + DEVICE_ATTR_RW(x);
>
> I'm not so sure does this improve readability. 644 is pretty obvious but
> for DEVICE_ATTR_RW() one has to dive into include/linux/device.h and
> include/linux/sysfs.h to see for what users it grants the write access.

OK, as you like.  It does help ensure that the functions that are supposed
to be defined are available.  There were a couple of occurrences of 0644
with no show or no store function.  Among the three declarers, there are
currently in total over 800 uses in the kernel, so they are also not so
obscure.

julia

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web