From: hartkopp Date: Tue, 19 Apr 2011 13:03:41 +0000 (+0000) Subject: can: make struct proto const X-Git-Url: https://rtime.felk.cvut.cz/gitweb/socketcan-devel.git/commitdiff_plain/51bc05c36e76e16ec6d7217718981c1bace08b0a 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 Signed-off-by: Oliver Hartkopp Signed-off-by: David S. Miller git-svn-id: svn://svn.berlios.de//socketcan/trunk@1237 030b6a49-0b11-0410-94ab-b0dab22257f2 --- diff --git a/kernel/2.6/include/socketcan/can/core.h b/kernel/2.6/include/socketcan/can/core.h index b8a17b1..af7fd65 100644 --- a/kernel/2.6/include/socketcan/can/core.h +++ b/kernel/2.6/include/socketcan/can/core.h @@ -39,18 +39,18 @@ * @prot: pointer to struct proto structure. */ struct can_proto { - int type; - int protocol; + int type; + int protocol; #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33) - int capability; + int capability; #endif - struct proto_ops *ops; + const struct proto_ops *ops; #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,12) - struct proto *prot; + struct proto *prot; #else - struct module *owner; - int (*init)(struct sock *sk); - size_t obj_size; + struct module *owner; + int (*init)(struct sock *sk); + size_t obj_size; #endif }; @@ -70,5 +70,6 @@ extern void can_rx_unregister(struct net_device *dev, canid_t can_id, void *data); 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 */ diff --git a/kernel/2.6/net/can/af_can.c b/kernel/2.6/net/can/af_can.c index e3f7b3c..98b9f36 100644 --- a/kernel/2.6/net/can/af_can.c +++ b/kernel/2.6/net/can/af_can.c @@ -112,7 +112,7 @@ struct s_pstats can_pstats; /* receive list statistics */ * 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; @@ -129,6 +129,7 @@ static int can_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) #endif } } +EXPORT_SYMBOL(can_ioctl); static void can_sock_destruct(struct sock *sk) { @@ -867,13 +868,9 @@ int can_proto_register(struct can_proto *cp) printk(KERN_ERR "can: protocol %d already registered\n", proto); err = -EBUSY; - } else { + } else 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); #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,12) diff --git a/kernel/2.6/net/can/bcm-prior-2-6-22.c b/kernel/2.6/net/can/bcm-prior-2-6-22.c index 4e47e9c..bc58c79 100644 --- a/kernel/2.6/net/can/bcm-prior-2-6-22.c +++ b/kernel/2.6/net/can/bcm-prior-2-6-22.c @@ -1545,7 +1545,7 @@ static int bcm_recvmsg(struct kiocb *iocb, struct socket *sock, return size; } -static struct proto_ops bcm_ops __read_mostly = { +static const struct proto_ops bcm_ops = { .family = PF_CAN, .release = bcm_release, .bind = sock_no_bind, @@ -1554,7 +1554,7 @@ static struct proto_ops bcm_ops __read_mostly = { .accept = sock_no_accept, .getname = sock_no_getname, .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, .shutdown = sock_no_shutdown, .setsockopt = sock_no_setsockopt, diff --git a/kernel/2.6/net/can/bcm.c b/kernel/2.6/net/can/bcm.c index a33218b..c1b0ed8 100644 --- a/kernel/2.6/net/can/bcm.c +++ b/kernel/2.6/net/can/bcm.c @@ -1702,7 +1702,7 @@ static int bcm_recvmsg(struct kiocb *iocb, struct socket *sock, return size; } -static struct proto_ops bcm_ops __read_mostly = { +static const struct proto_ops bcm_ops = { .family = PF_CAN, .release = bcm_release, .bind = sock_no_bind, @@ -1711,7 +1711,7 @@ static struct proto_ops bcm_ops __read_mostly = { .accept = sock_no_accept, .getname = sock_no_getname, .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, .shutdown = sock_no_shutdown, .setsockopt = sock_no_setsockopt, diff --git a/kernel/2.6/net/can/isotp.c b/kernel/2.6/net/can/isotp.c index b824984..21477e2 100644 --- a/kernel/2.6/net/can/isotp.c +++ b/kernel/2.6/net/can/isotp.c @@ -1126,7 +1126,7 @@ static int isotp_init(struct sock *sk) } -static struct proto_ops isotp_ops __read_mostly = { +static const struct proto_ops isotp_ops = { .family = PF_CAN, .release = isotp_release, .bind = isotp_bind, @@ -1135,7 +1135,7 @@ static struct proto_ops isotp_ops __read_mostly = { .accept = sock_no_accept, .getname = isotp_getname, .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, .shutdown = sock_no_shutdown, .setsockopt = isotp_setsockopt, diff --git a/kernel/2.6/net/can/raw.c b/kernel/2.6/net/can/raw.c index 68937ce..5ab46ce 100644 --- a/kernel/2.6/net/can/raw.c +++ b/kernel/2.6/net/can/raw.c @@ -774,7 +774,7 @@ static int raw_recvmsg(struct kiocb *iocb, struct socket *sock, return size; } -static struct proto_ops raw_ops __read_mostly = { +static const struct proto_ops raw_ops = { .family = PF_CAN, .release = raw_release, .bind = raw_bind, @@ -783,7 +783,7 @@ static struct proto_ops raw_ops __read_mostly = { .accept = sock_no_accept, .getname = raw_getname, .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, .shutdown = sock_no_shutdown, .setsockopt = raw_setsockopt,