/*1* af_can.c - Protocol family CAN core module2* (used by different CAN protocol modules)3*4* Copyright (c) 2002-2007 Volkswagen Group Electronic Research5* All rights reserved.6*7* Redistribution and use in source and binary forms, with or without8* modification, are permitted provided that the following conditions9* are met:10* 1. Redistributions of source code must retain the above copyright11* notice, this list of conditions and the following disclaimer.12* 2. Redistributions in binary form must reproduce the above copyright13* notice, this list of conditions and the following disclaimer in the14* documentation and/or other materials provided with the distribution.15* 3. Neither the name of Volkswagen nor the names of its contributors16* may be used to endorse or promote products derived from this software17* without specific prior written permission.18*19* Alternatively, provided that this notice is retained in full, this20* software may be distributed under the terms of the GNU General21* Public License ("GPL") version 2, in which case the provisions of the22* GPL apply INSTEAD OF those given above.23*24* The provided data structures and external interfaces from this code25* are not restricted to be used by modules with a GPL compatible license.26*27* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS28* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT29* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR30* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT31* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,32* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT33* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,34* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY35* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT36* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE37* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH38* DAMAGE.39*40* Send feedback to <[email protected]>41*42*/4344#include <linux/module.h>45#include <linux/init.h>46#include <linux/kmod.h>47#include <linux/slab.h>48#include <linux/list.h>49#include <linux/spinlock.h>50#include <linux/rcupdate.h>51#include <linux/uaccess.h>52#include <linux/net.h>53#include <linux/netdevice.h>54#include <linux/socket.h>55#include <linux/if_ether.h>56#include <linux/if_arp.h>57#include <linux/skbuff.h>58#include <linux/can.h>59#include <linux/can/core.h>60#include <net/net_namespace.h>61#include <net/sock.h>6263#include "af_can.h"6465static __initdata const char banner[] = KERN_INFO66"can: controller area network core (" CAN_VERSION_STRING ")\n";6768MODULE_DESCRIPTION("Controller Area Network PF_CAN core");69MODULE_LICENSE("Dual BSD/GPL");70MODULE_AUTHOR("Urs Thuermann <[email protected]>, "71"Oliver Hartkopp <[email protected]>");7273MODULE_ALIAS_NETPROTO(PF_CAN);7475static int stats_timer __read_mostly = 1;76module_param(stats_timer, int, S_IRUGO);77MODULE_PARM_DESC(stats_timer, "enable timer for statistics (default:on)");7879/* receive filters subscribed for 'all' CAN devices */80struct dev_rcv_lists can_rx_alldev_list;81static DEFINE_SPINLOCK(can_rcvlists_lock);8283static struct kmem_cache *rcv_cache __read_mostly;8485/* table of registered CAN protocols */86static const struct can_proto *proto_tab[CAN_NPROTO] __read_mostly;87static DEFINE_MUTEX(proto_tab_lock);8889struct timer_list can_stattimer; /* timer for statistics update */90struct s_stats can_stats; /* packet statistics */91struct s_pstats can_pstats; /* receive list statistics */9293/*94* af_can socket functions95*/9697int can_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)98{99struct sock *sk = sock->sk;100101switch (cmd) {102103case SIOCGSTAMP:104return sock_get_timestamp(sk, (struct timeval __user *)arg);105106default:107return -ENOIOCTLCMD;108}109}110EXPORT_SYMBOL(can_ioctl);111112static void can_sock_destruct(struct sock *sk)113{114skb_queue_purge(&sk->sk_receive_queue);115}116117static const struct can_proto *can_get_proto(int protocol)118{119const struct can_proto *cp;120121rcu_read_lock();122cp = rcu_dereference(proto_tab[protocol]);123if (cp && !try_module_get(cp->prot->owner))124cp = NULL;125rcu_read_unlock();126127return cp;128}129130static inline void can_put_proto(const struct can_proto *cp)131{132module_put(cp->prot->owner);133}134135static int can_create(struct net *net, struct socket *sock, int protocol,136int kern)137{138struct sock *sk;139const struct can_proto *cp;140int err = 0;141142sock->state = SS_UNCONNECTED;143144if (protocol < 0 || protocol >= CAN_NPROTO)145return -EINVAL;146147if (!net_eq(net, &init_net))148return -EAFNOSUPPORT;149150cp = can_get_proto(protocol);151152#ifdef CONFIG_MODULES153if (!cp) {154/* try to load protocol module if kernel is modular */155156err = request_module("can-proto-%d", protocol);157158/*159* In case of error we only print a message but don't160* return the error code immediately. Below we will161* return -EPROTONOSUPPORT162*/163if (err && printk_ratelimit())164printk(KERN_ERR "can: request_module "165"(can-proto-%d) failed.\n", protocol);166167cp = can_get_proto(protocol);168}169#endif170171/* check for available protocol and correct usage */172173if (!cp)174return -EPROTONOSUPPORT;175176if (cp->type != sock->type) {177err = -EPROTOTYPE;178goto errout;179}180181sock->ops = cp->ops;182183sk = sk_alloc(net, PF_CAN, GFP_KERNEL, cp->prot);184if (!sk) {185err = -ENOMEM;186goto errout;187}188189sock_init_data(sock, sk);190sk->sk_destruct = can_sock_destruct;191192if (sk->sk_prot->init)193err = sk->sk_prot->init(sk);194195if (err) {196/* release sk on errors */197sock_orphan(sk);198sock_put(sk);199}200201errout:202can_put_proto(cp);203return err;204}205206/*207* af_can tx path208*/209210/**211* can_send - transmit a CAN frame (optional with local loopback)212* @skb: pointer to socket buffer with CAN frame in data section213* @loop: loopback for listeners on local CAN sockets (recommended default!)214*215* Due to the loopback this routine must not be called from hardirq context.216*217* Return:218* 0 on success219* -ENETDOWN when the selected interface is down220* -ENOBUFS on full driver queue (see net_xmit_errno())221* -ENOMEM when local loopback failed at calling skb_clone()222* -EPERM when trying to send on a non-CAN interface223* -EINVAL when the skb->data does not contain a valid CAN frame224*/225int can_send(struct sk_buff *skb, int loop)226{227struct sk_buff *newskb = NULL;228struct can_frame *cf = (struct can_frame *)skb->data;229int err;230231if (skb->len != sizeof(struct can_frame) || cf->can_dlc > 8) {232kfree_skb(skb);233return -EINVAL;234}235236if (skb->dev->type != ARPHRD_CAN) {237kfree_skb(skb);238return -EPERM;239}240241if (!(skb->dev->flags & IFF_UP)) {242kfree_skb(skb);243return -ENETDOWN;244}245246skb->protocol = htons(ETH_P_CAN);247skb_reset_network_header(skb);248skb_reset_transport_header(skb);249250if (loop) {251/* local loopback of sent CAN frames */252253/* indication for the CAN driver: do loopback */254skb->pkt_type = PACKET_LOOPBACK;255256/*257* The reference to the originating sock may be required258* by the receiving socket to check whether the frame is259* its own. Example: can_raw sockopt CAN_RAW_RECV_OWN_MSGS260* Therefore we have to ensure that skb->sk remains the261* reference to the originating sock by restoring skb->sk262* after each skb_clone() or skb_orphan() usage.263*/264265if (!(skb->dev->flags & IFF_ECHO)) {266/*267* If the interface is not capable to do loopback268* itself, we do it here.269*/270newskb = skb_clone(skb, GFP_ATOMIC);271if (!newskb) {272kfree_skb(skb);273return -ENOMEM;274}275276newskb->sk = skb->sk;277newskb->ip_summed = CHECKSUM_UNNECESSARY;278newskb->pkt_type = PACKET_BROADCAST;279}280} else {281/* indication for the CAN driver: no loopback required */282skb->pkt_type = PACKET_HOST;283}284285/* send to netdevice */286err = dev_queue_xmit(skb);287if (err > 0)288err = net_xmit_errno(err);289290if (err) {291kfree_skb(newskb);292return err;293}294295if (newskb)296netif_rx_ni(newskb);297298/* update statistics */299can_stats.tx_frames++;300can_stats.tx_frames_delta++;301302return 0;303}304EXPORT_SYMBOL(can_send);305306/*307* af_can rx path308*/309310static struct dev_rcv_lists *find_dev_rcv_lists(struct net_device *dev)311{312if (!dev)313return &can_rx_alldev_list;314else315return (struct dev_rcv_lists *)dev->ml_priv;316}317318/**319* find_rcv_list - determine optimal filterlist inside device filter struct320* @can_id: pointer to CAN identifier of a given can_filter321* @mask: pointer to CAN mask of a given can_filter322* @d: pointer to the device filter struct323*324* Description:325* Returns the optimal filterlist to reduce the filter handling in the326* receive path. This function is called by service functions that need327* to register or unregister a can_filter in the filter lists.328*329* A filter matches in general, when330*331* <received_can_id> & mask == can_id & mask332*333* so every bit set in the mask (even CAN_EFF_FLAG, CAN_RTR_FLAG) describe334* relevant bits for the filter.335*336* The filter can be inverted (CAN_INV_FILTER bit set in can_id) or it can337* filter for error frames (CAN_ERR_FLAG bit set in mask). For error frames338* there is a special filterlist and a special rx path filter handling.339*340* Return:341* Pointer to optimal filterlist for the given can_id/mask pair.342* Constistency checked mask.343* Reduced can_id to have a preprocessed filter compare value.344*/345static struct hlist_head *find_rcv_list(canid_t *can_id, canid_t *mask,346struct dev_rcv_lists *d)347{348canid_t inv = *can_id & CAN_INV_FILTER; /* save flag before masking */349350/* filter for error frames in extra filterlist */351if (*mask & CAN_ERR_FLAG) {352/* clear CAN_ERR_FLAG in filter entry */353*mask &= CAN_ERR_MASK;354return &d->rx[RX_ERR];355}356357/* with cleared CAN_ERR_FLAG we have a simple mask/value filterpair */358359#define CAN_EFF_RTR_FLAGS (CAN_EFF_FLAG | CAN_RTR_FLAG)360361/* ensure valid values in can_mask for 'SFF only' frame filtering */362if ((*mask & CAN_EFF_FLAG) && !(*can_id & CAN_EFF_FLAG))363*mask &= (CAN_SFF_MASK | CAN_EFF_RTR_FLAGS);364365/* reduce condition testing at receive time */366*can_id &= *mask;367368/* inverse can_id/can_mask filter */369if (inv)370return &d->rx[RX_INV];371372/* mask == 0 => no condition testing at receive time */373if (!(*mask))374return &d->rx[RX_ALL];375376/* extra filterlists for the subscription of a single non-RTR can_id */377if (((*mask & CAN_EFF_RTR_FLAGS) == CAN_EFF_RTR_FLAGS) &&378!(*can_id & CAN_RTR_FLAG)) {379380if (*can_id & CAN_EFF_FLAG) {381if (*mask == (CAN_EFF_MASK | CAN_EFF_RTR_FLAGS)) {382/* RFC: a future use-case for hash-tables? */383return &d->rx[RX_EFF];384}385} else {386if (*mask == (CAN_SFF_MASK | CAN_EFF_RTR_FLAGS))387return &d->rx_sff[*can_id];388}389}390391/* default: filter via can_id/can_mask */392return &d->rx[RX_FIL];393}394395/**396* can_rx_register - subscribe CAN frames from a specific interface397* @dev: pointer to netdevice (NULL => subcribe from 'all' CAN devices list)398* @can_id: CAN identifier (see description)399* @mask: CAN mask (see description)400* @func: callback function on filter match401* @data: returned parameter for callback function402* @ident: string for calling module indentification403*404* Description:405* Invokes the callback function with the received sk_buff and the given406* parameter 'data' on a matching receive filter. A filter matches, when407*408* <received_can_id> & mask == can_id & mask409*410* The filter can be inverted (CAN_INV_FILTER bit set in can_id) or it can411* filter for error frames (CAN_ERR_FLAG bit set in mask).412*413* The provided pointer to the sk_buff is guaranteed to be valid as long as414* the callback function is running. The callback function must *not* free415* the given sk_buff while processing it's task. When the given sk_buff is416* needed after the end of the callback function it must be cloned inside417* the callback function with skb_clone().418*419* Return:420* 0 on success421* -ENOMEM on missing cache mem to create subscription entry422* -ENODEV unknown device423*/424int can_rx_register(struct net_device *dev, canid_t can_id, canid_t mask,425void (*func)(struct sk_buff *, void *), void *data,426char *ident)427{428struct receiver *r;429struct hlist_head *rl;430struct dev_rcv_lists *d;431int err = 0;432433/* insert new receiver (dev,canid,mask) -> (func,data) */434435if (dev && dev->type != ARPHRD_CAN)436return -ENODEV;437438r = kmem_cache_alloc(rcv_cache, GFP_KERNEL);439if (!r)440return -ENOMEM;441442spin_lock(&can_rcvlists_lock);443444d = find_dev_rcv_lists(dev);445if (d) {446rl = find_rcv_list(&can_id, &mask, d);447448r->can_id = can_id;449r->mask = mask;450r->matches = 0;451r->func = func;452r->data = data;453r->ident = ident;454455hlist_add_head_rcu(&r->list, rl);456d->entries++;457458can_pstats.rcv_entries++;459if (can_pstats.rcv_entries_max < can_pstats.rcv_entries)460can_pstats.rcv_entries_max = can_pstats.rcv_entries;461} else {462kmem_cache_free(rcv_cache, r);463err = -ENODEV;464}465466spin_unlock(&can_rcvlists_lock);467468return err;469}470EXPORT_SYMBOL(can_rx_register);471472/*473* can_rx_delete_receiver - rcu callback for single receiver entry removal474*/475static void can_rx_delete_receiver(struct rcu_head *rp)476{477struct receiver *r = container_of(rp, struct receiver, rcu);478479kmem_cache_free(rcv_cache, r);480}481482/**483* can_rx_unregister - unsubscribe CAN frames from a specific interface484* @dev: pointer to netdevice (NULL => unsubcribe from 'all' CAN devices list)485* @can_id: CAN identifier486* @mask: CAN mask487* @func: callback function on filter match488* @data: returned parameter for callback function489*490* Description:491* Removes subscription entry depending on given (subscription) values.492*/493void can_rx_unregister(struct net_device *dev, canid_t can_id, canid_t mask,494void (*func)(struct sk_buff *, void *), void *data)495{496struct receiver *r = NULL;497struct hlist_head *rl;498struct hlist_node *next;499struct dev_rcv_lists *d;500501if (dev && dev->type != ARPHRD_CAN)502return;503504spin_lock(&can_rcvlists_lock);505506d = find_dev_rcv_lists(dev);507if (!d) {508printk(KERN_ERR "BUG: receive list not found for "509"dev %s, id %03X, mask %03X\n",510DNAME(dev), can_id, mask);511goto out;512}513514rl = find_rcv_list(&can_id, &mask, d);515516/*517* Search the receiver list for the item to delete. This should518* exist, since no receiver may be unregistered that hasn't519* been registered before.520*/521522hlist_for_each_entry_rcu(r, next, rl, list) {523if (r->can_id == can_id && r->mask == mask &&524r->func == func && r->data == data)525break;526}527528/*529* Check for bugs in CAN protocol implementations:530* If no matching list item was found, the list cursor variable next531* will be NULL, while r will point to the last item of the list.532*/533534if (!next) {535printk(KERN_ERR "BUG: receive list entry not found for "536"dev %s, id %03X, mask %03X\n",537DNAME(dev), can_id, mask);538r = NULL;539goto out;540}541542hlist_del_rcu(&r->list);543d->entries--;544545if (can_pstats.rcv_entries > 0)546can_pstats.rcv_entries--;547548/* remove device structure requested by NETDEV_UNREGISTER */549if (d->remove_on_zero_entries && !d->entries) {550kfree(d);551dev->ml_priv = NULL;552}553554out:555spin_unlock(&can_rcvlists_lock);556557/* schedule the receiver item for deletion */558if (r)559call_rcu(&r->rcu, can_rx_delete_receiver);560}561EXPORT_SYMBOL(can_rx_unregister);562563static inline void deliver(struct sk_buff *skb, struct receiver *r)564{565r->func(skb, r->data);566r->matches++;567}568569static int can_rcv_filter(struct dev_rcv_lists *d, struct sk_buff *skb)570{571struct receiver *r;572struct hlist_node *n;573int matches = 0;574struct can_frame *cf = (struct can_frame *)skb->data;575canid_t can_id = cf->can_id;576577if (d->entries == 0)578return 0;579580if (can_id & CAN_ERR_FLAG) {581/* check for error frame entries only */582hlist_for_each_entry_rcu(r, n, &d->rx[RX_ERR], list) {583if (can_id & r->mask) {584deliver(skb, r);585matches++;586}587}588return matches;589}590591/* check for unfiltered entries */592hlist_for_each_entry_rcu(r, n, &d->rx[RX_ALL], list) {593deliver(skb, r);594matches++;595}596597/* check for can_id/mask entries */598hlist_for_each_entry_rcu(r, n, &d->rx[RX_FIL], list) {599if ((can_id & r->mask) == r->can_id) {600deliver(skb, r);601matches++;602}603}604605/* check for inverted can_id/mask entries */606hlist_for_each_entry_rcu(r, n, &d->rx[RX_INV], list) {607if ((can_id & r->mask) != r->can_id) {608deliver(skb, r);609matches++;610}611}612613/* check filterlists for single non-RTR can_ids */614if (can_id & CAN_RTR_FLAG)615return matches;616617if (can_id & CAN_EFF_FLAG) {618hlist_for_each_entry_rcu(r, n, &d->rx[RX_EFF], list) {619if (r->can_id == can_id) {620deliver(skb, r);621matches++;622}623}624} else {625can_id &= CAN_SFF_MASK;626hlist_for_each_entry_rcu(r, n, &d->rx_sff[can_id], list) {627deliver(skb, r);628matches++;629}630}631632return matches;633}634635static int can_rcv(struct sk_buff *skb, struct net_device *dev,636struct packet_type *pt, struct net_device *orig_dev)637{638struct dev_rcv_lists *d;639struct can_frame *cf = (struct can_frame *)skb->data;640int matches;641642if (!net_eq(dev_net(dev), &init_net))643goto drop;644645if (WARN_ONCE(dev->type != ARPHRD_CAN ||646skb->len != sizeof(struct can_frame) ||647cf->can_dlc > 8,648"PF_CAN: dropped non conform skbuf: "649"dev type %d, len %d, can_dlc %d\n",650dev->type, skb->len, cf->can_dlc))651goto drop;652653/* update statistics */654can_stats.rx_frames++;655can_stats.rx_frames_delta++;656657rcu_read_lock();658659/* deliver the packet to sockets listening on all devices */660matches = can_rcv_filter(&can_rx_alldev_list, skb);661662/* find receive list for this device */663d = find_dev_rcv_lists(dev);664if (d)665matches += can_rcv_filter(d, skb);666667rcu_read_unlock();668669/* consume the skbuff allocated by the netdevice driver */670consume_skb(skb);671672if (matches > 0) {673can_stats.matches++;674can_stats.matches_delta++;675}676677return NET_RX_SUCCESS;678679drop:680kfree_skb(skb);681return NET_RX_DROP;682}683684/*685* af_can protocol functions686*/687688/**689* can_proto_register - register CAN transport protocol690* @cp: pointer to CAN protocol structure691*692* Return:693* 0 on success694* -EINVAL invalid (out of range) protocol number695* -EBUSY protocol already in use696* -ENOBUF if proto_register() fails697*/698int can_proto_register(const struct can_proto *cp)699{700int proto = cp->protocol;701int err = 0;702703if (proto < 0 || proto >= CAN_NPROTO) {704printk(KERN_ERR "can: protocol number %d out of range\n",705proto);706return -EINVAL;707}708709err = proto_register(cp->prot, 0);710if (err < 0)711return err;712713mutex_lock(&proto_tab_lock);714715if (proto_tab[proto]) {716printk(KERN_ERR "can: protocol %d already registered\n",717proto);718err = -EBUSY;719} else720rcu_assign_pointer(proto_tab[proto], cp);721722mutex_unlock(&proto_tab_lock);723724if (err < 0)725proto_unregister(cp->prot);726727return err;728}729EXPORT_SYMBOL(can_proto_register);730731/**732* can_proto_unregister - unregister CAN transport protocol733* @cp: pointer to CAN protocol structure734*/735void can_proto_unregister(const struct can_proto *cp)736{737int proto = cp->protocol;738739mutex_lock(&proto_tab_lock);740BUG_ON(proto_tab[proto] != cp);741rcu_assign_pointer(proto_tab[proto], NULL);742mutex_unlock(&proto_tab_lock);743744synchronize_rcu();745746proto_unregister(cp->prot);747}748EXPORT_SYMBOL(can_proto_unregister);749750/*751* af_can notifier to create/remove CAN netdevice specific structs752*/753static int can_notifier(struct notifier_block *nb, unsigned long msg,754void *data)755{756struct net_device *dev = (struct net_device *)data;757struct dev_rcv_lists *d;758759if (!net_eq(dev_net(dev), &init_net))760return NOTIFY_DONE;761762if (dev->type != ARPHRD_CAN)763return NOTIFY_DONE;764765switch (msg) {766767case NETDEV_REGISTER:768769/* create new dev_rcv_lists for this device */770d = kzalloc(sizeof(*d), GFP_KERNEL);771if (!d) {772printk(KERN_ERR773"can: allocation of receive list failed\n");774return NOTIFY_DONE;775}776BUG_ON(dev->ml_priv);777dev->ml_priv = d;778779break;780781case NETDEV_UNREGISTER:782spin_lock(&can_rcvlists_lock);783784d = dev->ml_priv;785if (d) {786if (d->entries)787d->remove_on_zero_entries = 1;788else {789kfree(d);790dev->ml_priv = NULL;791}792} else793printk(KERN_ERR "can: notifier: receive list not "794"found for dev %s\n", dev->name);795796spin_unlock(&can_rcvlists_lock);797798break;799}800801return NOTIFY_DONE;802}803804/*805* af_can module init/exit functions806*/807808static struct packet_type can_packet __read_mostly = {809.type = cpu_to_be16(ETH_P_CAN),810.dev = NULL,811.func = can_rcv,812};813814static const struct net_proto_family can_family_ops = {815.family = PF_CAN,816.create = can_create,817.owner = THIS_MODULE,818};819820/* notifier block for netdevice event */821static struct notifier_block can_netdev_notifier __read_mostly = {822.notifier_call = can_notifier,823};824825static __init int can_init(void)826{827printk(banner);828829memset(&can_rx_alldev_list, 0, sizeof(can_rx_alldev_list));830831rcv_cache = kmem_cache_create("can_receiver", sizeof(struct receiver),8320, 0, NULL);833if (!rcv_cache)834return -ENOMEM;835836if (stats_timer) {837/* the statistics are updated every second (timer triggered) */838setup_timer(&can_stattimer, can_stat_update, 0);839mod_timer(&can_stattimer, round_jiffies(jiffies + HZ));840} else841can_stattimer.function = NULL;842843can_init_proc();844845/* protocol register */846sock_register(&can_family_ops);847register_netdevice_notifier(&can_netdev_notifier);848dev_add_pack(&can_packet);849850return 0;851}852853static __exit void can_exit(void)854{855struct net_device *dev;856857if (stats_timer)858del_timer(&can_stattimer);859860can_remove_proc();861862/* protocol unregister */863dev_remove_pack(&can_packet);864unregister_netdevice_notifier(&can_netdev_notifier);865sock_unregister(PF_CAN);866867/* remove created dev_rcv_lists from still registered CAN devices */868rcu_read_lock();869for_each_netdev_rcu(&init_net, dev) {870if (dev->type == ARPHRD_CAN && dev->ml_priv){871872struct dev_rcv_lists *d = dev->ml_priv;873874BUG_ON(d->entries);875kfree(d);876dev->ml_priv = NULL;877}878}879rcu_read_unlock();880881rcu_barrier(); /* Wait for completion of call_rcu()'s */882883kmem_cache_destroy(rcv_cache);884}885886module_init(can_init);887module_exit(can_exit);888889890