2 * af_can.c - Protocol family CAN core module
3 * (used by different CAN protocol modules)
5 * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of Volkswagen nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * Alternatively, provided that this notice is retained in full, this
21 * software may be distributed under the terms of the GNU General
22 * Public License ("GPL") version 2, in which case the provisions of the
23 * GPL apply INSTEAD OF those given above.
25 * The provided data structures and external interfaces from this code
26 * are not restricted to be used by modules with a GPL compatible license.
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
41 * Send feedback to <socketcan-users@lists.berlios.de>
45 #include <linux/module.h>
46 #include <linux/version.h>
47 #include <linux/init.h>
48 #include <linux/kmod.h>
49 #include <linux/slab.h>
50 #include <linux/list.h>
51 #include <linux/spinlock.h>
52 #include <linux/rcupdate.h>
53 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
54 #include <linux/uaccess.h>
56 #include <asm/uaccess.h>
58 #include <linux/net.h>
59 #include <linux/netdevice.h>
60 #include <linux/socket.h>
61 #include <linux/if_ether.h>
62 #include <linux/if_arp.h>
63 #include <linux/skbuff.h>
64 #include <linux/can.h>
65 #include <linux/can/core.h>
66 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
67 #include <net/net_namespace.h>
73 #include <linux/can/version.h> /* for RCSID. Removed by mkpatch script */
76 static __initdata const char banner[] = KERN_INFO
77 "can: controller area network core (" CAN_VERSION_STRING ")\n";
79 MODULE_DESCRIPTION("Controller Area Network PF_CAN core");
80 MODULE_LICENSE("Dual BSD/GPL");
81 MODULE_AUTHOR("Urs Thuermann <urs.thuermann@volkswagen.de>, "
82 "Oliver Hartkopp <oliver.hartkopp@volkswagen.de>");
84 MODULE_ALIAS_NETPROTO(PF_CAN);
86 static int stats_timer __read_mostly = 1;
87 module_param(stats_timer, int, S_IRUGO);
88 MODULE_PARM_DESC(stats_timer, "enable timer for statistics (default:on)");
90 HLIST_HEAD(can_rx_dev_list);
91 static struct dev_rcv_lists can_rx_alldev_list;
92 static DEFINE_SPINLOCK(can_rcvlists_lock);
94 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
95 static struct kmem_cache *rcv_cache __read_mostly;
97 static kmem_cache_t *rcv_cache;
100 /* table of registered CAN protocols */
101 static struct can_proto *proto_tab[CAN_NPROTO] __read_mostly;
102 static DEFINE_SPINLOCK(proto_tab_lock);
104 struct timer_list can_stattimer; /* timer for statistics update */
105 struct s_stats can_stats; /* packet statistics */
106 struct s_pstats can_pstats; /* receive list statistics */
108 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14)
109 static void *kzalloc(size_t size, unsigned int __nocast flags)
111 void *ret = kmalloc(size, flags);
113 memset(ret, 0, size);
119 * af_can socket functions
122 static int can_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
124 struct sock *sk = sock->sk;
129 return sock_get_timestamp(sk, (struct timeval __user *)arg);
132 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
135 return dev_ioctl(cmd, (void __user *)arg);
140 static void can_sock_destruct(struct sock *sk)
142 skb_queue_purge(&sk->sk_receive_queue);
143 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,12)
145 kfree(sk->sk_protinfo);
149 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
150 static int can_create(struct net *net, struct socket *sock, int protocol)
152 static int can_create(struct socket *sock, int protocol)
156 struct can_proto *cp;
157 char module_name[sizeof("can-proto-000")];
160 sock->state = SS_UNCONNECTED;
162 if (protocol < 0 || protocol >= CAN_NPROTO)
165 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
166 if (net != &init_net)
167 return -EAFNOSUPPORT;
170 /* try to load protocol module, when CONFIG_KMOD is defined */
171 if (!proto_tab[protocol]) {
172 sprintf(module_name, "can-proto-%d", protocol);
173 err = request_module(module_name);
176 * In case of error we only print a message but don't
177 * return the error code immediately. Below we will
178 * return -EPROTONOSUPPORT
180 if (err == -ENOSYS) {
181 if (printk_ratelimit())
182 printk(KERN_INFO "can: request_module(%s)"
183 " not implemented.\n", module_name);
185 if (printk_ratelimit())
186 printk(KERN_ERR "can: request_module(%s)"
187 " failed.\n", module_name);
191 spin_lock(&proto_tab_lock);
192 cp = proto_tab[protocol];
193 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,12)
194 if (cp && !try_module_get(cp->prot->owner))
197 if (cp && !try_module_get(cp->owner))
200 spin_unlock(&proto_tab_lock);
202 /* check for available protocol and correct usage */
205 return -EPROTONOSUPPORT;
207 if (cp->type != sock->type) {
208 err = -EPROTONOSUPPORT;
212 if (cp->capability >= 0 && !capable(cp->capability)) {
219 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
220 sk = sk_alloc(net, PF_CAN, GFP_KERNEL, cp->prot, 1);
221 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,12)
222 sk = sk_alloc(PF_CAN, GFP_KERNEL, cp->prot, 1);
224 sk = sk_alloc(PF_CAN, GFP_KERNEL, 1, 0);
231 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,12)
233 sk->sk_protinfo = kmalloc(cp->obj_size, GFP_KERNEL);
234 if (!sk->sk_protinfo) {
240 sk_set_owner(sk, proto_tab[protocol]->owner);
243 sock_init_data(sock, sk);
244 sk->sk_destruct = can_sock_destruct;
246 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,12)
247 if (sk->sk_prot->init)
248 err = sk->sk_prot->init(sk);
255 /* release sk on errors */
261 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,12)
262 module_put(cp->prot->owner);
264 module_put(cp->owner);
274 * can_send - transmit a CAN frame (optional with local loopback)
275 * @skb: pointer to socket buffer with CAN frame in data section
276 * @loop: loopback for listeners on local CAN sockets (recommended default!)
280 * -ENETDOWN when the selected interface is down
281 * -ENOBUFS on full driver queue (see net_xmit_errno())
282 * -ENOMEM when local loopback failed at calling skb_clone()
283 * -EPERM when trying to send on a non-CAN interface
285 int can_send(struct sk_buff *skb, int loop)
289 if (skb->dev->type != ARPHRD_CAN) {
294 if (!(skb->dev->flags & IFF_UP)) {
299 skb->protocol = htons(ETH_P_CAN);
300 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
301 skb_reset_network_header(skb);
302 skb_reset_transport_header(skb);
304 skb->nh.raw = skb->data;
305 skb->h.raw = skb->data;
309 /* local loopback of sent CAN frames */
311 /* indication for the CAN driver: do loopback */
312 skb->pkt_type = PACKET_LOOPBACK;
315 * The reference to the originating sock may be required
316 * by the receiving socket to check whether the frame is
317 * its own. Example: can_raw sockopt CAN_RAW_RECV_OWN_MSGS
318 * Therefore we have to ensure that skb->sk remains the
319 * reference to the originating sock by restoring skb->sk
320 * after each skb_clone() or skb_orphan() usage.
323 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25)
324 #define IFF_ECHO IFF_LOOPBACK
326 if (!(skb->dev->flags & IFF_ECHO)) {
328 * If the interface is not capable to do loopback
329 * itself, we do it here.
331 struct sk_buff *newskb = skb_clone(skb, GFP_ATOMIC);
338 newskb->sk = skb->sk;
339 newskb->ip_summed = CHECKSUM_UNNECESSARY;
340 newskb->pkt_type = PACKET_BROADCAST;
344 /* indication for the CAN driver: no loopback required */
345 skb->pkt_type = PACKET_HOST;
348 /* send to netdevice */
349 err = dev_queue_xmit(skb);
351 err = net_xmit_errno(err);
353 /* update statistics */
354 can_stats.tx_frames++;
355 can_stats.tx_frames_delta++;
359 EXPORT_SYMBOL(can_send);
365 static struct dev_rcv_lists *find_dev_rcv_lists(struct net_device *dev)
367 struct dev_rcv_lists *d = NULL;
368 struct hlist_node *n;
371 * find receive list for this device
373 * The hlist_for_each_entry*() macros curse through the list
374 * using the pointer variable n and set d to the containing
375 * struct in each list iteration. Therefore, after list
376 * iteration, d is unmodified when the list is empty, and it
377 * points to last list element, when the list is non-empty
378 * but no match in the loop body is found. I.e. d is *not*
379 * NULL when no match is found. We can, however, use the
380 * cursor variable n to decide if a match was found.
383 hlist_for_each_entry_rcu(d, n, &can_rx_dev_list, list) {
391 static struct hlist_head *find_rcv_list(canid_t *can_id, canid_t *mask,
392 struct dev_rcv_lists *d)
394 canid_t inv = *can_id & CAN_INV_FILTER; /* save flag before masking */
396 /* filter error frames */
397 if (*mask & CAN_ERR_FLAG) {
398 /* clear CAN_ERR_FLAG in list entry */
399 *mask &= CAN_ERR_MASK;
400 return &d->rx[RX_ERR];
403 /* ensure valid values in can_mask */
404 if (*mask & CAN_EFF_FLAG)
405 *mask &= (CAN_EFF_MASK | CAN_EFF_FLAG | CAN_RTR_FLAG);
407 *mask &= (CAN_SFF_MASK | CAN_RTR_FLAG);
409 /* reduce condition testing at receive time */
412 /* inverse can_id/can_mask filter */
414 return &d->rx[RX_INV];
416 /* mask == 0 => no condition testing at receive time */
418 return &d->rx[RX_ALL];
420 /* use extra filterset for the subscription of exactly *ONE* can_id */
421 if (*can_id & CAN_EFF_FLAG) {
422 if (*mask == (CAN_EFF_MASK | CAN_EFF_FLAG)) {
423 /* RFC: a use-case for hash-tables in the future? */
424 return &d->rx[RX_EFF];
427 if (*mask == CAN_SFF_MASK)
428 return &d->rx_sff[*can_id];
431 /* default: filter via can_id/can_mask */
432 return &d->rx[RX_FIL];
436 * can_rx_register - subscribe CAN frames from a specific interface
437 * @dev: pointer to netdevice (NULL => subcribe from 'all' CAN devices list)
438 * @can_id: CAN identifier (see description)
439 * @mask: CAN mask (see description)
440 * @func: callback function on filter match
441 * @data: returned parameter for callback function
442 * @ident: string for calling module indentification
445 * Invokes the callback function with the received sk_buff and the given
446 * parameter 'data' on a matching receive filter. A filter matches, when
448 * <received_can_id> & mask == can_id & mask
450 * The filter can be inverted (CAN_INV_FILTER bit set in can_id) or it can
451 * filter for error frames (CAN_ERR_FLAG bit set in mask).
455 * -ENOMEM on missing cache mem to create subscription entry
456 * -ENODEV unknown device
458 int can_rx_register(struct net_device *dev, canid_t can_id, canid_t mask,
459 void (*func)(struct sk_buff *, void *), void *data,
463 struct hlist_head *rl;
464 struct dev_rcv_lists *d;
467 /* insert new receiver (dev,canid,mask) -> (func,data) */
469 r = kmem_cache_alloc(rcv_cache, GFP_KERNEL);
473 spin_lock(&can_rcvlists_lock);
475 d = find_dev_rcv_lists(dev);
477 rl = find_rcv_list(&can_id, &mask, d);
486 hlist_add_head_rcu(&r->list, rl);
489 can_pstats.rcv_entries++;
490 if (can_pstats.rcv_entries_max < can_pstats.rcv_entries)
491 can_pstats.rcv_entries_max = can_pstats.rcv_entries;
493 kmem_cache_free(rcv_cache, r);
497 spin_unlock(&can_rcvlists_lock);
501 EXPORT_SYMBOL(can_rx_register);
504 * can_rx_delete_device - rcu callback for dev_rcv_lists structure removal
506 static void can_rx_delete_device(struct rcu_head *rp)
508 struct dev_rcv_lists *d = container_of(rp, struct dev_rcv_lists, rcu);
514 * can_rx_delete_receiver - rcu callback for single receiver entry removal
516 static void can_rx_delete_receiver(struct rcu_head *rp)
518 struct receiver *r = container_of(rp, struct receiver, rcu);
520 kmem_cache_free(rcv_cache, r);
524 * can_rx_unregister - unsubscribe CAN frames from a specific interface
525 * @dev: pointer to netdevice (NULL => unsubcribe from 'all' CAN devices list)
526 * @can_id: CAN identifier
528 * @func: callback function on filter match
529 * @data: returned parameter for callback function
532 * Removes subscription entry depending on given (subscription) values.
534 void can_rx_unregister(struct net_device *dev, canid_t can_id, canid_t mask,
535 void (*func)(struct sk_buff *, void *), void *data)
537 struct receiver *r = NULL;
538 struct hlist_head *rl;
539 struct hlist_node *next;
540 struct dev_rcv_lists *d;
542 spin_lock(&can_rcvlists_lock);
544 d = find_dev_rcv_lists(dev);
546 printk(KERN_ERR "BUG: receive list not found for "
547 "dev %s, id %03X, mask %03X\n",
548 DNAME(dev), can_id, mask);
552 rl = find_rcv_list(&can_id, &mask, d);
555 * Search the receiver list for the item to delete. This should
556 * exist, since no receiver may be unregistered that hasn't
557 * been registered before.
560 hlist_for_each_entry_rcu(r, next, rl, list) {
561 if (r->can_id == can_id && r->mask == mask
562 && r->func == func && r->data == data)
567 * Check for bugs in CAN protocol implementations:
568 * If no matching list item was found, the list cursor variable next
569 * will be NULL, while r will point to the last item of the list.
573 printk(KERN_ERR "BUG: receive list entry not found for "
574 "dev %s, id %03X, mask %03X\n",
575 DNAME(dev), can_id, mask);
581 hlist_del_rcu(&r->list);
584 if (can_pstats.rcv_entries > 0)
585 can_pstats.rcv_entries--;
587 /* remove device structure requested by NETDEV_UNREGISTER */
588 if (d->remove_on_zero_entries && !d->entries)
589 hlist_del_rcu(&d->list);
594 spin_unlock(&can_rcvlists_lock);
596 /* schedule the receiver item for deletion */
598 call_rcu(&r->rcu, can_rx_delete_receiver);
600 /* schedule the device structure for deletion */
602 call_rcu(&d->rcu, can_rx_delete_device);
604 EXPORT_SYMBOL(can_rx_unregister);
606 static inline void deliver(struct sk_buff *skb, struct receiver *r)
608 struct sk_buff *clone = skb_clone(skb, GFP_ATOMIC);
612 r->func(clone, r->data);
617 static int can_rcv_filter(struct dev_rcv_lists *d, struct sk_buff *skb)
620 struct hlist_node *n;
622 struct can_frame *cf = (struct can_frame *)skb->data;
623 canid_t can_id = cf->can_id;
628 if (can_id & CAN_ERR_FLAG) {
629 /* check for error frame entries only */
630 hlist_for_each_entry_rcu(r, n, &d->rx[RX_ERR], list) {
631 if (can_id & r->mask) {
639 /* check for unfiltered entries */
640 hlist_for_each_entry_rcu(r, n, &d->rx[RX_ALL], list) {
645 /* check for can_id/mask entries */
646 hlist_for_each_entry_rcu(r, n, &d->rx[RX_FIL], list) {
647 if ((can_id & r->mask) == r->can_id) {
653 /* check for inverted can_id/mask entries */
654 hlist_for_each_entry_rcu(r, n, &d->rx[RX_INV], list) {
655 if ((can_id & r->mask) != r->can_id) {
661 /* check CAN_ID specific entries */
662 if (can_id & CAN_EFF_FLAG) {
663 hlist_for_each_entry_rcu(r, n, &d->rx[RX_EFF], list) {
664 if (r->can_id == can_id) {
670 can_id &= CAN_SFF_MASK;
671 hlist_for_each_entry_rcu(r, n, &d->rx_sff[can_id], list) {
680 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,14)
681 static int can_rcv(struct sk_buff *skb, struct net_device *dev,
682 struct packet_type *pt, struct net_device *orig_dev)
684 static int can_rcv(struct sk_buff *skb, struct net_device *dev,
685 struct packet_type *pt)
688 struct dev_rcv_lists *d;
691 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
692 if (dev->type != ARPHRD_CAN || dev->nd_net != &init_net) {
694 if (dev->type != ARPHRD_CAN) {
700 /* update statistics */
701 can_stats.rx_frames++;
702 can_stats.rx_frames_delta++;
706 /* deliver the packet to sockets listening on all devices */
707 matches = can_rcv_filter(&can_rx_alldev_list, skb);
709 /* find receive list for this device */
710 d = find_dev_rcv_lists(dev);
712 matches += can_rcv_filter(d, skb);
716 /* free the skbuff allocated by the netdevice driver */
721 can_stats.matches_delta++;
728 * af_can protocol functions
732 * can_proto_register - register CAN transport protocol
733 * @cp: pointer to CAN protocol structure
737 * -EINVAL invalid (out of range) protocol number
738 * -EBUSY protocol already in use
739 * -ENOBUF if proto_register() fails
741 int can_proto_register(struct can_proto *cp)
743 int proto = cp->protocol;
746 if (proto < 0 || proto >= CAN_NPROTO) {
747 printk(KERN_ERR "can: protocol number %d out of range\n",
752 spin_lock(&proto_tab_lock);
753 if (proto_tab[proto]) {
754 printk(KERN_ERR "can: protocol %d already registered\n",
760 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,12)
761 err = proto_register(cp->prot, 0);
766 proto_tab[proto] = cp;
768 /* use generic ioctl function if the module doesn't bring its own */
770 cp->ops->ioctl = can_ioctl;
773 spin_unlock(&proto_tab_lock);
777 EXPORT_SYMBOL(can_proto_register);
780 * can_proto_unregister - unregister CAN transport protocol
781 * @cp: pointer to CAN protocol structure
783 void can_proto_unregister(struct can_proto *cp)
785 int proto = cp->protocol;
787 spin_lock(&proto_tab_lock);
788 if (!proto_tab[proto]) {
789 printk(KERN_ERR "BUG: can: protocol %d is not registered\n",
792 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,12)
793 proto_unregister(cp->prot);
795 proto_tab[proto] = NULL;
796 spin_unlock(&proto_tab_lock);
798 EXPORT_SYMBOL(can_proto_unregister);
801 * af_can notifier to create/remove CAN netdevice specific structs
803 static int can_notifier(struct notifier_block *nb, unsigned long msg,
806 struct net_device *dev = (struct net_device *)data;
807 struct dev_rcv_lists *d;
809 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
810 if (dev->nd_net != &init_net)
814 if (dev->type != ARPHRD_CAN)
819 case NETDEV_REGISTER:
822 * create new dev_rcv_lists for this device
824 * N.B. zeroing the struct is the correct initialization
825 * for the embedded hlist_head structs.
826 * Another list type, e.g. list_head, would require
827 * explicit initialization.
830 d = kzalloc(sizeof(*d), GFP_KERNEL);
833 "can: allocation of receive list failed\n");
838 spin_lock(&can_rcvlists_lock);
839 hlist_add_head_rcu(&d->list, &can_rx_dev_list);
840 spin_unlock(&can_rcvlists_lock);
844 case NETDEV_UNREGISTER:
845 spin_lock(&can_rcvlists_lock);
847 d = find_dev_rcv_lists(dev);
850 d->remove_on_zero_entries = 1;
853 hlist_del_rcu(&d->list);
855 printk(KERN_ERR "can: notifier: receive list not "
856 "found for dev %s\n", dev->name);
858 spin_unlock(&can_rcvlists_lock);
861 call_rcu(&d->rcu, can_rx_delete_device);
870 * af_can module init/exit functions
873 static struct packet_type can_packet __read_mostly = {
874 .type = __constant_htons(ETH_P_CAN),
879 static struct net_proto_family can_family_ops __read_mostly = {
881 .create = can_create,
882 .owner = THIS_MODULE,
885 /* notifier block for netdevice event */
886 static struct notifier_block can_netdev_notifier __read_mostly = {
887 .notifier_call = can_notifier,
890 static __init int can_init(void)
894 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23)
895 rcv_cache = kmem_cache_create("can_receiver", sizeof(struct receiver),
898 rcv_cache = kmem_cache_create("can_receiver", sizeof(struct receiver),
905 * Insert can_rx_alldev_list for reception on all devices.
906 * This struct is zero initialized which is correct for the
907 * embedded hlist heads, the dev pointer, and the entries counter.
910 spin_lock(&can_rcvlists_lock);
911 hlist_add_head_rcu(&can_rx_alldev_list.list, &can_rx_dev_list);
912 spin_unlock(&can_rcvlists_lock);
915 /* the statistics are updated every second (timer triggered) */
916 setup_timer(&can_stattimer, can_stat_update, 0);
917 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
918 mod_timer(&can_stattimer, round_jiffies(jiffies + HZ));
920 mod_timer(&can_stattimer, jiffies + HZ);
923 can_stattimer.function = NULL;
927 /* protocol register */
928 sock_register(&can_family_ops);
929 register_netdevice_notifier(&can_netdev_notifier);
930 dev_add_pack(&can_packet);
935 static __exit void can_exit(void)
937 struct dev_rcv_lists *d;
938 struct hlist_node *n, *next;
941 del_timer(&can_stattimer);
945 /* protocol unregister */
946 dev_remove_pack(&can_packet);
947 unregister_netdevice_notifier(&can_netdev_notifier);
948 sock_unregister(PF_CAN);
950 /* remove can_rx_dev_list */
951 spin_lock(&can_rcvlists_lock);
952 hlist_del(&can_rx_alldev_list.list);
953 hlist_for_each_entry_safe(d, n, next, &can_rx_dev_list, list) {
957 spin_unlock(&can_rcvlists_lock);
959 kmem_cache_destroy(rcv_cache);
962 module_init(can_init);
963 module_exit(can_exit);