All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 2/2] net: phonet: mark phonet_protocol as const
@ 2017-09-30  9:40 Lin Zhang
  2017-09-30 11:51 ` Rémi Denis-Courmont
  0 siblings, 1 reply; 2+ messages in thread
From: Lin Zhang @ 2017-09-30  9:40 UTC (permalink / raw)
  To: davem; +Cc: netdev, courmisch, Lin Zhang

The phonet_protocol structs don't need to be written by anyone and
so can be marked as const.

Signed-off-by: Lin Zhang <xiaolou4617@gmail.com>
---
changelog:

v1 -> v2:
	* remove __read_mostly tag
---
 include/net/phonet/phonet.h |  6 ++++--
 net/phonet/af_phonet.c      | 15 ++++++++-------
 net/phonet/datagram.c       |  2 +-
 net/phonet/pep.c            |  2 +-
 4 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/include/net/phonet/phonet.h b/include/net/phonet/phonet.h
index 039cc29..51e1a2a 100644
--- a/include/net/phonet/phonet.h
+++ b/include/net/phonet/phonet.h
@@ -108,8 +108,10 @@ struct phonet_protocol {
 	int			sock_type;
 };
 
-int phonet_proto_register(unsigned int protocol, struct phonet_protocol *pp);
-void phonet_proto_unregister(unsigned int protocol, struct phonet_protocol *pp);
+int phonet_proto_register(unsigned int protocol,
+		const struct phonet_protocol *pp);
+void phonet_proto_unregister(unsigned int protocol,
+		const struct phonet_protocol *pp);
 
 int phonet_sysctl_init(void);
 void phonet_sysctl_exit(void);
diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
index b12142e..63b9870 100644
--- a/net/phonet/af_phonet.c
+++ b/net/phonet/af_phonet.c
@@ -35,11 +35,11 @@
 #include <net/phonet/pn_dev.h>
 
 /* Transport protocol registration */
-static struct phonet_protocol *proto_tab[PHONET_NPROTO] __read_mostly;
+static const struct phonet_protocol *proto_tab[PHONET_NPROTO];
 
-static struct phonet_protocol *phonet_proto_get(unsigned int protocol)
+static const struct phonet_protocol *phonet_proto_get(unsigned int protocol)
 {
-	struct phonet_protocol *pp;
+	const struct phonet_protocol *pp;
 
 	if (protocol >= PHONET_NPROTO)
 		return NULL;
@@ -53,7 +53,7 @@ static struct phonet_protocol *phonet_proto_get(unsigned int protocol)
 	return pp;
 }
 
-static inline void phonet_proto_put(struct phonet_protocol *pp)
+static inline void phonet_proto_put(const struct phonet_protocol *pp)
 {
 	module_put(pp->prot->owner);
 }
@@ -65,7 +65,7 @@ static int pn_socket_create(struct net *net, struct socket *sock, int protocol,
 {
 	struct sock *sk;
 	struct pn_sock *pn;
-	struct phonet_protocol *pnp;
+	const struct phonet_protocol *pnp;
 	int err;
 
 	if (!capable(CAP_SYS_ADMIN))
@@ -470,7 +470,7 @@ static int phonet_rcv(struct sk_buff *skb, struct net_device *dev,
 static DEFINE_MUTEX(proto_tab_lock);
 
 int __init_or_module phonet_proto_register(unsigned int protocol,
-						struct phonet_protocol *pp)
+				const struct phonet_protocol *pp)
 {
 	int err = 0;
 
@@ -492,7 +492,8 @@ int __init_or_module phonet_proto_register(unsigned int protocol,
 }
 EXPORT_SYMBOL(phonet_proto_register);
 
-void phonet_proto_unregister(unsigned int protocol, struct phonet_protocol *pp)
+void phonet_proto_unregister(unsigned int protocol,
+			const struct phonet_protocol *pp)
 {
 	mutex_lock(&proto_tab_lock);
 	BUG_ON(proto_tab[protocol] != pp);
diff --git a/net/phonet/datagram.c b/net/phonet/datagram.c
index 5e71043..b44fb90 100644
--- a/net/phonet/datagram.c
+++ b/net/phonet/datagram.c
@@ -195,7 +195,7 @@ static int pn_backlog_rcv(struct sock *sk, struct sk_buff *skb)
 	.name		= "PHONET",
 };
 
-static struct phonet_protocol pn_dgram_proto = {
+static const struct phonet_protocol pn_dgram_proto = {
 	.ops		= &phonet_dgram_ops,
 	.prot		= &pn_proto,
 	.sock_type	= SOCK_DGRAM,
diff --git a/net/phonet/pep.c b/net/phonet/pep.c
index e815379..9fc76b1 100644
--- a/net/phonet/pep.c
+++ b/net/phonet/pep.c
@@ -1351,7 +1351,7 @@ static void pep_sock_unhash(struct sock *sk)
 	.name		= "PNPIPE",
 };
 
-static struct phonet_protocol pep_pn_proto = {
+static const struct phonet_protocol pep_pn_proto = {
 	.ops		= &phonet_stream_ops,
 	.prot		= &pep_proto,
 	.sock_type	= SOCK_SEQPACKET,
-- 
1.8.3.1

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

* Re: [PATCH v2 2/2] net: phonet: mark phonet_protocol as const
  2017-09-30  9:40 [PATCH v2 2/2] net: phonet: mark phonet_protocol as const Lin Zhang
@ 2017-09-30 11:51 ` Rémi Denis-Courmont
  0 siblings, 0 replies; 2+ messages in thread
From: Rémi Denis-Courmont @ 2017-09-30 11:51 UTC (permalink / raw)
  To: Lin Zhang; +Cc: davem, netdev, courmisch

On samedi 30 septembre 2017 17:40:48 EEST Lin Zhang wrote:
> The phonet_protocol structs don't need to be written by anyone and
> so can be marked as const.
> 
> Signed-off-by: Lin Zhang <xiaolou4617@gmail.com>
> ---
> changelog:
> 
> v1 -> v2:
> 	* remove __read_mostly tag
> ---
>  include/net/phonet/phonet.h |  6 ++++--
>  net/phonet/af_phonet.c      | 15 ++++++++-------
>  net/phonet/datagram.c       |  2 +-
>  net/phonet/pep.c            |  2 +-
>  4 files changed, 14 insertions(+), 11 deletions(-)
> 
> diff --git a/include/net/phonet/phonet.h b/include/net/phonet/phonet.h
> index 039cc29..51e1a2a 100644
> --- a/include/net/phonet/phonet.h
> +++ b/include/net/phonet/phonet.h
> @@ -108,8 +108,10 @@ struct phonet_protocol {
>  	int			sock_type;
>  };
> 
> -int phonet_proto_register(unsigned int protocol, struct phonet_protocol
> *pp); -void phonet_proto_unregister(unsigned int protocol, struct
> phonet_protocol *pp); +int phonet_proto_register(unsigned int protocol,
> +		const struct phonet_protocol *pp);
> +void phonet_proto_unregister(unsigned int protocol,
> +		const struct phonet_protocol *pp);
> 
>  int phonet_sysctl_init(void);
>  void phonet_sysctl_exit(void);
> diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
> index b12142e..63b9870 100644
> --- a/net/phonet/af_phonet.c
> +++ b/net/phonet/af_phonet.c
> @@ -35,11 +35,11 @@
>  #include <net/phonet/pn_dev.h>
> 
>  /* Transport protocol registration */
> -static struct phonet_protocol *proto_tab[PHONET_NPROTO] __read_mostly;
> +static const struct phonet_protocol *proto_tab[PHONET_NPROTO];

Your patch makes each element in the table constant. It does not, cannot, make 
the table itself constant. So I am not certain that removing __read_mostly is 
a good thing.

(Well, nowadays this should probably be rare-write rather than read-mostly but 
that's a slightly different issue.)

-- 
Rémi Denis-Courmont

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

end of thread, other threads:[~2017-09-30 12:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-30  9:40 [PATCH v2 2/2] net: phonet: mark phonet_protocol as const Lin Zhang
2017-09-30 11:51 ` Rémi Denis-Courmont

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.