瀏覽代碼

can: make struct proto const

can_ioctl is the only reason for struct proto to be non-const.
script/check-patch.pl suggests struct proto be const.

Setting the reference to the common can_ioctl() in all CAN protocols directly
removes the need to make the struct proto writable in af_can.c

Signed-off-by: Kurt Van Dijck <kurt.van.dijck@eia.be>
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
Oliver Hartkopp 14 年之前
父節點
當前提交
53914b6799
共有 4 個文件被更改,包括 12 次插入14 次删除
  1. 5 4
      include/linux/can/core.h
  2. 3 6
      net/can/af_can.c
  3. 2 2
      net/can/bcm.c
  4. 2 2
      net/can/raw.c

+ 5 - 4
include/linux/can/core.h

@@ -36,10 +36,10 @@
  * @prot:       pointer to struct proto structure.
  * @prot:       pointer to struct proto structure.
  */
  */
 struct can_proto {
 struct can_proto {
-	int              type;
-	int              protocol;
-	struct proto_ops *ops;
-	struct proto     *prot;
+	int type;
+	int protocol;
+	const struct proto_ops *ops;
+	struct proto *prot;
 };
 };
 
 
 /* function prototypes for the CAN networklayer core (af_can.c) */
 /* function prototypes for the CAN networklayer core (af_can.c) */
@@ -58,5 +58,6 @@ extern void can_rx_unregister(struct net_device *dev, canid_t can_id,
 			      void *data);
 			      void *data);
 
 
 extern int can_send(struct sk_buff *skb, int loop);
 extern int can_send(struct sk_buff *skb, int loop);
+extern int can_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg);
 
 
 #endif /* CAN_CORE_H */
 #endif /* CAN_CORE_H */

+ 3 - 6
net/can/af_can.c

@@ -95,7 +95,7 @@ struct s_pstats   can_pstats;      /* receive list statistics */
  * af_can socket functions
  * af_can socket functions
  */
  */
 
 
-static int can_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
+int can_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
 {
 {
 	struct sock *sk = sock->sk;
 	struct sock *sk = sock->sk;
 
 
@@ -108,6 +108,7 @@ static int can_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
 		return -ENOIOCTLCMD;
 		return -ENOIOCTLCMD;
 	}
 	}
 }
 }
+EXPORT_SYMBOL(can_ioctl);
 
 
 static void can_sock_destruct(struct sock *sk)
 static void can_sock_destruct(struct sock *sk)
 {
 {
@@ -698,13 +699,9 @@ int can_proto_register(struct can_proto *cp)
 		printk(KERN_ERR "can: protocol %d already registered\n",
 		printk(KERN_ERR "can: protocol %d already registered\n",
 		       proto);
 		       proto);
 		err = -EBUSY;
 		err = -EBUSY;
-	} else {
+	} else
 		proto_tab[proto] = cp;
 		proto_tab[proto] = cp;
 
 
-		/* use generic ioctl function if not defined by module */
-		if (!cp->ops->ioctl)
-			cp->ops->ioctl = can_ioctl;
-	}
 	spin_unlock(&proto_tab_lock);
 	spin_unlock(&proto_tab_lock);
 
 
 	if (err < 0)
 	if (err < 0)

+ 2 - 2
net/can/bcm.c

@@ -1569,7 +1569,7 @@ static int bcm_recvmsg(struct kiocb *iocb, struct socket *sock,
 	return size;
 	return size;
 }
 }
 
 
-static struct proto_ops bcm_ops __read_mostly = {
+static const struct proto_ops bcm_ops = {
 	.family        = PF_CAN,
 	.family        = PF_CAN,
 	.release       = bcm_release,
 	.release       = bcm_release,
 	.bind          = sock_no_bind,
 	.bind          = sock_no_bind,
@@ -1578,7 +1578,7 @@ static struct proto_ops bcm_ops __read_mostly = {
 	.accept        = sock_no_accept,
 	.accept        = sock_no_accept,
 	.getname       = sock_no_getname,
 	.getname       = sock_no_getname,
 	.poll          = datagram_poll,
 	.poll          = datagram_poll,
-	.ioctl         = NULL,		/* use can_ioctl() from af_can.c */
+	.ioctl         = can_ioctl,	/* use can_ioctl() from af_can.c */
 	.listen        = sock_no_listen,
 	.listen        = sock_no_listen,
 	.shutdown      = sock_no_shutdown,
 	.shutdown      = sock_no_shutdown,
 	.setsockopt    = sock_no_setsockopt,
 	.setsockopt    = sock_no_setsockopt,

+ 2 - 2
net/can/raw.c

@@ -742,7 +742,7 @@ static int raw_recvmsg(struct kiocb *iocb, struct socket *sock,
 	return size;
 	return size;
 }
 }
 
 
-static struct proto_ops raw_ops __read_mostly = {
+static const struct proto_ops raw_ops = {
 	.family        = PF_CAN,
 	.family        = PF_CAN,
 	.release       = raw_release,
 	.release       = raw_release,
 	.bind          = raw_bind,
 	.bind          = raw_bind,
@@ -751,7 +751,7 @@ static struct proto_ops raw_ops __read_mostly = {
 	.accept        = sock_no_accept,
 	.accept        = sock_no_accept,
 	.getname       = raw_getname,
 	.getname       = raw_getname,
 	.poll          = datagram_poll,
 	.poll          = datagram_poll,
-	.ioctl         = NULL,		/* use can_ioctl() from af_can.c */
+	.ioctl         = can_ioctl,	/* use can_ioctl() from af_can.c */
 	.listen        = sock_no_listen,
 	.listen        = sock_no_listen,
 	.shutdown      = sock_no_shutdown,
 	.shutdown      = sock_no_shutdown,
 	.setsockopt    = raw_setsockopt,
 	.setsockopt    = raw_setsockopt,