Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 73cb88ec authored by Arjan van de Ven's avatar Arjan van de Ven Committed by David S. Miller
Browse files

net: make the tcp and udp file_operations for the /proc stuff const



the tcp and udp code creates a set of struct file_operations at runtime
while it can also be done at compile time, with the added benefit of then
having these file operations be const.

the trickiest part was to get the "THIS_MODULE" reference right; the naive
method of declaring a struct in the place of registration would not work
for this reason.

Signed-off-by: default avatarArjan van de Ven <arjan@linux.intel.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 98f41f69
Loading
Loading
Loading
Loading
+6 −4
Original line number Original line Diff line number Diff line
@@ -1403,10 +1403,12 @@ enum tcp_seq_states {
	TCP_SEQ_STATE_TIME_WAIT,
	TCP_SEQ_STATE_TIME_WAIT,
};
};


int tcp_seq_open(struct inode *inode, struct file *file);

struct tcp_seq_afinfo {
struct tcp_seq_afinfo {
	char				*name;
	char				*name;
	sa_family_t			family;
	sa_family_t			family;
	struct file_operations	seq_fops;
	const struct file_operations	*seq_fops;
	struct seq_operations		seq_ops;
	struct seq_operations		seq_ops;
};
};


+7 −5
Original line number Original line Diff line number Diff line
@@ -230,11 +230,13 @@ extern struct sock *udp6_lib_lookup(struct net *net, const struct in6_addr *sadd
#endif
#endif


/* /proc */
/* /proc */
int udp_seq_open(struct inode *inode, struct file *file);

struct udp_seq_afinfo {
struct udp_seq_afinfo {
	char				*name;
	char				*name;
	sa_family_t			family;
	sa_family_t			family;
	struct udp_table		*udp_table;
	struct udp_table		*udp_table;
	struct file_operations	seq_fops;
	const struct file_operations	*seq_fops;
	struct seq_operations		seq_ops;
	struct seq_operations		seq_ops;
};
};


+12 −10
Original line number Original line Diff line number Diff line
@@ -2339,7 +2339,7 @@ static void tcp_seq_stop(struct seq_file *seq, void *v)
	}
	}
}
}


static int tcp_seq_open(struct inode *inode, struct file *file)
int tcp_seq_open(struct inode *inode, struct file *file)
{
{
	struct tcp_seq_afinfo *afinfo = PDE(inode)->data;
	struct tcp_seq_afinfo *afinfo = PDE(inode)->data;
	struct tcp_iter_state *s;
	struct tcp_iter_state *s;
@@ -2355,23 +2355,19 @@ static int tcp_seq_open(struct inode *inode, struct file *file)
	s->last_pos 		= 0;
	s->last_pos 		= 0;
	return 0;
	return 0;
}
}
EXPORT_SYMBOL(tcp_seq_open);


int tcp_proc_register(struct net *net, struct tcp_seq_afinfo *afinfo)
int tcp_proc_register(struct net *net, struct tcp_seq_afinfo *afinfo)
{
{
	int rc = 0;
	int rc = 0;
	struct proc_dir_entry *p;
	struct proc_dir_entry *p;


	afinfo->seq_fops.open		= tcp_seq_open;
	afinfo->seq_fops.read		= seq_read;
	afinfo->seq_fops.llseek		= seq_lseek;
	afinfo->seq_fops.release	= seq_release_net;

	afinfo->seq_ops.start		= tcp_seq_start;
	afinfo->seq_ops.start		= tcp_seq_start;
	afinfo->seq_ops.next		= tcp_seq_next;
	afinfo->seq_ops.next		= tcp_seq_next;
	afinfo->seq_ops.stop		= tcp_seq_stop;
	afinfo->seq_ops.stop		= tcp_seq_stop;


	p = proc_create_data(afinfo->name, S_IRUGO, net->proc_net,
	p = proc_create_data(afinfo->name, S_IRUGO, net->proc_net,
			     &afinfo->seq_fops, afinfo);
			     afinfo->seq_fops, afinfo);
	if (!p)
	if (!p)
		rc = -ENOMEM;
		rc = -ENOMEM;
	return rc;
	return rc;
@@ -2520,12 +2516,18 @@ static int tcp4_seq_show(struct seq_file *seq, void *v)
	return 0;
	return 0;
}
}


static const struct file_operations tcp_afinfo_seq_fops = {
	.owner   = THIS_MODULE,
	.open    = tcp_seq_open,
	.read    = seq_read,
	.llseek  = seq_lseek,
	.release = seq_release_net
};

static struct tcp_seq_afinfo tcp4_seq_afinfo = {
static struct tcp_seq_afinfo tcp4_seq_afinfo = {
	.name		= "tcp",
	.name		= "tcp",
	.family		= AF_INET,
	.family		= AF_INET,
	.seq_fops	= {
	.seq_fops	= &tcp_afinfo_seq_fops,
		.owner		= THIS_MODULE,
	},
	.seq_ops	= {
	.seq_ops	= {
		.show		= tcp4_seq_show,
		.show		= tcp4_seq_show,
	},
	},
+12 −10
Original line number Original line Diff line number Diff line
@@ -2037,7 +2037,7 @@ static void udp_seq_stop(struct seq_file *seq, void *v)
		spin_unlock_bh(&state->udp_table->hash[state->bucket].lock);
		spin_unlock_bh(&state->udp_table->hash[state->bucket].lock);
}
}


static int udp_seq_open(struct inode *inode, struct file *file)
int udp_seq_open(struct inode *inode, struct file *file)
{
{
	struct udp_seq_afinfo *afinfo = PDE(inode)->data;
	struct udp_seq_afinfo *afinfo = PDE(inode)->data;
	struct udp_iter_state *s;
	struct udp_iter_state *s;
@@ -2053,6 +2053,7 @@ static int udp_seq_open(struct inode *inode, struct file *file)
	s->udp_table		= afinfo->udp_table;
	s->udp_table		= afinfo->udp_table;
	return err;
	return err;
}
}
EXPORT_SYMBOL(udp_seq_open);


/* ------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------ */
int udp_proc_register(struct net *net, struct udp_seq_afinfo *afinfo)
int udp_proc_register(struct net *net, struct udp_seq_afinfo *afinfo)
@@ -2060,17 +2061,12 @@ int udp_proc_register(struct net *net, struct udp_seq_afinfo *afinfo)
	struct proc_dir_entry *p;
	struct proc_dir_entry *p;
	int rc = 0;
	int rc = 0;


	afinfo->seq_fops.open		= udp_seq_open;
	afinfo->seq_fops.read		= seq_read;
	afinfo->seq_fops.llseek		= seq_lseek;
	afinfo->seq_fops.release	= seq_release_net;

	afinfo->seq_ops.start		= udp_seq_start;
	afinfo->seq_ops.start		= udp_seq_start;
	afinfo->seq_ops.next		= udp_seq_next;
	afinfo->seq_ops.next		= udp_seq_next;
	afinfo->seq_ops.stop		= udp_seq_stop;
	afinfo->seq_ops.stop		= udp_seq_stop;


	p = proc_create_data(afinfo->name, S_IRUGO, net->proc_net,
	p = proc_create_data(afinfo->name, S_IRUGO, net->proc_net,
			     &afinfo->seq_fops, afinfo);
			     afinfo->seq_fops, afinfo);
	if (!p)
	if (!p)
		rc = -ENOMEM;
		rc = -ENOMEM;
	return rc;
	return rc;
@@ -2120,14 +2116,20 @@ int udp4_seq_show(struct seq_file *seq, void *v)
	return 0;
	return 0;
}
}


static const struct file_operations udp_afinfo_seq_fops = {
	.owner    = THIS_MODULE,
	.open     = udp_seq_open,
	.read     = seq_read,
	.llseek   = seq_lseek,
	.release  = seq_release_net
};

/* ------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------ */
static struct udp_seq_afinfo udp4_seq_afinfo = {
static struct udp_seq_afinfo udp4_seq_afinfo = {
	.name		= "udp",
	.name		= "udp",
	.family		= AF_INET,
	.family		= AF_INET,
	.udp_table	= &udp_table,
	.udp_table	= &udp_table,
	.seq_fops	= {
	.seq_fops	= &udp_afinfo_seq_fops,
		.owner	=	THIS_MODULE,
	},
	.seq_ops	= {
	.seq_ops	= {
		.show		= udp4_seq_show,
		.show		= udp4_seq_show,
	},
	},
+10 −3
Original line number Original line Diff line number Diff line
@@ -71,13 +71,20 @@ static struct inet_protosw udplite4_protosw = {
};
};


#ifdef CONFIG_PROC_FS
#ifdef CONFIG_PROC_FS

static const struct file_operations udplite_afinfo_seq_fops = {
	.owner    = THIS_MODULE,
	.open     = udp_seq_open,
	.read     = seq_read,
	.llseek   = seq_lseek,
	.release  = seq_release_net
};

static struct udp_seq_afinfo udplite4_seq_afinfo = {
static struct udp_seq_afinfo udplite4_seq_afinfo = {
	.name		= "udplite",
	.name		= "udplite",
	.family		= AF_INET,
	.family		= AF_INET,
	.udp_table 	= &udplite_table,
	.udp_table 	= &udplite_table,
	.seq_fops	= {
	.seq_fops	= &udplite_afinfo_seq_fops,
		.owner	=	THIS_MODULE,
	},
	.seq_ops	= {
	.seq_ops	= {
		.show		= udp4_seq_show,
		.show		= udp4_seq_show,
	},
	},
Loading