Thomas Gleixner | 1a59d1b8 | 2019-05-27 08:55:05 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Evgeniy Polyakov | 7672d0b | 2005-09-11 19:15:07 -0700 | [diff] [blame] | 2 | /* |
Valentin Ilie | f3c48ec | 2012-07-14 13:08:29 +0000 | [diff] [blame] | 3 | * connector.c |
Frederic Weisbecker | 1a5645b | 2009-02-02 23:22:04 -0800 | [diff] [blame] | 4 | * |
Evgeniy Polyakov | acb9c1b | 2009-07-21 12:43:51 -0700 | [diff] [blame] | 5 | * 2004+ Copyright (c) Evgeniy Polyakov <zbr@ioremap.net> |
Evgeniy Polyakov | 7672d0b | 2005-09-11 19:15:07 -0700 | [diff] [blame] | 6 | * All rights reserved. |
Evgeniy Polyakov | 7672d0b | 2005-09-11 19:15:07 -0700 | [diff] [blame] | 7 | */ |
| 8 | |
Randy Dunlap | d2af686 | 2018-07-07 08:27:53 -0700 | [diff] [blame] | 9 | #include <linux/compiler.h> |
Evgeniy Polyakov | 7672d0b | 2005-09-11 19:15:07 -0700 | [diff] [blame] | 10 | #include <linux/kernel.h> |
| 11 | #include <linux/module.h> |
| 12 | #include <linux/list.h> |
| 13 | #include <linux/skbuff.h> |
Hong zhi guo | 9631d79 | 2013-03-27 06:54:56 +0000 | [diff] [blame] | 14 | #include <net/netlink.h> |
Evgeniy Polyakov | 7672d0b | 2005-09-11 19:15:07 -0700 | [diff] [blame] | 15 | #include <linux/moduleparam.h> |
| 16 | #include <linux/connector.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 17 | #include <linux/slab.h> |
Arjan van de Ven | 8ed965d | 2006-03-23 03:00:21 -0800 | [diff] [blame] | 18 | #include <linux/mutex.h> |
Li Zefan | a0a61a6 | 2008-06-27 20:03:24 -0700 | [diff] [blame] | 19 | #include <linux/proc_fs.h> |
| 20 | #include <linux/spinlock.h> |
Evgeniy Polyakov | 7672d0b | 2005-09-11 19:15:07 -0700 | [diff] [blame] | 21 | |
| 22 | #include <net/sock.h> |
| 23 | |
| 24 | MODULE_LICENSE("GPL"); |
Evgeniy Polyakov | acb9c1b | 2009-07-21 12:43:51 -0700 | [diff] [blame] | 25 | MODULE_AUTHOR("Evgeniy Polyakov <zbr@ioremap.net>"); |
Evgeniy Polyakov | 7672d0b | 2005-09-11 19:15:07 -0700 | [diff] [blame] | 26 | MODULE_DESCRIPTION("Generic userspace <-> kernelspace connector."); |
Stephen Hemminger | 3700c3c | 2010-12-10 12:27:49 -0800 | [diff] [blame] | 27 | MODULE_ALIAS_NET_PF_PROTO(PF_NETLINK, NETLINK_CONNECTOR); |
Evgeniy Polyakov | 7672d0b | 2005-09-11 19:15:07 -0700 | [diff] [blame] | 28 | |
Evgeniy Polyakov | 7672d0b | 2005-09-11 19:15:07 -0700 | [diff] [blame] | 29 | static struct cn_dev cdev; |
| 30 | |
Li Zefan | 7837467 | 2008-02-26 18:25:53 -0800 | [diff] [blame] | 31 | static int cn_already_initialized; |
Evgeniy Polyakov | 7672d0b | 2005-09-11 19:15:07 -0700 | [diff] [blame] | 32 | |
| 33 | /* |
David Fries | 34470e0 | 2014-04-08 22:37:08 -0500 | [diff] [blame] | 34 | * Sends mult (multiple) cn_msg at a time. |
| 35 | * |
Evgeniy Polyakov | 7672d0b | 2005-09-11 19:15:07 -0700 | [diff] [blame] | 36 | * msg->seq and msg->ack are used to determine message genealogy. |
| 37 | * When someone sends message it puts there locally unique sequence |
| 38 | * and random acknowledge numbers. Sequence number may be copied into |
| 39 | * nlmsghdr->nlmsg_seq too. |
| 40 | * |
| 41 | * Sequence number is incremented with each message to be sent. |
| 42 | * |
David Fries | ac8f733 | 2014-01-15 22:29:19 -0600 | [diff] [blame] | 43 | * If we expect a reply to our message then the sequence number in |
Evgeniy Polyakov | 7672d0b | 2005-09-11 19:15:07 -0700 | [diff] [blame] | 44 | * received message MUST be the same as in original message, and |
| 45 | * acknowledge number MUST be the same + 1. |
| 46 | * |
| 47 | * If we receive a message and its sequence number is not equal to the |
| 48 | * one we are expecting then it is a new message. |
| 49 | * |
| 50 | * If we receive a message and its sequence number is the same as one |
| 51 | * we are expecting but it's acknowledgement number is not equal to |
| 52 | * the acknowledgement number in the original message + 1, then it is |
| 53 | * a new message. |
| 54 | * |
David Fries | 34470e0 | 2014-04-08 22:37:08 -0500 | [diff] [blame] | 55 | * If msg->len != len, then additional cn_msg messages are expected following |
| 56 | * the first msg. |
| 57 | * |
David Fries | ac8f733 | 2014-01-15 22:29:19 -0600 | [diff] [blame] | 58 | * The message is sent to, the portid if given, the group if given, both if |
| 59 | * both, or if both are zero then the group is looked up and sent there. |
Evgeniy Polyakov | 7672d0b | 2005-09-11 19:15:07 -0700 | [diff] [blame] | 60 | */ |
David Fries | 34470e0 | 2014-04-08 22:37:08 -0500 | [diff] [blame] | 61 | int cn_netlink_send_mult(struct cn_msg *msg, u16 len, u32 portid, u32 __group, |
David Fries | ac8f733 | 2014-01-15 22:29:19 -0600 | [diff] [blame] | 62 | gfp_t gfp_mask) |
Evgeniy Polyakov | 7672d0b | 2005-09-11 19:15:07 -0700 | [diff] [blame] | 63 | { |
| 64 | struct cn_callback_entry *__cbq; |
| 65 | unsigned int size; |
| 66 | struct sk_buff *skb; |
| 67 | struct nlmsghdr *nlh; |
| 68 | struct cn_msg *data; |
| 69 | struct cn_dev *dev = &cdev; |
| 70 | u32 group = 0; |
| 71 | int found = 0; |
| 72 | |
David Fries | ac8f733 | 2014-01-15 22:29:19 -0600 | [diff] [blame] | 73 | if (portid || __group) { |
| 74 | group = __group; |
| 75 | } else { |
Evgeniy Polyakov | 7672d0b | 2005-09-11 19:15:07 -0700 | [diff] [blame] | 76 | spin_lock_bh(&dev->cbdev->queue_lock); |
| 77 | list_for_each_entry(__cbq, &dev->cbdev->queue_list, |
| 78 | callback_entry) { |
Evgeniy Polyakov | acd042b | 2005-09-26 15:06:50 -0700 | [diff] [blame] | 79 | if (cn_cb_equal(&__cbq->id.id, &msg->id)) { |
Evgeniy Polyakov | 7672d0b | 2005-09-11 19:15:07 -0700 | [diff] [blame] | 80 | found = 1; |
| 81 | group = __cbq->group; |
Li Zefan | fd00eec | 2008-01-04 01:54:38 -0800 | [diff] [blame] | 82 | break; |
Evgeniy Polyakov | 7672d0b | 2005-09-11 19:15:07 -0700 | [diff] [blame] | 83 | } |
| 84 | } |
| 85 | spin_unlock_bh(&dev->cbdev->queue_lock); |
| 86 | |
| 87 | if (!found) |
| 88 | return -ENODEV; |
Evgeniy Polyakov | 7672d0b | 2005-09-11 19:15:07 -0700 | [diff] [blame] | 89 | } |
| 90 | |
David Fries | ac8f733 | 2014-01-15 22:29:19 -0600 | [diff] [blame] | 91 | if (!portid && !netlink_has_listeners(dev->nls, group)) |
Evgeniy Polyakov | b191ba0 | 2006-03-20 22:21:40 -0800 | [diff] [blame] | 92 | return -ESRCH; |
| 93 | |
David Fries | 34470e0 | 2014-04-08 22:37:08 -0500 | [diff] [blame] | 94 | size = sizeof(*msg) + len; |
Evgeniy Polyakov | 7672d0b | 2005-09-11 19:15:07 -0700 | [diff] [blame] | 95 | |
Hong zhi guo | 9631d79 | 2013-03-27 06:54:56 +0000 | [diff] [blame] | 96 | skb = nlmsg_new(size, gfp_mask); |
Evgeniy Polyakov | 7672d0b | 2005-09-11 19:15:07 -0700 | [diff] [blame] | 97 | if (!skb) |
| 98 | return -ENOMEM; |
| 99 | |
Hong zhi guo | 9631d79 | 2013-03-27 06:54:56 +0000 | [diff] [blame] | 100 | nlh = nlmsg_put(skb, 0, msg->seq, NLMSG_DONE, size, 0); |
Javier Martinez Canillas | 85c9316 | 2012-06-26 05:41:24 +0000 | [diff] [blame] | 101 | if (!nlh) { |
| 102 | kfree_skb(skb); |
| 103 | return -EMSGSIZE; |
| 104 | } |
Evgeniy Polyakov | 7672d0b | 2005-09-11 19:15:07 -0700 | [diff] [blame] | 105 | |
Javier Martinez Canillas | 85c9316 | 2012-06-26 05:41:24 +0000 | [diff] [blame] | 106 | data = nlmsg_data(nlh); |
Evgeniy Polyakov | 7672d0b | 2005-09-11 19:15:07 -0700 | [diff] [blame] | 107 | |
Mathias Krause | ac73bf5 | 2013-09-30 22:03:08 +0200 | [diff] [blame] | 108 | memcpy(data, msg, size); |
Evgeniy Polyakov | 7672d0b | 2005-09-11 19:15:07 -0700 | [diff] [blame] | 109 | |
| 110 | NETLINK_CB(skb).dst_group = group; |
| 111 | |
David Fries | ac8f733 | 2014-01-15 22:29:19 -0600 | [diff] [blame] | 112 | if (group) |
| 113 | return netlink_broadcast(dev->nls, skb, portid, group, |
| 114 | gfp_mask); |
Mel Gorman | d0164ad | 2015-11-06 16:28:21 -0800 | [diff] [blame] | 115 | return netlink_unicast(dev->nls, skb, portid, |
| 116 | !gfpflags_allow_blocking(gfp_mask)); |
Evgeniy Polyakov | 7672d0b | 2005-09-11 19:15:07 -0700 | [diff] [blame] | 117 | } |
David Fries | 34470e0 | 2014-04-08 22:37:08 -0500 | [diff] [blame] | 118 | EXPORT_SYMBOL_GPL(cn_netlink_send_mult); |
| 119 | |
| 120 | /* same as cn_netlink_send_mult except msg->len is used for len */ |
| 121 | int cn_netlink_send(struct cn_msg *msg, u32 portid, u32 __group, |
| 122 | gfp_t gfp_mask) |
| 123 | { |
| 124 | return cn_netlink_send_mult(msg, msg->len, portid, __group, gfp_mask); |
| 125 | } |
Andrew Morton | deb0e9b | 2006-06-23 02:05:46 -0700 | [diff] [blame] | 126 | EXPORT_SYMBOL_GPL(cn_netlink_send); |
Evgeniy Polyakov | 7672d0b | 2005-09-11 19:15:07 -0700 | [diff] [blame] | 127 | |
| 128 | /* |
| 129 | * Callback helper - queues work and setup destructor for given data. |
| 130 | */ |
Philipp Reisner | f1489cf | 2009-10-02 02:40:07 +0000 | [diff] [blame] | 131 | static int cn_call_callback(struct sk_buff *skb) |
Evgeniy Polyakov | 7672d0b | 2005-09-11 19:15:07 -0700 | [diff] [blame] | 132 | { |
David Fries | a30cfa4 | 2014-11-10 20:19:36 -0600 | [diff] [blame] | 133 | struct nlmsghdr *nlh; |
Patrick McHardy | 04f482f | 2011-03-28 08:39:36 +0000 | [diff] [blame] | 134 | struct cn_callback_entry *i, *cbq = NULL; |
Evgeniy Polyakov | 7672d0b | 2005-09-11 19:15:07 -0700 | [diff] [blame] | 135 | struct cn_dev *dev = &cdev; |
Hong zhi guo | 9631d79 | 2013-03-27 06:54:56 +0000 | [diff] [blame] | 136 | struct cn_msg *msg = nlmsg_data(nlmsg_hdr(skb)); |
Patrick McHardy | 04f482f | 2011-03-28 08:39:36 +0000 | [diff] [blame] | 137 | struct netlink_skb_parms *nsp = &NETLINK_CB(skb); |
Evgeniy Polyakov | acd042b | 2005-09-26 15:06:50 -0700 | [diff] [blame] | 138 | int err = -ENODEV; |
Evgeniy Polyakov | 7672d0b | 2005-09-11 19:15:07 -0700 | [diff] [blame] | 139 | |
David Fries | a30cfa4 | 2014-11-10 20:19:36 -0600 | [diff] [blame] | 140 | /* verify msg->len is within skb */ |
| 141 | nlh = nlmsg_hdr(skb); |
| 142 | if (nlh->nlmsg_len < NLMSG_HDRLEN + sizeof(struct cn_msg) + msg->len) |
| 143 | return -EINVAL; |
| 144 | |
Evgeniy Polyakov | 7672d0b | 2005-09-11 19:15:07 -0700 | [diff] [blame] | 145 | spin_lock_bh(&dev->cbdev->queue_lock); |
Patrick McHardy | 04f482f | 2011-03-28 08:39:36 +0000 | [diff] [blame] | 146 | list_for_each_entry(i, &dev->cbdev->queue_list, callback_entry) { |
| 147 | if (cn_cb_equal(&i->id.id, &msg->id)) { |
Elena Reshetova | e65f7ee | 2017-10-20 10:23:49 +0300 | [diff] [blame] | 148 | refcount_inc(&i->refcnt); |
Patrick McHardy | 04f482f | 2011-03-28 08:39:36 +0000 | [diff] [blame] | 149 | cbq = i; |
Evgeniy Polyakov | 7672d0b | 2005-09-11 19:15:07 -0700 | [diff] [blame] | 150 | break; |
| 151 | } |
| 152 | } |
| 153 | spin_unlock_bh(&dev->cbdev->queue_lock); |
| 154 | |
Patrick McHardy | 04f482f | 2011-03-28 08:39:36 +0000 | [diff] [blame] | 155 | if (cbq != NULL) { |
| 156 | cbq->callback(msg, nsp); |
| 157 | kfree_skb(skb); |
| 158 | cn_queue_release_callback(cbq); |
Patrick McHardy | 0e08785 | 2011-04-12 05:39:51 +0000 | [diff] [blame] | 159 | err = 0; |
Patrick McHardy | 04f482f | 2011-03-28 08:39:36 +0000 | [diff] [blame] | 160 | } |
| 161 | |
Evgeniy Polyakov | acd042b | 2005-09-26 15:06:50 -0700 | [diff] [blame] | 162 | return err; |
Evgeniy Polyakov | 7672d0b | 2005-09-11 19:15:07 -0700 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | /* |
Evgeniy Polyakov | 7672d0b | 2005-09-11 19:15:07 -0700 | [diff] [blame] | 166 | * Main netlink receiving function. |
| 167 | * |
Li Zefan | 00f5e06 | 2008-01-04 01:55:01 -0800 | [diff] [blame] | 168 | * It checks skb, netlink header and msg sizes, and calls callback helper. |
Evgeniy Polyakov | 7672d0b | 2005-09-11 19:15:07 -0700 | [diff] [blame] | 169 | */ |
Florian Westphal | 55285bf | 2015-12-31 14:26:33 +0100 | [diff] [blame] | 170 | static void cn_rx_skb(struct sk_buff *skb) |
Evgeniy Polyakov | 7672d0b | 2005-09-11 19:15:07 -0700 | [diff] [blame] | 171 | { |
| 172 | struct nlmsghdr *nlh; |
Mathias Krause | 162b2be | 2013-09-30 22:03:07 +0200 | [diff] [blame] | 173 | int len, err; |
Evgeniy Polyakov | 7672d0b | 2005-09-11 19:15:07 -0700 | [diff] [blame] | 174 | |
Hong zhi guo | 9631d79 | 2013-03-27 06:54:56 +0000 | [diff] [blame] | 175 | if (skb->len >= NLMSG_HDRLEN) { |
Arnaldo Carvalho de Melo | b529ccf | 2007-04-25 19:08:35 -0700 | [diff] [blame] | 176 | nlh = nlmsg_hdr(skb); |
Mathias Krause | 162b2be | 2013-09-30 22:03:07 +0200 | [diff] [blame] | 177 | len = nlmsg_len(nlh); |
Evgeniy Polyakov | 7672d0b | 2005-09-11 19:15:07 -0700 | [diff] [blame] | 178 | |
Mathias Krause | 162b2be | 2013-09-30 22:03:07 +0200 | [diff] [blame] | 179 | if (len < (int)sizeof(struct cn_msg) || |
Evgeniy Polyakov | 7672d0b | 2005-09-11 19:15:07 -0700 | [diff] [blame] | 180 | skb->len < nlh->nlmsg_len || |
Florian Westphal | 55285bf | 2015-12-31 14:26:33 +0100 | [diff] [blame] | 181 | len > CONNECTOR_MAX_MSG_SIZE) |
Michal Januszewski | 6cf92e9 | 2007-10-30 20:41:49 -0700 | [diff] [blame] | 182 | return; |
Evgeniy Polyakov | 7672d0b | 2005-09-11 19:15:07 -0700 | [diff] [blame] | 183 | |
Florian Westphal | 55285bf | 2015-12-31 14:26:33 +0100 | [diff] [blame] | 184 | err = cn_call_callback(skb_get(skb)); |
Evgeniy Polyakov | 7672d0b | 2005-09-11 19:15:07 -0700 | [diff] [blame] | 185 | if (err < 0) |
| 186 | kfree_skb(skb); |
| 187 | } |
Evgeniy Polyakov | 7672d0b | 2005-09-11 19:15:07 -0700 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | /* |
Evgeniy Polyakov | 7672d0b | 2005-09-11 19:15:07 -0700 | [diff] [blame] | 191 | * Callback add routing - adds callback with given ID and name. |
| 192 | * If there is registered callback with the same ID it will not be added. |
| 193 | * |
| 194 | * May sleep. |
| 195 | */ |
Joe Perches | 008536e | 2011-02-19 15:45:29 -0800 | [diff] [blame] | 196 | int cn_add_callback(struct cb_id *id, const char *name, |
Valentin Ilie | f3c48ec | 2012-07-14 13:08:29 +0000 | [diff] [blame] | 197 | void (*callback)(struct cn_msg *, |
| 198 | struct netlink_skb_parms *)) |
Evgeniy Polyakov | 7672d0b | 2005-09-11 19:15:07 -0700 | [diff] [blame] | 199 | { |
| 200 | int err; |
| 201 | struct cn_dev *dev = &cdev; |
Evgeniy Polyakov | 7672d0b | 2005-09-11 19:15:07 -0700 | [diff] [blame] | 202 | |
Evgeniy Polyakov | d6cc7f1 | 2006-06-19 23:42:53 -0700 | [diff] [blame] | 203 | if (!cn_already_initialized) |
| 204 | return -EAGAIN; |
| 205 | |
Evgeniy Polyakov | acd042b | 2005-09-26 15:06:50 -0700 | [diff] [blame] | 206 | err = cn_queue_add_callback(dev->cbdev, name, id, callback); |
| 207 | if (err) |
Evgeniy Polyakov | 7672d0b | 2005-09-11 19:15:07 -0700 | [diff] [blame] | 208 | return err; |
Evgeniy Polyakov | 7672d0b | 2005-09-11 19:15:07 -0700 | [diff] [blame] | 209 | |
Evgeniy Polyakov | 7672d0b | 2005-09-11 19:15:07 -0700 | [diff] [blame] | 210 | return 0; |
| 211 | } |
Andrew Morton | deb0e9b | 2006-06-23 02:05:46 -0700 | [diff] [blame] | 212 | EXPORT_SYMBOL_GPL(cn_add_callback); |
Evgeniy Polyakov | 7672d0b | 2005-09-11 19:15:07 -0700 | [diff] [blame] | 213 | |
| 214 | /* |
| 215 | * Callback remove routing - removes callback |
| 216 | * with given ID. |
| 217 | * If there is no registered callback with given |
| 218 | * ID nothing happens. |
| 219 | * |
| 220 | * May sleep while waiting for reference counter to become zero. |
| 221 | */ |
| 222 | void cn_del_callback(struct cb_id *id) |
| 223 | { |
| 224 | struct cn_dev *dev = &cdev; |
| 225 | |
| 226 | cn_queue_del_callback(dev->cbdev, id); |
Evgeniy Polyakov | 7672d0b | 2005-09-11 19:15:07 -0700 | [diff] [blame] | 227 | } |
Andrew Morton | deb0e9b | 2006-06-23 02:05:46 -0700 | [diff] [blame] | 228 | EXPORT_SYMBOL_GPL(cn_del_callback); |
Evgeniy Polyakov | 7672d0b | 2005-09-11 19:15:07 -0700 | [diff] [blame] | 229 | |
Randy Dunlap | d2af686 | 2018-07-07 08:27:53 -0700 | [diff] [blame] | 230 | static int __maybe_unused cn_proc_show(struct seq_file *m, void *v) |
Li Zefan | a0a61a6 | 2008-06-27 20:03:24 -0700 | [diff] [blame] | 231 | { |
| 232 | struct cn_queue_dev *dev = cdev.cbdev; |
| 233 | struct cn_callback_entry *cbq; |
| 234 | |
| 235 | seq_printf(m, "Name ID\n"); |
| 236 | |
| 237 | spin_lock_bh(&dev->queue_lock); |
| 238 | |
| 239 | list_for_each_entry(cbq, &dev->queue_list, callback_entry) { |
| 240 | seq_printf(m, "%-15s %u:%u\n", |
| 241 | cbq->id.name, |
| 242 | cbq->id.id.idx, |
| 243 | cbq->id.id.val); |
| 244 | } |
| 245 | |
| 246 | spin_unlock_bh(&dev->queue_lock); |
| 247 | |
| 248 | return 0; |
| 249 | } |
| 250 | |
Pablo Neira Ayuso | a31f2d1 | 2012-06-29 06:15:21 +0000 | [diff] [blame] | 251 | static struct cn_dev cdev = { |
| 252 | .input = cn_rx_skb, |
| 253 | }; |
| 254 | |
Greg Kroah-Hartman | 0fe763c | 2012-12-21 15:14:44 -0800 | [diff] [blame] | 255 | static int cn_init(void) |
Evgeniy Polyakov | 7672d0b | 2005-09-11 19:15:07 -0700 | [diff] [blame] | 256 | { |
| 257 | struct cn_dev *dev = &cdev; |
Pablo Neira Ayuso | a31f2d1 | 2012-06-29 06:15:21 +0000 | [diff] [blame] | 258 | struct netlink_kernel_cfg cfg = { |
| 259 | .groups = CN_NETLINK_USERS + 0xf, |
| 260 | .input = dev->input, |
| 261 | }; |
Evgeniy Polyakov | 7672d0b | 2005-09-11 19:15:07 -0700 | [diff] [blame] | 262 | |
Pablo Neira Ayuso | 9f00d97 | 2012-09-08 02:53:54 +0000 | [diff] [blame] | 263 | dev->nls = netlink_kernel_create(&init_net, NETLINK_CONNECTOR, &cfg); |
Evgeniy Polyakov | 7672d0b | 2005-09-11 19:15:07 -0700 | [diff] [blame] | 264 | if (!dev->nls) |
| 265 | return -EIO; |
| 266 | |
| 267 | dev->cbdev = cn_queue_alloc_dev("cqueue", dev->nls); |
| 268 | if (!dev->cbdev) { |
Denis V. Lunev | b7c6ba6 | 2008-01-28 14:41:19 -0800 | [diff] [blame] | 269 | netlink_kernel_release(dev->nls); |
Evgeniy Polyakov | 7672d0b | 2005-09-11 19:15:07 -0700 | [diff] [blame] | 270 | return -EINVAL; |
| 271 | } |
Frederic Weisbecker | 1a5645b | 2009-02-02 23:22:04 -0800 | [diff] [blame] | 272 | |
Evgeniy Polyakov | d6cc7f1 | 2006-06-19 23:42:53 -0700 | [diff] [blame] | 273 | cn_already_initialized = 1; |
Evgeniy Polyakov | 7672d0b | 2005-09-11 19:15:07 -0700 | [diff] [blame] | 274 | |
Christoph Hellwig | 3f3942a | 2018-05-15 15:57:23 +0200 | [diff] [blame] | 275 | proc_create_single("connector", S_IRUGO, init_net.proc_net, cn_proc_show); |
Li Zefan | a0a61a6 | 2008-06-27 20:03:24 -0700 | [diff] [blame] | 276 | |
Evgeniy Polyakov | 7672d0b | 2005-09-11 19:15:07 -0700 | [diff] [blame] | 277 | return 0; |
| 278 | } |
| 279 | |
Greg Kroah-Hartman | 0fe763c | 2012-12-21 15:14:44 -0800 | [diff] [blame] | 280 | static void cn_fini(void) |
Evgeniy Polyakov | 7672d0b | 2005-09-11 19:15:07 -0700 | [diff] [blame] | 281 | { |
| 282 | struct cn_dev *dev = &cdev; |
| 283 | |
| 284 | cn_already_initialized = 0; |
| 285 | |
Gao feng | ece31ff | 2013-02-18 01:34:56 +0000 | [diff] [blame] | 286 | remove_proc_entry("connector", init_net.proc_net); |
Li Zefan | a0a61a6 | 2008-06-27 20:03:24 -0700 | [diff] [blame] | 287 | |
Evgeniy Polyakov | 7672d0b | 2005-09-11 19:15:07 -0700 | [diff] [blame] | 288 | cn_queue_free_dev(dev->cbdev); |
Denis V. Lunev | b7c6ba6 | 2008-01-28 14:41:19 -0800 | [diff] [blame] | 289 | netlink_kernel_release(dev->nls); |
Evgeniy Polyakov | 7672d0b | 2005-09-11 19:15:07 -0700 | [diff] [blame] | 290 | } |
| 291 | |
Evgeniy Polyakov | d6cc7f1 | 2006-06-19 23:42:53 -0700 | [diff] [blame] | 292 | subsys_initcall(cn_init); |
Evgeniy Polyakov | 7672d0b | 2005-09-11 19:15:07 -0700 | [diff] [blame] | 293 | module_exit(cn_fini); |