Skip to contentSkip to conversation

net: unix: make some variables constant

PATCH In review Changli Gao 3 participants 4 messages Oct 19, 2010

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: unix: make some variables constant

And since ctl_table.data is initialized later, we don't need to initialize the data member of the template variable unix_table.

---
 net/unix/sysctl_net_unix.c |    5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
net/unix/sysctl_net_unix.c +2 -3
index 397cffe..1114ccc 100644
@@ -15,10 +15,9 @@
 
 #include <net/af_unix.h>
 
-static ctl_table unix_table[] = {
+const static ctl_table unix_table[] = {
 	{
 		.procname	= "max_dgram_qlen",
-		.data		= &init_net.unx.sysctl_max_dgram_qlen,
 		.maxlen		= sizeof(int),
 		.mode		= 0644,
 		.proc_handler	= proc_dointvec
@@ -26,7 +25,7 @@ static ctl_table unix_table[] = {
 	{ }
 };
 
-static struct ctl_path unix_path[] = {
+const static struct ctl_path unix_path[] = {
 	{ .procname = "net", },
 	{ .procname = "unix", },
 	{ },
#1 lore raw
Quoted 3 lines · Changli Gao

And since ctl_table.data is initialized later, we don't need to initialize the data member of the template variable unix_table.

The init cost is nothing, since its a data blob that must be there anyway.

We could even avoid the kmemdup() if CONFIG_NET_NS is not set

#2 lore raw
Quoted 7 lines · Eric Dumazet
Quoted 3 lines · Changli Gao

And since ctl_table.data is initialized later, we don't need to initialize the data member of the template variable unix_table.

The init cost is nothing, since its a data blob that must be there anyway.

Yes. I have tried to avoid global variable unix_table and unix_path, then I got a bigger kernel image, so I gave it up.

Quoted 4 lines

We could even avoid the kmemdup() if CONFIG_NET_NS is not set

It is a good idea. We can check if the NS is init_net before kmalloc and kfree.

I'll send a update patch later. Thanks.

Signature · 2 lines
Regards,
Changli Gao([email protected])
#3 lore raw
In reply to Changli Gao
Quoted 12 lines · On Tue, 19 Oct 2010 13:24:02 +0800 Changli Gao <[email protected]> wrote:

And since ctl_table.data is initialized later, we don't need to initialize the data member of the template variable unix_table.

---
 net/unix/sysctl_net_unix.c |    5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
net/unix/sysctl_net_unix.c +0 -0
index 397cffe..1114ccc 100644

net/unix/sysctl_net_unix.c line 18

Quoted 5 lines
net/unix/sysctl_net_unix.c +1 -1
@@ -15,10 +15,9 @@
 
 #include <net/af_unix.h>
 
-static ctl_table unix_table[] = {
+const static ctl_table unix_table[] = {

Typical convention is "static const" rather than "const static"

git grep 'const static' | wc -l  => 5
git grep 'static const' | wc -l  => 18589