2016-09-11 13:26:22

by Julia Lawall

[permalink] [raw]
Subject: [PATCH 00/26] constify local structures

Constify local structures.

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

// <smpl>
// The first rule ignores some cases that posed problems
@r disable optional_qualifier@
identifier s != {peri_clk_data,threshold_attr,tracer_flags,tracer};
identifier i != {s5k5baf_cis_rect,smtcfb_fix};
position p;
@@
static struct s i@p = { ... };

@lstruct@
identifier r.s;
@@
struct s { ... };

@used depends on lstruct@
identifier r.i;
@@
i

@bad1@
expression e;
identifier r.i;
assignment operator a;
@@
(<+...i...+>) a e

@bad2@
identifier r.i;
@@
&(<+...i...+>)

@bad3@
identifier r.i;
declarer d;
@@
d(...,<+...i...+>,...);

@bad4@
identifier r.i;
type T;
T[] e;
identifier f;
position p;
@@

f@p(...,
(
(<+...i...+>)
&
e
)
,...)

@bad4a@
identifier r.i;
type T;
T *e;
identifier f;
position p;
@@

f@p(...,
(
(<+...i...+>)
&
e
)
,...)

@ok5@
expression *e;
identifier r.i;
position p;
@@
e =@p i

@bad5@
expression *e;
identifier r.i;
position p != ok5.p;
@@
e =@p (<+...i...+>)

@rr depends on used && !bad1 && !bad2 && !bad3 && !bad4 && !bad4a && !bad5@
identifier s,r.i;
position r.p;
@@

static
+const
struct s i@p = { ... };

@depends on used && !bad1 && !bad2 && !bad3 && !bad4 && !bad4a && !bad5
disable optional_qualifier@
identifier rr.s,r.i;
@@

static
+const
struct s i;
// </smpl>

---

drivers/acpi/acpi_apd.c | 8 +++---
drivers/char/tpm/tpm-interface.c | 10 ++++----
drivers/char/tpm/tpm-sysfs.c | 2 -
drivers/cpufreq/intel_pstate.c | 8 +++---
drivers/infiniband/hw/i40iw/i40iw_uk.c | 6 ++---
drivers/media/i2c/tvp514x.c | 2 -
drivers/media/pci/ddbridge/ddbridge-core.c | 18 +++++++--------
drivers/media/pci/ngene/ngene-cards.c | 14 ++++++------
drivers/media/pci/smipcie/smipcie-main.c | 8 +++---
drivers/misc/sgi-xp/xpc_uv.c | 2 -
drivers/net/arcnet/com20020-pci.c | 10 ++++----
drivers/net/can/c_can/c_can_pci.c | 4 +--
drivers/net/can/sja1000/plx_pci.c | 20 ++++++++---------
drivers/net/ethernet/mellanox/mlx4/main.c | 4 +--
drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c | 2 -
drivers/net/ethernet/renesas/sh_eth.c | 14 ++++++------
drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c | 2 -
drivers/net/wireless/ath/dfs_pattern_detector.c | 2 -
drivers/net/wireless/intel/iwlegacy/3945.c | 4 +--
drivers/net/wireless/realtek/rtlwifi/rtl8188ee/sw.c | 2 -
drivers/net/wireless/realtek/rtlwifi/rtl8192ce/sw.c | 2 -
drivers/net/wireless/realtek/rtlwifi/rtl8192de/sw.c | 2 -
drivers/net/wireless/realtek/rtlwifi/rtl8192ee/sw.c | 2 -
drivers/net/wireless/realtek/rtlwifi/rtl8192se/sw.c | 2 -
drivers/net/wireless/realtek/rtlwifi/rtl8723ae/sw.c | 2 -
drivers/net/wireless/realtek/rtlwifi/rtl8723be/sw.c | 2 -
drivers/net/wireless/realtek/rtlwifi/rtl8821ae/sw.c | 2 -
drivers/platform/chrome/chromeos_laptop.c | 22 +++++++++----------
drivers/platform/x86/intel_scu_ipc.c | 6 ++---
drivers/platform/x86/intel_telemetry_debugfs.c | 2 -
drivers/scsi/esas2r/esas2r_flash.c | 2 -
drivers/scsi/hptiop.c | 6 ++---
drivers/spi/spi-dw-pci.c | 4 +--
drivers/staging/rtl8192e/rtl8192e/rtl_core.c | 2 -
drivers/usb/misc/ezusb.c | 2 -
drivers/video/fbdev/matrox/matroxfb_g450.c | 2 -
lib/crc64_ecma.c | 2 -
sound/pci/ctxfi/ctatc.c | 2 -
sound/pci/hda/patch_ca0132.c | 10 ++++----
sound/pci/riptide/riptide.c | 2 -
40 files changed, 110 insertions(+), 110 deletions(-)


2016-09-11 17:21:20

by Jarkko Sakkinen

[permalink] [raw]
Subject: Re: [PATCH 00/26] constify local structures

On Sun, Sep 11, 2016 at 03:05:42PM +0200, Julia Lawall wrote:
> Constify local structures.
>
> The semantic patch that makes this change is as follows:
> (http://coccinelle.lip6.fr/)

Just my two cents but:

1. You *can* use a static analysis too to find bugs or other issues.
2. However, you should manually do the commits and proper commit
messages to subsystems based on your findings. And I generally think
that if one contributes code one should also at least smoke test changes
somehow.

I don't know if I'm alone with my opinion. I just think that one should
also do the analysis part and not blindly create and submit patches.

Anyway, I'll apply the TPM change at some point. As I said they were
for better. Thanks.

/Jarkko

> // <smpl>
> // The first rule ignores some cases that posed problems
> @r disable optional_qualifier@
> identifier s != {peri_clk_data,threshold_attr,tracer_flags,tracer};
> identifier i != {s5k5baf_cis_rect,smtcfb_fix};
> position p;
> @@
> static struct s i@p = { ... };
>
> @lstruct@
> identifier r.s;
> @@
> struct s { ... };
>
> @used depends on lstruct@
> identifier r.i;
> @@
> i
>
> @bad1@
> expression e;
> identifier r.i;
> assignment operator a;
> @@
> (<+...i...+>) a e
>
> @bad2@
> identifier r.i;
> @@
> &(<+...i...+>)
>
> @bad3@
> identifier r.i;
> declarer d;
> @@
> d(...,<+...i...+>,...);
>
> @bad4@
> identifier r.i;
> type T;
> T[] e;
> identifier f;
> position p;
> @@
>
> f@p(...,
> (
> (<+...i...+>)
> &
> e
> )
> ,...)
>
> @bad4a@
> identifier r.i;
> type T;
> T *e;
> identifier f;
> position p;
> @@
>
> f@p(...,
> (
> (<+...i...+>)
> &
> e
> )
> ,...)
>
> @ok5@
> expression *e;
> identifier r.i;
> position p;
> @@
> e =@p i
>
> @bad5@
> expression *e;
> identifier r.i;
> position p != ok5.p;
> @@
> e =@p (<+...i...+>)
>
> @rr depends on used && !bad1 && !bad2 && !bad3 && !bad4 && !bad4a && !bad5@
> identifier s,r.i;
> position r.p;
> @@
>
> static
> +const
> struct s i@p = { ... };
>
> @depends on used && !bad1 && !bad2 && !bad3 && !bad4 && !bad4a && !bad5
> disable optional_qualifier@
> identifier rr.s,r.i;
> @@
>
> static
> +const
> struct s i;
> // </smpl>
>
> ---
>
> drivers/acpi/acpi_apd.c | 8 +++---
> drivers/char/tpm/tpm-interface.c | 10 ++++----
> drivers/char/tpm/tpm-sysfs.c | 2 -
> drivers/cpufreq/intel_pstate.c | 8 +++---
> drivers/infiniband/hw/i40iw/i40iw_uk.c | 6 ++---
> drivers/media/i2c/tvp514x.c | 2 -
> drivers/media/pci/ddbridge/ddbridge-core.c | 18 +++++++--------
> drivers/media/pci/ngene/ngene-cards.c | 14 ++++++------
> drivers/media/pci/smipcie/smipcie-main.c | 8 +++---
> drivers/misc/sgi-xp/xpc_uv.c | 2 -
> drivers/net/arcnet/com20020-pci.c | 10 ++++----
> drivers/net/can/c_can/c_can_pci.c | 4 +--
> drivers/net/can/sja1000/plx_pci.c | 20 ++++++++---------
> drivers/net/ethernet/mellanox/mlx4/main.c | 4 +--
> drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c | 2 -
> drivers/net/ethernet/renesas/sh_eth.c | 14 ++++++------
> drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c | 2 -
> drivers/net/wireless/ath/dfs_pattern_detector.c | 2 -
> drivers/net/wireless/intel/iwlegacy/3945.c | 4 +--
> drivers/net/wireless/realtek/rtlwifi/rtl8188ee/sw.c | 2 -
> drivers/net/wireless/realtek/rtlwifi/rtl8192ce/sw.c | 2 -
> drivers/net/wireless/realtek/rtlwifi/rtl8192de/sw.c | 2 -
> drivers/net/wireless/realtek/rtlwifi/rtl8192ee/sw.c | 2 -
> drivers/net/wireless/realtek/rtlwifi/rtl8192se/sw.c | 2 -
> drivers/net/wireless/realtek/rtlwifi/rtl8723ae/sw.c | 2 -
> drivers/net/wireless/realtek/rtlwifi/rtl8723be/sw.c | 2 -
> drivers/net/wireless/realtek/rtlwifi/rtl8821ae/sw.c | 2 -
> drivers/platform/chrome/chromeos_laptop.c | 22 +++++++++----------
> drivers/platform/x86/intel_scu_ipc.c | 6 ++---
> drivers/platform/x86/intel_telemetry_debugfs.c | 2 -
> drivers/scsi/esas2r/esas2r_flash.c | 2 -
> drivers/scsi/hptiop.c | 6 ++---
> drivers/spi/spi-dw-pci.c | 4 +--
> drivers/staging/rtl8192e/rtl8192e/rtl_core.c | 2 -
> drivers/usb/misc/ezusb.c | 2 -
> drivers/video/fbdev/matrox/matroxfb_g450.c | 2 -
> lib/crc64_ecma.c | 2 -
> sound/pci/ctxfi/ctatc.c | 2 -
> sound/pci/hda/patch_ca0132.c | 10 ++++----
> sound/pci/riptide/riptide.c | 2 -
> 40 files changed, 110 insertions(+), 110 deletions(-)

2016-09-12 08:54:14

by Julia Lawall

[permalink] [raw]
Subject: Re: [PATCH 00/26] constify local structures



On Sun, 11 Sep 2016, Jarkko Sakkinen wrote:

> On Sun, Sep 11, 2016 at 03:05:42PM +0200, Julia Lawall wrote:
> > Constify local structures.
> >
> > The semantic patch that makes this change is as follows:
> > (http://coccinelle.lip6.fr/)
>
> Just my two cents but:
>
> 1. You *can* use a static analysis too to find bugs or other issues.
> 2. However, you should manually do the commits and proper commit
> messages to subsystems based on your findings. And I generally think
> that if one contributes code one should also at least smoke test changes
> somehow.
>
> I don't know if I'm alone with my opinion. I just think that one should
> also do the analysis part and not blindly create and submit patches.

All of the patches are compile tested. And the individual patches are
submitted to the relevant maintainers. The individual commit messages
give a more detailed explanation of the strategy used to decide that the
structure was constifiable. It seemed redundant to put that in the cover
letter, which will not be committed anyway.

julia

>
> Anyway, I'll apply the TPM change at some point. As I said they were
> for better. Thanks.
>
> /Jarkko
>
> > // <smpl>
> > // The first rule ignores some cases that posed problems
> > @r disable optional_qualifier@
> > identifier s != {peri_clk_data,threshold_attr,tracer_flags,tracer};
> > identifier i != {s5k5baf_cis_rect,smtcfb_fix};
> > position p;
> > @@
> > static struct s i@p = { ... };
> >
> > @lstruct@
> > identifier r.s;
> > @@
> > struct s { ... };
> >
> > @used depends on lstruct@
> > identifier r.i;
> > @@
> > i
> >
> > @bad1@
> > expression e;
> > identifier r.i;
> > assignment operator a;
> > @@
> > (<+...i...+>) a e
> >
> > @bad2@
> > identifier r.i;
> > @@
> > &(<+...i...+>)
> >
> > @bad3@
> > identifier r.i;
> > declarer d;
> > @@
> > d(...,<+...i...+>,...);
> >
> > @bad4@
> > identifier r.i;
> > type T;
> > T[] e;
> > identifier f;
> > position p;
> > @@
> >
> > f@p(...,
> > (
> > (<+...i...+>)
> > &
> > e
> > )
> > ,...)
> >
> > @bad4a@
> > identifier r.i;
> > type T;
> > T *e;
> > identifier f;
> > position p;
> > @@
> >
> > f@p(...,
> > (
> > (<+...i...+>)
> > &
> > e
> > )
> > ,...)
> >
> > @ok5@
> > expression *e;
> > identifier r.i;
> > position p;
> > @@
> > e =@p i
> >
> > @bad5@
> > expression *e;
> > identifier r.i;
> > position p != ok5.p;
> > @@
> > e =@p (<+...i...+>)
> >
> > @rr depends on used && !bad1 && !bad2 && !bad3 && !bad4 && !bad4a && !bad5@
> > identifier s,r.i;
> > position r.p;
> > @@
> >
> > static
> > +const
> > struct s i@p = { ... };
> >
> > @depends on used && !bad1 && !bad2 && !bad3 && !bad4 && !bad4a && !bad5
> > disable optional_qualifier@
> > identifier rr.s,r.i;
> > @@
> >
> > static
> > +const
> > struct s i;
> > // </smpl>
> >
> > ---
> >
> > drivers/acpi/acpi_apd.c | 8 +++---
> > drivers/char/tpm/tpm-interface.c | 10 ++++----
> > drivers/char/tpm/tpm-sysfs.c | 2 -
> > drivers/cpufreq/intel_pstate.c | 8 +++---
> > drivers/infiniband/hw/i40iw/i40iw_uk.c | 6 ++---
> > drivers/media/i2c/tvp514x.c | 2 -
> > drivers/media/pci/ddbridge/ddbridge-core.c | 18 +++++++--------
> > drivers/media/pci/ngene/ngene-cards.c | 14 ++++++------
> > drivers/media/pci/smipcie/smipcie-main.c | 8 +++---
> > drivers/misc/sgi-xp/xpc_uv.c | 2 -
> > drivers/net/arcnet/com20020-pci.c | 10 ++++----
> > drivers/net/can/c_can/c_can_pci.c | 4 +--
> > drivers/net/can/sja1000/plx_pci.c | 20 ++++++++---------
> > drivers/net/ethernet/mellanox/mlx4/main.c | 4 +--
> > drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c | 2 -
> > drivers/net/ethernet/renesas/sh_eth.c | 14 ++++++------
> > drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c | 2 -
> > drivers/net/wireless/ath/dfs_pattern_detector.c | 2 -
> > drivers/net/wireless/intel/iwlegacy/3945.c | 4 +--
> > drivers/net/wireless/realtek/rtlwifi/rtl8188ee/sw.c | 2 -
> > drivers/net/wireless/realtek/rtlwifi/rtl8192ce/sw.c | 2 -
> > drivers/net/wireless/realtek/rtlwifi/rtl8192de/sw.c | 2 -
> > drivers/net/wireless/realtek/rtlwifi/rtl8192ee/sw.c | 2 -
> > drivers/net/wireless/realtek/rtlwifi/rtl8192se/sw.c | 2 -
> > drivers/net/wireless/realtek/rtlwifi/rtl8723ae/sw.c | 2 -
> > drivers/net/wireless/realtek/rtlwifi/rtl8723be/sw.c | 2 -
> > drivers/net/wireless/realtek/rtlwifi/rtl8821ae/sw.c | 2 -
> > drivers/platform/chrome/chromeos_laptop.c | 22 +++++++++----------
> > drivers/platform/x86/intel_scu_ipc.c | 6 ++---
> > drivers/platform/x86/intel_telemetry_debugfs.c | 2 -
> > drivers/scsi/esas2r/esas2r_flash.c | 2 -
> > drivers/scsi/hptiop.c | 6 ++---
> > drivers/spi/spi-dw-pci.c | 4 +--
> > drivers/staging/rtl8192e/rtl8192e/rtl_core.c | 2 -
> > drivers/usb/misc/ezusb.c | 2 -
> > drivers/video/fbdev/matrox/matroxfb_g450.c | 2 -
> > lib/crc64_ecma.c | 2 -
> > sound/pci/ctxfi/ctatc.c | 2 -
> > sound/pci/hda/patch_ca0132.c | 10 ++++----
> > sound/pci/riptide/riptide.c | 2 -
> > 40 files changed, 110 insertions(+), 110 deletions(-)
>

2016-09-12 13:44:47

by Felipe Balbi

[permalink] [raw]
Subject: Re: [PATCH 00/26] constify local structures


Hi,

Jarkko Sakkinen <[email protected]> writes:
> On Mon, Sep 12, 2016 at 10:54:07AM +0200, Julia Lawall wrote:
>>
>>
>> On Sun, 11 Sep 2016, Jarkko Sakkinen wrote:
>>
>> > On Sun, Sep 11, 2016 at 03:05:42PM +0200, Julia Lawall wrote:
>> > > Constify local structures.
>> > >
>> > > The semantic patch that makes this change is as follows:
>> > > (http://coccinelle.lip6.fr/)
>> >
>> > Just my two cents but:
>> >
>> > 1. You *can* use a static analysis too to find bugs or other issues.
>> > 2. However, you should manually do the commits and proper commit
>> > messages to subsystems based on your findings. And I generally think
>> > that if one contributes code one should also at least smoke test changes
>> > somehow.
>> >
>> > I don't know if I'm alone with my opinion. I just think that one should
>> > also do the analysis part and not blindly create and submit patches.
>>
>> All of the patches are compile tested. And the individual patches are
>
> Compile-testing is not testing. If you are not able to test a commit,
> you should explain why.

Dude, Julia has been doing semantic patching for years already and
nobody has raised any concerns so far. There's already an expectation
that Coccinelle *works* and Julia's sematic patches are sound.

Besides, adding 'const' is something that causes virtually no functional
changes to the point that build-testing is really all you need. Any
problems caused by adding 'const' to a definition will be seen by build
errors or warnings.

Really, just stop with the pointless discussion and go read a bit about
Coccinelle and what semantic patches are giving you. The work done by
Julia and her peers are INRIA have measurable benefits.

You're really making a thunderstorm in a glass of water.

--
balbi


Attachments:
signature.asc (800.00 B)

2016-09-12 11:24:59

by Stanislaw Gruszka

[permalink] [raw]
Subject: Re: [PATCH 08/26] iwlegacy: constify local structures

On Sun, Sep 11, 2016 at 03:05:50PM +0200, Julia Lawall wrote:
> For structure types defined in the same file or local header files, find
> top-level static structure declarations that have the following
> properties:
> 1. Never reassigned.
> 2. Address never taken
> 3. Not passed to a top-level macro call
> 4. No pointer or array-typed field passed to a function or stored in a
> variable.
> Declare structures having all of these properties as const.
>
> Done using Coccinelle.
> Based on a suggestion by Joe Perches <[email protected]>.
>
> Signed-off-by: Julia Lawall <[email protected]>

Acked-by: Stanislaw Gruszka <[email protected]>

2016-09-12 13:52:15

by Julia Lawall

[permalink] [raw]
Subject: Re: [PATCH 00/26] constify local structures



On Mon, 12 Sep 2016, Felipe Balbi wrote:

>
> Hi,
>
> Jarkko Sakkinen <[email protected]> writes:
> > On Mon, Sep 12, 2016 at 10:54:07AM +0200, Julia Lawall wrote:
> >>
> >>
> >> On Sun, 11 Sep 2016, Jarkko Sakkinen wrote:
> >>
> >> > On Sun, Sep 11, 2016 at 03:05:42PM +0200, Julia Lawall wrote:
> >> > > Constify local structures.
> >> > >
> >> > > The semantic patch that makes this change is as follows:
> >> > > (http://coccinelle.lip6.fr/)
> >> >
> >> > Just my two cents but:
> >> >
> >> > 1. You *can* use a static analysis too to find bugs or other issues.
> >> > 2. However, you should manually do the commits and proper commit
> >> > messages to subsystems based on your findings. And I generally think
> >> > that if one contributes code one should also at least smoke test changes
> >> > somehow.
> >> >
> >> > I don't know if I'm alone with my opinion. I just think that one should
> >> > also do the analysis part and not blindly create and submit patches.
> >>
> >> All of the patches are compile tested. And the individual patches are
> >
> > Compile-testing is not testing. If you are not able to test a commit,
> > you should explain why.
>
> Dude, Julia has been doing semantic patching for years already and
> nobody has raised any concerns so far. There's already an expectation
> that Coccinelle *works* and Julia's sematic patches are sound.
>
> Besides, adding 'const' is something that causes virtually no functional
> changes to the point that build-testing is really all you need. Any
> problems caused by adding 'const' to a definition will be seen by build
> errors or warnings.
>
> Really, just stop with the pointless discussion and go read a bit about
> Coccinelle and what semantic patches are giving you. The work done by
> Julia and her peers are INRIA have measurable benefits.
>
> You're really making a thunderstorm in a glass of water.

Thanks for the defense, but since a lot of these patches torned out to be
wrong, due to an incorrect parse by Coccinelle, combined with an
unpleasantly lax compiler, Jarkko does have a point that I should have
looked at the patches more carefully. In any case, I have written to the
maintainers relevant to the patches that turned out to be incorrect.

julia

2016-09-11 13:26:30

by Julia Lawall

[permalink] [raw]
Subject: [PATCH 21/26] rtlwifi: rtl818x: constify local structures

For structure types defined in the same file or local header files, find
top-level static structure declarations that have the following
properties:
1. Never reassigned.
2. Address never taken
3. Not passed to a top-level macro call
4. No pointer or array-typed field passed to a function or stored in a
variable.
Declare structures having all of these properties as const.

Done using Coccinelle.
Based on a suggestion by Joe Perches <[email protected]>.

Signed-off-by: Julia Lawall <[email protected]>

---
The semantic patch seems too long for a commit log, but is in the cover
letter.

drivers/net/wireless/realtek/rtlwifi/rtl8188ee/sw.c | 2 +-
drivers/net/wireless/realtek/rtlwifi/rtl8192ce/sw.c | 2 +-
drivers/net/wireless/realtek/rtlwifi/rtl8192de/sw.c | 2 +-
drivers/net/wireless/realtek/rtlwifi/rtl8192ee/sw.c | 2 +-
drivers/net/wireless/realtek/rtlwifi/rtl8192se/sw.c | 2 +-
drivers/net/wireless/realtek/rtlwifi/rtl8723ae/sw.c | 2 +-
drivers/net/wireless/realtek/rtlwifi/rtl8723be/sw.c | 2 +-
drivers/net/wireless/realtek/rtlwifi/rtl8821ae/sw.c | 2 +-
8 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/sw.c b/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/sw.c
index 47e32cb..e7b11b4 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/sw.c
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/sw.c
@@ -280,7 +280,7 @@ static struct rtl_mod_params rtl88ee_mod_params = {
.debug = DBG_EMERG,
};

-static struct rtl_hal_cfg rtl88ee_hal_cfg = {
+static const struct rtl_hal_cfg rtl88ee_hal_cfg = {
.bar_id = 2,
.write_readback = true,
.name = "rtl88e_pci",
diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8192ce/sw.c b/drivers/net/wireless/realtek/rtlwifi/rtl8192ce/sw.c
index 4780bdc..87aa209 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8192ce/sw.c
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8192ce/sw.c
@@ -258,7 +258,7 @@ static struct rtl_mod_params rtl92ce_mod_params = {
.debug = DBG_EMERG,
};

-static struct rtl_hal_cfg rtl92ce_hal_cfg = {
+static const struct rtl_hal_cfg rtl92ce_hal_cfg = {
.bar_id = 2,
.write_readback = true,
.name = "rtl92c_pci",
diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8192de/sw.c b/drivers/net/wireless/realtek/rtlwifi/rtl8192de/sw.c
index c6e09a1..0538a4d 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8192de/sw.c
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8192de/sw.c
@@ -262,7 +262,7 @@ static struct rtl_mod_params rtl92de_mod_params = {
.debug = DBG_EMERG,
};

-static struct rtl_hal_cfg rtl92de_hal_cfg = {
+static const struct rtl_hal_cfg rtl92de_hal_cfg = {
.bar_id = 2,
.write_readback = true,
.name = "rtl8192de",
diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/sw.c b/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/sw.c
index c31c6bf..ac299cb 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/sw.c
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/sw.c
@@ -262,7 +262,7 @@ static struct rtl_mod_params rtl92ee_mod_params = {
.debug = DBG_EMERG,
};

-static struct rtl_hal_cfg rtl92ee_hal_cfg = {
+static const struct rtl_hal_cfg rtl92ee_hal_cfg = {
.bar_id = 2,
.write_readback = true,
.name = "rtl92ee_pci",
diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8192se/sw.c b/drivers/net/wireless/realtek/rtlwifi/rtl8192se/sw.c
index 31baca41..5e8e02d 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8192se/sw.c
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8192se/sw.c
@@ -306,7 +306,7 @@ static struct rtl_mod_params rtl92se_mod_params = {

/* Because memory R/W bursting will cause system hang/crash
* for 92se, so we don't read back after every write action */
-static struct rtl_hal_cfg rtl92se_hal_cfg = {
+static const struct rtl_hal_cfg rtl92se_hal_cfg = {
.bar_id = 1,
.write_readback = false,
.name = "rtl92s_pci",
diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8723ae/sw.c b/drivers/net/wireless/realtek/rtlwifi/rtl8723ae/sw.c
index ff49a8c..89c828a 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8723ae/sw.c
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8723ae/sw.c
@@ -276,7 +276,7 @@ static struct rtl_mod_params rtl8723e_mod_params = {
.disable_watchdog = false,
};

-static struct rtl_hal_cfg rtl8723e_hal_cfg = {
+static const struct rtl_hal_cfg rtl8723e_hal_cfg = {
.bar_id = 2,
.write_readback = true,
.name = "rtl8723e_pci",
diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8723be/sw.c b/drivers/net/wireless/realtek/rtlwifi/rtl8723be/sw.c
index 2101793..20b53f0 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8723be/sw.c
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8723be/sw.c
@@ -276,7 +276,7 @@ static struct rtl_mod_params rtl8723be_mod_params = {
.ant_sel = 0,
};

-static struct rtl_hal_cfg rtl8723be_hal_cfg = {
+static const struct rtl_hal_cfg rtl8723be_hal_cfg = {
.bar_id = 2,
.write_readback = true,
.name = "rtl8723be_pci",
diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/sw.c b/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/sw.c
index 4159f9b..22f687b1 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/sw.c
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/sw.c
@@ -316,7 +316,7 @@ static struct rtl_mod_params rtl8821ae_mod_params = {
.disable_watchdog = 0,
};

-static struct rtl_hal_cfg rtl8821ae_hal_cfg = {
+static const struct rtl_hal_cfg rtl8821ae_hal_cfg = {
.bar_id = 2,
.write_readback = true,
.name = "rtl8821ae_pci",

2016-09-11 19:11:41

by Julia Lawall

[permalink] [raw]
Subject: Re: [PATCH 00/26] constify local structures


On Sun, 11 Sep 2016, Joe Perches wrote:

> On Sun, 2016-09-11 at 15:05 +0200, Julia Lawall wrote:
> > Constify local structures.
>
> Thanks Julia.
>
> A few suggestions & questions:
>
> Perhaps the script should go into scripts/coccinelle/
> so that future cases could be caught by the robot
> and commit message referenced by the patch instances.

OK.

> Can you please compile the files modified using the
> appropriate defconfig/allyesconfig and show the

I currently send patches for this issue only for files that compile using
the x86 allyesconfig.

> movement from data to const by using
> $ size <object>.new/old
> and include that in the changelogs (maybe next time)?

OK, thanks for the suggestion.

> Is it possible for a rule to trace the instances where
> an address of a struct or struct member is taken by
> locally defined and declared function call where the
> callee does not modify any dereferenced object?
>
> ie:
>
> struct foo {
> int bar;
> char *baz;
> };
>
> struct foo qux[] = {
> { 1, "description 1" },
> { 2, "dewcription 2" },
> [ n, "etc" ]...,
> };
>
> void message(struct foo *msg)
> {
> printk("%d %s\n", msg->bar, msg->baz);
> }
>
> where some code uses
>
> message(qux[index]);
>
> So could a coccinelle script change:
>
> struct foo qux[] = { to const struct foo quz[] = {
>
> and
>
> void message(struct foo *msg) to void message(const struct foo *msg)

Yes, this could be possible too.

Thanks for the feedback.

julia

2016-09-11 13:26:22

by Julia Lawall

[permalink] [raw]
Subject: [PATCH 06/26] ath: constify local structures

For structure types defined in the same file or local header files, find
top-level static structure declarations that have the following
properties:
1. Never reassigned.
2. Address never taken
3. Not passed to a top-level macro call
4. No pointer or array-typed field passed to a function or stored in a
variable.
Declare structures having all of these properties as const.

Done using Coccinelle.
Based on a suggestion by Joe Perches <[email protected]>.

Signed-off-by: Julia Lawall <[email protected]>

---
The semantic patch seems too long for a commit log, but is in the cover
letter.

drivers/net/wireless/ath/dfs_pattern_detector.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/wireless/ath/dfs_pattern_detector.c b/drivers/net/wireless/ath/dfs_pattern_detector.c
index 2f8136d..4100ffd 100644
--- a/drivers/net/wireless/ath/dfs_pattern_detector.c
+++ b/drivers/net/wireless/ath/dfs_pattern_detector.c
@@ -338,7 +338,7 @@ static bool dpd_set_domain(struct dfs_pattern_detector *dpd,
return true;
}

-static struct dfs_pattern_detector default_dpd = {
+static const struct dfs_pattern_detector default_dpd = {
.exit = dpd_exit,
.set_dfs_domain = dpd_set_domain,
.add_pulse = dpd_add_pulse,

2016-09-11 17:56:33

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH 00/26] constify local structures

On Sun, 2016-09-11 at 15:05 +0200, Julia Lawall wrote:
> Constify local structures.

Thanks Julia.

A few suggestions & questions:

Perhaps the script should go into scripts/coccinelle/
so that future cases could be caught by the robot
and commit message referenced by the patch instances.

Can you please compile the files modified using the
appropriate defconfig/allyesconfig and show the
movement from data to const by using
$ size <object>.new/old
and include that in the changelogs (maybe next time)?

Is it possible for a rule to trace the instances where
an address of a struct or struct member is taken by
locally defined and declared function call where the
callee does not modify any dereferenced object?

ie:

struct foo {
int bar;
char *baz;
};

struct foo qux[] = {
{ 1, "description 1" },
{ 2, "dewcription 2" },
[ n, "etc" ]...,
};

void message(struct foo *msg)
{
printk("%d %s\n", msg->bar, msg->baz);
}

where some code uses

message(qux[index]);

So could a coccinelle script change:

struct foo qux[] = { to const struct foo quz[] = {

and

void message(struct foo *msg) to void message(const struct foo *msg)

2016-09-12 20:14:56

by Jarkko Sakkinen

[permalink] [raw]
Subject: Re: [PATCH 00/26] constify local structures

On Mon, Sep 12, 2016 at 04:43:58PM +0300, Felipe Balbi wrote:
>
> Hi,
>
> Jarkko Sakkinen <[email protected]> writes:
> > On Mon, Sep 12, 2016 at 10:54:07AM +0200, Julia Lawall wrote:
> >>
> >>
> >> On Sun, 11 Sep 2016, Jarkko Sakkinen wrote:
> >>
> >> > On Sun, Sep 11, 2016 at 03:05:42PM +0200, Julia Lawall wrote:
> >> > > Constify local structures.
> >> > >
> >> > > The semantic patch that makes this change is as follows:
> >> > > (http://coccinelle.lip6.fr/)
> >> >
> >> > Just my two cents but:
> >> >
> >> > 1. You *can* use a static analysis too to find bugs or other issues.
> >> > 2. However, you should manually do the commits and proper commit
> >> > messages to subsystems based on your findings. And I generally think
> >> > that if one contributes code one should also at least smoke test changes
> >> > somehow.
> >> >
> >> > I don't know if I'm alone with my opinion. I just think that one should
> >> > also do the analysis part and not blindly create and submit patches.
> >>
> >> All of the patches are compile tested. And the individual patches are
> >
> > Compile-testing is not testing. If you are not able to test a commit,
> > you should explain why.
>
> Dude, Julia has been doing semantic patching for years already and
> nobody has raised any concerns so far. There's already an expectation
> that Coccinelle *works* and Julia's sematic patches are sound.
>
> Besides, adding 'const' is something that causes virtually no functional
> changes to the point that build-testing is really all you need. Any
> problems caused by adding 'const' to a definition will be seen by build
> errors or warnings.
>
> Really, just stop with the pointless discussion and go read a bit about
> Coccinelle and what semantic patches are giving you. The work done by
> Julia and her peers are INRIA have measurable benefits.
>
> You're really making a thunderstorm in a glass of water.

Hmm... I've been using coccinelle in cyclic basis for some time now.
My comment was oversized but I didn't mean it to be impolite or attack
of any kind for that matter.

> --
> balbi

/Jarkko

2016-09-12 18:50:31

by Jarkko Sakkinen

[permalink] [raw]
Subject: Re: [PATCH 00/26] constify local structures

On Mon, Sep 12, 2016 at 03:52:08PM +0200, Julia Lawall wrote:
>
>
> On Mon, 12 Sep 2016, Felipe Balbi wrote:
>
> >
> > Hi,
> >
> > Jarkko Sakkinen <[email protected]> writes:
> > > On Mon, Sep 12, 2016 at 10:54:07AM +0200, Julia Lawall wrote:
> > >>
> > >>
> > >> On Sun, 11 Sep 2016, Jarkko Sakkinen wrote:
> > >>
> > >> > On Sun, Sep 11, 2016 at 03:05:42PM +0200, Julia Lawall wrote:
> > >> > > Constify local structures.
> > >> > >
> > >> > > The semantic patch that makes this change is as follows:
> > >> > > (http://coccinelle.lip6.fr/)
> > >> >
> > >> > Just my two cents but:
> > >> >
> > >> > 1. You *can* use a static analysis too to find bugs or other issues.
> > >> > 2. However, you should manually do the commits and proper commit
> > >> > messages to subsystems based on your findings. And I generally think
> > >> > that if one contributes code one should also at least smoke test changes
> > >> > somehow.
> > >> >
> > >> > I don't know if I'm alone with my opinion. I just think that one should
> > >> > also do the analysis part and not blindly create and submit patches.
> > >>
> > >> All of the patches are compile tested. And the individual patches are
> > >
> > > Compile-testing is not testing. If you are not able to test a commit,
> > > you should explain why.
> >
> > Dude, Julia has been doing semantic patching for years already and
> > nobody has raised any concerns so far. There's already an expectation
> > that Coccinelle *works* and Julia's sematic patches are sound.
> >
> > Besides, adding 'const' is something that causes virtually no functional
> > changes to the point that build-testing is really all you need. Any
> > problems caused by adding 'const' to a definition will be seen by build
> > errors or warnings.
> >
> > Really, just stop with the pointless discussion and go read a bit about
> > Coccinelle and what semantic patches are giving you. The work done by
> > Julia and her peers are INRIA have measurable benefits.
> >
> > You're really making a thunderstorm in a glass of water.
>
> Thanks for the defense, but since a lot of these patches torned out to be
> wrong, due to an incorrect parse by Coccinelle, combined with an
> unpleasantly lax compiler, Jarkko does have a point that I should have
> looked at the patches more carefully. In any case, I have written to the
> maintainers relevant to the patches that turned out to be incorrect.

Exactly. I'm not excepting that every commit would require extensive
analysis but it would be good to quickly at least skim through commits
and see if they make sense (or ask if unsure) :)

And I'm fine with compile testing if it is mentioned in the commit msg.

> julia

/Jarkko

2016-09-12 13:57:42

by Geert Uytterhoeven

[permalink] [raw]
Subject: Re: [PATCH 00/26] constify local structures

On Mon, Sep 12, 2016 at 3:43 PM, Felipe Balbi
<[email protected]> wrote:
> Jarkko Sakkinen <[email protected]> writes:
>> On Mon, Sep 12, 2016 at 10:54:07AM +0200, Julia Lawall wrote:
>>> On Sun, 11 Sep 2016, Jarkko Sakkinen wrote:
>>> > On Sun, Sep 11, 2016 at 03:05:42PM +0200, Julia Lawall wrote:
>>> > > Constify local structures.
>>> > >
>>> > > The semantic patch that makes this change is as follows:
>>> > > (http://coccinelle.lip6.fr/)
>>> >
>>> > Just my two cents but:
>>> >
>>> > 1. You *can* use a static analysis too to find bugs or other issues.
>>> > 2. However, you should manually do the commits and proper commit
>>> > messages to subsystems based on your findings. And I generally think
>>> > that if one contributes code one should also at least smoke test changes
>>> > somehow.
>>> >
>>> > I don't know if I'm alone with my opinion. I just think that one should
>>> > also do the analysis part and not blindly create and submit patches.
>>>
>>> All of the patches are compile tested. And the individual patches are
>>
>> Compile-testing is not testing. If you are not able to test a commit,
>> you should explain why.
>
> Dude, Julia has been doing semantic patching for years already and
> nobody has raised any concerns so far. There's already an expectation
> that Coccinelle *works* and Julia's sematic patches are sound.

+1

> Besides, adding 'const' is something that causes virtually no functional
> changes to the point that build-testing is really all you need. Any
> problems caused by adding 'const' to a definition will be seen by build
> errors or warnings.

Unfortunately in this particular case they could lead to failures that can only
be detected at runtime, when failing o write to a read-only piece of memory,
due to the casting away of the constness of the pointers later.
Fortunately this was detected during code review (doh...).

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

2016-09-12 13:24:03

by Julia Lawall

[permalink] [raw]
Subject: Re: [PATCH 00/26] constify local structures



On Mon, 12 Sep 2016, Jarkko Sakkinen wrote:

> On Mon, Sep 12, 2016 at 10:54:07AM +0200, Julia Lawall wrote:
> >
> >
> > On Sun, 11 Sep 2016, Jarkko Sakkinen wrote:
> >
> > > On Sun, Sep 11, 2016 at 03:05:42PM +0200, Julia Lawall wrote:
> > > > Constify local structures.
> > > >
> > > > The semantic patch that makes this change is as follows:
> > > > (http://coccinelle.lip6.fr/)
> > >
> > > Just my two cents but:
> > >
> > > 1. You *can* use a static analysis too to find bugs or other issues.
> > > 2. However, you should manually do the commits and proper commit
> > > messages to subsystems based on your findings. And I generally think
> > > that if one contributes code one should also at least smoke test changes
> > > somehow.
> > >
> > > I don't know if I'm alone with my opinion. I just think that one should
> > > also do the analysis part and not blindly create and submit patches.
> >
> > All of the patches are compile tested. And the individual patches are
>
> Compile-testing is not testing. If you are not able to test a commit,
> you should explain why.
>
> > submitted to the relevant maintainers. The individual commit messages
> > give a more detailed explanation of the strategy used to decide that the
> > structure was constifiable. It seemed redundant to put that in the cover
> > letter, which will not be committed anyway.
>
> I don't mean to be harsh but I do not care about your thought process
> *that much* when I review a commit (sometimes it might make sense to
> explain that but it depends on the context).
>
> I mostly only care why a particular change makes sense for this
> particular subsystem. The report given by a static analysis tool can
> be a starting point for making a commit but it's not sufficient.
> Based on the report you should look subsystems as individuals.

OK, thanks for the feedback.

julia

2016-09-12 21:11:55

by Julia Lawall

[permalink] [raw]
Subject: Re: [PATCH 00/26] constify local structures



On Mon, 12 Sep 2016, Jarkko Sakkinen wrote:

> On Mon, Sep 12, 2016 at 04:43:58PM +0300, Felipe Balbi wrote:
> >
> > Hi,
> >
> > Jarkko Sakkinen <[email protected]> writes:
> > > On Mon, Sep 12, 2016 at 10:54:07AM +0200, Julia Lawall wrote:
> > >>
> > >>
> > >> On Sun, 11 Sep 2016, Jarkko Sakkinen wrote:
> > >>
> > >> > On Sun, Sep 11, 2016 at 03:05:42PM +0200, Julia Lawall wrote:
> > >> > > Constify local structures.
> > >> > >
> > >> > > The semantic patch that makes this change is as follows:
> > >> > > (http://coccinelle.lip6.fr/)
> > >> >
> > >> > Just my two cents but:
> > >> >
> > >> > 1. You *can* use a static analysis too to find bugs or other issues.
> > >> > 2. However, you should manually do the commits and proper commit
> > >> > messages to subsystems based on your findings. And I generally think
> > >> > that if one contributes code one should also at least smoke test changes
> > >> > somehow.
> > >> >
> > >> > I don't know if I'm alone with my opinion. I just think that one should
> > >> > also do the analysis part and not blindly create and submit patches.
> > >>
> > >> All of the patches are compile tested. And the individual patches are
> > >
> > > Compile-testing is not testing. If you are not able to test a commit,
> > > you should explain why.
> >
> > Dude, Julia has been doing semantic patching for years already and
> > nobody has raised any concerns so far. There's already an expectation
> > that Coccinelle *works* and Julia's sematic patches are sound.
> >
> > Besides, adding 'const' is something that causes virtually no functional
> > changes to the point that build-testing is really all you need. Any
> > problems caused by adding 'const' to a definition will be seen by build
> > errors or warnings.
> >
> > Really, just stop with the pointless discussion and go read a bit about
> > Coccinelle and what semantic patches are giving you. The work done by
> > Julia and her peers are INRIA have measurable benefits.
> >
> > You're really making a thunderstorm in a glass of water.
>
> Hmm... I've been using coccinelle in cyclic basis for some time now.
> My comment was oversized but I didn't mean it to be impolite or attack
> of any kind for that matter.

No problem :) Thanks for the feedback.

julia

2016-09-11 13:26:23

by Julia Lawall

[permalink] [raw]
Subject: [PATCH 08/26] iwlegacy: constify local structures

For structure types defined in the same file or local header files, find
top-level static structure declarations that have the following
properties:
1. Never reassigned.
2. Address never taken
3. Not passed to a top-level macro call
4. No pointer or array-typed field passed to a function or stored in a
variable.
Declare structures having all of these properties as const.

Done using Coccinelle.
Based on a suggestion by Joe Perches <[email protected]>.

Signed-off-by: Julia Lawall <[email protected]>

---
The semantic patch seems too long for a commit log, but is in the cover
letter.

drivers/net/wireless/intel/iwlegacy/3945.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/wireless/intel/iwlegacy/3945.c b/drivers/net/wireless/intel/iwlegacy/3945.c
index 209dc99..4db327a 100644
--- a/drivers/net/wireless/intel/iwlegacy/3945.c
+++ b/drivers/net/wireless/intel/iwlegacy/3945.c
@@ -2671,7 +2671,7 @@ const struct il_ops il3945_ops = {
.send_led_cmd = il3945_send_led_cmd,
};

-static struct il_cfg il3945_bg_cfg = {
+static const struct il_cfg il3945_bg_cfg = {
.name = "3945BG",
.fw_name_pre = IL3945_FW_PRE,
.ucode_api_max = IL3945_UCODE_API_MAX,
@@ -2700,7 +2700,7 @@ static struct il_cfg il3945_bg_cfg = {
},
};

-static struct il_cfg il3945_abg_cfg = {
+static const struct il_cfg il3945_abg_cfg = {
.name = "3945ABG",
.fw_name_pre = IL3945_FW_PRE,
.ucode_api_max = IL3945_UCODE_API_MAX,

2016-09-12 13:16:38

by Jarkko Sakkinen

[permalink] [raw]
Subject: Re: [PATCH 00/26] constify local structures

On Mon, Sep 12, 2016 at 10:54:07AM +0200, Julia Lawall wrote:
>
>
> On Sun, 11 Sep 2016, Jarkko Sakkinen wrote:
>
> > On Sun, Sep 11, 2016 at 03:05:42PM +0200, Julia Lawall wrote:
> > > Constify local structures.
> > >
> > > The semantic patch that makes this change is as follows:
> > > (http://coccinelle.lip6.fr/)
> >
> > Just my two cents but:
> >
> > 1. You *can* use a static analysis too to find bugs or other issues.
> > 2. However, you should manually do the commits and proper commit
> > messages to subsystems based on your findings. And I generally think
> > that if one contributes code one should also at least smoke test changes
> > somehow.
> >
> > I don't know if I'm alone with my opinion. I just think that one should
> > also do the analysis part and not blindly create and submit patches.
>
> All of the patches are compile tested. And the individual patches are

Compile-testing is not testing. If you are not able to test a commit,
you should explain why.

> submitted to the relevant maintainers. The individual commit messages
> give a more detailed explanation of the strategy used to decide that the
> structure was constifiable. It seemed redundant to put that in the cover
> letter, which will not be committed anyway.

I don't mean to be harsh but I do not care about your thought process
*that much* when I review a commit (sometimes it might make sense to
explain that but it depends on the context).

I mostly only care why a particular change makes sense for this
particular subsystem. The report given by a static analysis tool can
be a starting point for making a commit but it's not sufficient.
Based on the report you should look subsystems as individuals.

> julia

/Jarkko

2016-09-14 17:02:07

by Kalle Valo

[permalink] [raw]
Subject: Re: [06/26] ath: constify local structures

Julia Lawall <[email protected]> wrote:
> For structure types defined in the same file or local header files, find
> top-level static structure declarations that have the following
> properties:
> 1. Never reassigned.
> 2. Address never taken
> 3. Not passed to a top-level macro call
> 4. No pointer or array-typed field passed to a function or stored in a
> variable.
> Declare structures having all of these properties as const.
>
> Done using Coccinelle.
> Based on a suggestion by Joe Perches <[email protected]>.
>
> Signed-off-by: Julia Lawall <[email protected]>

Thanks, 3 patches applied to wireless-drivers-next.git:

8136fd58ad60 ath: constify local structures
1dc80798a8ca iwlegacy: constify local structures
d86e64768859 rtlwifi: rtl818x: constify local structures

--
Sent by pwcli
https://patchwork.kernel.org/patch/9325363/