public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] iptables: Constify option struct
@ 2017-09-27 11:44 Harsha Sharma
  2017-10-04 14:08 ` Pablo Neira Ayuso
  0 siblings, 1 reply; 2+ messages in thread
From: Harsha Sharma @ 2017-09-27 11:44 UTC (permalink / raw)
  To: pablo; +Cc: netfilter-devel, linux-kernel, outreachy-kernel, Harsha Sharma

The struct of type option is only used to initialise a field inside
the xtables_globals struct and is not modified anywhere.
Done using following coccinelle semantic patch

@r1 disable optional_qualifier@
identifier s,i;
position p;
@@

static struct option i@p[] ={...};

@ok1@
identifier r1.i;
expression e;
position p;
@@
e = i@p

@bad@
position p != {r1.p,ok1.p};
identifier r1.i;
@@
e@i@p

@depends on !bad disable optional_qualifier@
identifier r1.i;
@@
static
+const
struct option i[] = { ... };

Signed-off-by: Harsha Sharma <harshasharmaiitr@gmail.com>
---
 iptables/ip6tables.c  | 2 +-
 iptables/iptables.c   | 2 +-
 iptables/xtables-eb.c | 2 +-
 iptables/xtables.c    | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/iptables/ip6tables.c b/iptables/ip6tables.c
index 49bd006..0f6fa31 100644
--- a/iptables/ip6tables.c
+++ b/iptables/ip6tables.c
@@ -78,7 +78,7 @@ static const char optflags[]
 
 static const char unsupported_rev[] = " [unsupported revision]";
 
-static struct option original_opts[] = {
+static const struct option original_opts[] = {
 	{.name = "append",        .has_arg = 1, .val = 'A'},
 	{.name = "delete",        .has_arg = 1, .val = 'D'},
 	{.name = "check" ,        .has_arg = 1, .val = 'C'},
diff --git a/iptables/iptables.c b/iptables/iptables.c
index 69d19fe..e930fe2 100644
--- a/iptables/iptables.c
+++ b/iptables/iptables.c
@@ -75,7 +75,7 @@ static const char optflags[]
 
 static const char unsupported_rev[] = " [unsupported revision]";
 
-static struct option original_opts[] = {
+static const struct option original_opts[] = {
 	{.name = "append",        .has_arg = 1, .val = 'A'},
 	{.name = "delete",        .has_arg = 1, .val = 'D'},
 	{.name = "check",         .has_arg = 1, .val = 'C'},
diff --git a/iptables/xtables-eb.c b/iptables/xtables-eb.c
index c8b5d4f..60ec935 100644
--- a/iptables/xtables-eb.c
+++ b/iptables/xtables-eb.c
@@ -247,7 +247,7 @@ static int get_current_chain(const char *chain)
 
 /* Default command line options. Do not mess around with the already
  * assigned numbers unless you know what you are doing */
-static struct option ebt_original_options[] =
+static const struct option ebt_original_options[] =
 {
 	{ "append"         , required_argument, 0, 'A' },
 	{ "insert"         , required_argument, 0, 'I' },
diff --git a/iptables/xtables.c b/iptables/xtables.c
index ac11325..aebe7d7 100644
--- a/iptables/xtables.c
+++ b/iptables/xtables.c
@@ -59,7 +59,7 @@ static const char cmdflags[] = { 'I', 'D', 'D', 'R', 'A', 'L', 'F', 'Z',
 static const char optflags[]
 = { 'n', 's', 'd', 'p', 'j', 'v', 'x', 'i', 'o', '0', 'c', 'f'};
 
-static struct option original_opts[] = {
+static const struct option original_opts[] = {
 	{.name = "append",	  .has_arg = 1, .val = 'A'},
 	{.name = "delete",	  .has_arg = 1, .val = 'D'},
 	{.name = "check",	  .has_arg = 1, .val = 'C'},
-- 
1.9.1

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

* Re: [PATCH] iptables: Constify option struct
  2017-09-27 11:44 [PATCH] iptables: Constify option struct Harsha Sharma
@ 2017-10-04 14:08 ` Pablo Neira Ayuso
  0 siblings, 0 replies; 2+ messages in thread
From: Pablo Neira Ayuso @ 2017-10-04 14:08 UTC (permalink / raw)
  To: Harsha Sharma; +Cc: netfilter-devel, linux-kernel, outreachy-kernel

On Wed, Sep 27, 2017 at 05:14:52PM +0530, Harsha Sharma wrote:
> The struct of type option is only used to initialise a field inside
> the xtables_globals struct and is not modified anywhere.
> Done using following coccinelle semantic patch

Applied, thanks.

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

end of thread, other threads:[~2017-10-04 14:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-09-27 11:44 [PATCH] iptables: Constify option struct Harsha Sharma
2017-10-04 14:08 ` Pablo Neira Ayuso

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