Thomas Gleixner | 43aa313 | 2019-05-29 07:17:54 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Vitaly Kuznetsov | 14b50f8 | 2015-04-11 18:07:51 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Kernel/userspace transport abstraction for Hyper-V util driver. |
| 4 | * |
| 5 | * Copyright (C) 2015, Vitaly Kuznetsov <vkuznets@redhat.com> |
Vitaly Kuznetsov | 14b50f8 | 2015-04-11 18:07:51 -0700 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <linux/slab.h> |
| 9 | #include <linux/fs.h> |
| 10 | #include <linux/poll.h> |
| 11 | |
| 12 | #include "hyperv_vmbus.h" |
| 13 | #include "hv_utils_transport.h" |
| 14 | |
| 15 | static DEFINE_SPINLOCK(hvt_list_lock); |
| 16 | static struct list_head hvt_list = LIST_HEAD_INIT(hvt_list); |
| 17 | |
| 18 | static void hvt_reset(struct hvutil_transport *hvt) |
| 19 | { |
Vitaly Kuznetsov | 14b50f8 | 2015-04-11 18:07:51 -0700 | [diff] [blame] | 20 | kfree(hvt->outmsg); |
| 21 | hvt->outmsg = NULL; |
| 22 | hvt->outmsg_len = 0; |
Vitaly Kuznetsov | 14b50f8 | 2015-04-11 18:07:51 -0700 | [diff] [blame] | 23 | if (hvt->on_reset) |
| 24 | hvt->on_reset(); |
| 25 | } |
| 26 | |
| 27 | static ssize_t hvt_op_read(struct file *file, char __user *buf, |
| 28 | size_t count, loff_t *ppos) |
| 29 | { |
| 30 | struct hvutil_transport *hvt; |
| 31 | int ret; |
| 32 | |
| 33 | hvt = container_of(file->f_op, struct hvutil_transport, fops); |
| 34 | |
Vitaly Kuznetsov | a150256 | 2015-12-14 19:01:55 -0800 | [diff] [blame] | 35 | if (wait_event_interruptible(hvt->outmsg_q, hvt->outmsg_len > 0 || |
| 36 | hvt->mode != HVUTIL_TRANSPORT_CHARDEV)) |
Vitaly Kuznetsov | 14b50f8 | 2015-04-11 18:07:51 -0700 | [diff] [blame] | 37 | return -EINTR; |
| 38 | |
Vitaly Kuznetsov | a72f3a4 | 2015-12-14 19:01:54 -0800 | [diff] [blame] | 39 | mutex_lock(&hvt->lock); |
Vitaly Kuznetsov | a150256 | 2015-12-14 19:01:55 -0800 | [diff] [blame] | 40 | |
| 41 | if (hvt->mode == HVUTIL_TRANSPORT_DESTROY) { |
| 42 | ret = -EBADF; |
| 43 | goto out_unlock; |
| 44 | } |
| 45 | |
Vitaly Kuznetsov | 14b50f8 | 2015-04-11 18:07:51 -0700 | [diff] [blame] | 46 | if (!hvt->outmsg) { |
| 47 | ret = -EAGAIN; |
| 48 | goto out_unlock; |
| 49 | } |
| 50 | |
| 51 | if (count < hvt->outmsg_len) { |
| 52 | ret = -EINVAL; |
| 53 | goto out_unlock; |
| 54 | } |
| 55 | |
| 56 | if (!copy_to_user(buf, hvt->outmsg, hvt->outmsg_len)) |
| 57 | ret = hvt->outmsg_len; |
| 58 | else |
| 59 | ret = -EFAULT; |
| 60 | |
| 61 | kfree(hvt->outmsg); |
| 62 | hvt->outmsg = NULL; |
| 63 | hvt->outmsg_len = 0; |
| 64 | |
Vitaly Kuznetsov | e0fa3e5 | 2016-06-09 17:08:57 -0700 | [diff] [blame] | 65 | if (hvt->on_read) |
| 66 | hvt->on_read(); |
| 67 | hvt->on_read = NULL; |
| 68 | |
Vitaly Kuznetsov | 14b50f8 | 2015-04-11 18:07:51 -0700 | [diff] [blame] | 69 | out_unlock: |
Vitaly Kuznetsov | a72f3a4 | 2015-12-14 19:01:54 -0800 | [diff] [blame] | 70 | mutex_unlock(&hvt->lock); |
Vitaly Kuznetsov | 14b50f8 | 2015-04-11 18:07:51 -0700 | [diff] [blame] | 71 | return ret; |
| 72 | } |
| 73 | |
| 74 | static ssize_t hvt_op_write(struct file *file, const char __user *buf, |
| 75 | size_t count, loff_t *ppos) |
| 76 | { |
| 77 | struct hvutil_transport *hvt; |
| 78 | u8 *inmsg; |
Vitaly Kuznetsov | 1f75338 | 2015-12-14 19:01:53 -0800 | [diff] [blame] | 79 | int ret; |
Vitaly Kuznetsov | 14b50f8 | 2015-04-11 18:07:51 -0700 | [diff] [blame] | 80 | |
| 81 | hvt = container_of(file->f_op, struct hvutil_transport, fops); |
| 82 | |
Olaf Hering | b003596 | 2015-12-14 16:01:37 -0800 | [diff] [blame] | 83 | inmsg = memdup_user(buf, count); |
| 84 | if (IS_ERR(inmsg)) |
| 85 | return PTR_ERR(inmsg); |
| 86 | |
Vitaly Kuznetsov | a150256 | 2015-12-14 19:01:55 -0800 | [diff] [blame] | 87 | if (hvt->mode == HVUTIL_TRANSPORT_DESTROY) |
| 88 | ret = -EBADF; |
| 89 | else |
| 90 | ret = hvt->on_msg(inmsg, count); |
Vitaly Kuznetsov | 1f75338 | 2015-12-14 19:01:53 -0800 | [diff] [blame] | 91 | |
Vitaly Kuznetsov | 14b50f8 | 2015-04-11 18:07:51 -0700 | [diff] [blame] | 92 | kfree(inmsg); |
| 93 | |
Vitaly Kuznetsov | 1f75338 | 2015-12-14 19:01:53 -0800 | [diff] [blame] | 94 | return ret ? ret : count; |
Vitaly Kuznetsov | 14b50f8 | 2015-04-11 18:07:51 -0700 | [diff] [blame] | 95 | } |
| 96 | |
Al Viro | afc9a42 | 2017-07-03 06:39:46 -0400 | [diff] [blame] | 97 | static __poll_t hvt_op_poll(struct file *file, poll_table *wait) |
Vitaly Kuznetsov | 14b50f8 | 2015-04-11 18:07:51 -0700 | [diff] [blame] | 98 | { |
| 99 | struct hvutil_transport *hvt; |
| 100 | |
| 101 | hvt = container_of(file->f_op, struct hvutil_transport, fops); |
| 102 | |
| 103 | poll_wait(file, &hvt->outmsg_q, wait); |
Vitaly Kuznetsov | a150256 | 2015-12-14 19:01:55 -0800 | [diff] [blame] | 104 | |
| 105 | if (hvt->mode == HVUTIL_TRANSPORT_DESTROY) |
Linus Torvalds | a9a0884 | 2018-02-11 14:34:03 -0800 | [diff] [blame] | 106 | return EPOLLERR | EPOLLHUP; |
Vitaly Kuznetsov | a150256 | 2015-12-14 19:01:55 -0800 | [diff] [blame] | 107 | |
Vitaly Kuznetsov | 14b50f8 | 2015-04-11 18:07:51 -0700 | [diff] [blame] | 108 | if (hvt->outmsg_len > 0) |
Linus Torvalds | a9a0884 | 2018-02-11 14:34:03 -0800 | [diff] [blame] | 109 | return EPOLLIN | EPOLLRDNORM; |
Vitaly Kuznetsov | 14b50f8 | 2015-04-11 18:07:51 -0700 | [diff] [blame] | 110 | |
| 111 | return 0; |
| 112 | } |
| 113 | |
| 114 | static int hvt_op_open(struct inode *inode, struct file *file) |
| 115 | { |
| 116 | struct hvutil_transport *hvt; |
Vitaly Kuznetsov | a150256 | 2015-12-14 19:01:55 -0800 | [diff] [blame] | 117 | int ret = 0; |
| 118 | bool issue_reset = false; |
Vitaly Kuznetsov | 14b50f8 | 2015-04-11 18:07:51 -0700 | [diff] [blame] | 119 | |
| 120 | hvt = container_of(file->f_op, struct hvutil_transport, fops); |
| 121 | |
Vitaly Kuznetsov | a150256 | 2015-12-14 19:01:55 -0800 | [diff] [blame] | 122 | mutex_lock(&hvt->lock); |
| 123 | |
| 124 | if (hvt->mode == HVUTIL_TRANSPORT_DESTROY) { |
| 125 | ret = -EBADF; |
| 126 | } else if (hvt->mode == HVUTIL_TRANSPORT_INIT) { |
| 127 | /* |
| 128 | * Switching to CHARDEV mode. We switch bach to INIT when |
| 129 | * device gets released. |
| 130 | */ |
Vitaly Kuznetsov | 14b50f8 | 2015-04-11 18:07:51 -0700 | [diff] [blame] | 131 | hvt->mode = HVUTIL_TRANSPORT_CHARDEV; |
Vitaly Kuznetsov | a150256 | 2015-12-14 19:01:55 -0800 | [diff] [blame] | 132 | } |
Vitaly Kuznetsov | 14b50f8 | 2015-04-11 18:07:51 -0700 | [diff] [blame] | 133 | else if (hvt->mode == HVUTIL_TRANSPORT_NETLINK) { |
| 134 | /* |
| 135 | * We're switching from netlink communication to using char |
| 136 | * device. Issue the reset first. |
| 137 | */ |
Vitaly Kuznetsov | a150256 | 2015-12-14 19:01:55 -0800 | [diff] [blame] | 138 | issue_reset = true; |
Vitaly Kuznetsov | 14b50f8 | 2015-04-11 18:07:51 -0700 | [diff] [blame] | 139 | hvt->mode = HVUTIL_TRANSPORT_CHARDEV; |
Vitaly Kuznetsov | a150256 | 2015-12-14 19:01:55 -0800 | [diff] [blame] | 140 | } else { |
| 141 | ret = -EBUSY; |
| 142 | } |
Vitaly Kuznetsov | 14b50f8 | 2015-04-11 18:07:51 -0700 | [diff] [blame] | 143 | |
Vitaly Kuznetsov | a150256 | 2015-12-14 19:01:55 -0800 | [diff] [blame] | 144 | if (issue_reset) |
| 145 | hvt_reset(hvt); |
| 146 | |
| 147 | mutex_unlock(&hvt->lock); |
| 148 | |
| 149 | return ret; |
Vitaly Kuznetsov | 14b50f8 | 2015-04-11 18:07:51 -0700 | [diff] [blame] | 150 | } |
| 151 | |
Vitaly Kuznetsov | 9420098 | 2015-12-14 19:01:56 -0800 | [diff] [blame] | 152 | static void hvt_transport_free(struct hvutil_transport *hvt) |
| 153 | { |
| 154 | misc_deregister(&hvt->mdev); |
| 155 | kfree(hvt->outmsg); |
| 156 | kfree(hvt); |
| 157 | } |
| 158 | |
Vitaly Kuznetsov | 14b50f8 | 2015-04-11 18:07:51 -0700 | [diff] [blame] | 159 | static int hvt_op_release(struct inode *inode, struct file *file) |
| 160 | { |
| 161 | struct hvutil_transport *hvt; |
Vitaly Kuznetsov | 9420098 | 2015-12-14 19:01:56 -0800 | [diff] [blame] | 162 | int mode_old; |
Vitaly Kuznetsov | 14b50f8 | 2015-04-11 18:07:51 -0700 | [diff] [blame] | 163 | |
| 164 | hvt = container_of(file->f_op, struct hvutil_transport, fops); |
| 165 | |
Vitaly Kuznetsov | a150256 | 2015-12-14 19:01:55 -0800 | [diff] [blame] | 166 | mutex_lock(&hvt->lock); |
Vitaly Kuznetsov | 9420098 | 2015-12-14 19:01:56 -0800 | [diff] [blame] | 167 | mode_old = hvt->mode; |
Vitaly Kuznetsov | a150256 | 2015-12-14 19:01:55 -0800 | [diff] [blame] | 168 | if (hvt->mode != HVUTIL_TRANSPORT_DESTROY) |
| 169 | hvt->mode = HVUTIL_TRANSPORT_INIT; |
Vitaly Kuznetsov | 14b50f8 | 2015-04-11 18:07:51 -0700 | [diff] [blame] | 170 | /* |
| 171 | * Cleanup message buffers to avoid spurious messages when the daemon |
| 172 | * connects back. |
| 173 | */ |
| 174 | hvt_reset(hvt); |
| 175 | |
Vitaly Kuznetsov | 9420098 | 2015-12-14 19:01:56 -0800 | [diff] [blame] | 176 | if (mode_old == HVUTIL_TRANSPORT_DESTROY) |
Vitaly Kuznetsov | e9c18ae | 2017-03-04 18:13:59 -0700 | [diff] [blame] | 177 | complete(&hvt->release); |
| 178 | |
| 179 | mutex_unlock(&hvt->lock); |
Vitaly Kuznetsov | 9420098 | 2015-12-14 19:01:56 -0800 | [diff] [blame] | 180 | |
Vitaly Kuznetsov | 14b50f8 | 2015-04-11 18:07:51 -0700 | [diff] [blame] | 181 | return 0; |
| 182 | } |
| 183 | |
| 184 | static void hvt_cn_callback(struct cn_msg *msg, struct netlink_skb_parms *nsp) |
| 185 | { |
| 186 | struct hvutil_transport *hvt, *hvt_found = NULL; |
| 187 | |
| 188 | spin_lock(&hvt_list_lock); |
| 189 | list_for_each_entry(hvt, &hvt_list, list) { |
| 190 | if (hvt->cn_id.idx == msg->id.idx && |
| 191 | hvt->cn_id.val == msg->id.val) { |
| 192 | hvt_found = hvt; |
| 193 | break; |
| 194 | } |
| 195 | } |
| 196 | spin_unlock(&hvt_list_lock); |
| 197 | if (!hvt_found) { |
| 198 | pr_warn("hvt_cn_callback: spurious message received!\n"); |
| 199 | return; |
| 200 | } |
| 201 | |
| 202 | /* |
| 203 | * Switching to NETLINK mode. Switching to CHARDEV happens when someone |
| 204 | * opens the device. |
| 205 | */ |
Vitaly Kuznetsov | a150256 | 2015-12-14 19:01:55 -0800 | [diff] [blame] | 206 | mutex_lock(&hvt->lock); |
Vitaly Kuznetsov | 14b50f8 | 2015-04-11 18:07:51 -0700 | [diff] [blame] | 207 | if (hvt->mode == HVUTIL_TRANSPORT_INIT) |
| 208 | hvt->mode = HVUTIL_TRANSPORT_NETLINK; |
| 209 | |
| 210 | if (hvt->mode == HVUTIL_TRANSPORT_NETLINK) |
| 211 | hvt_found->on_msg(msg->data, msg->len); |
| 212 | else |
| 213 | pr_warn("hvt_cn_callback: unexpected netlink message!\n"); |
Vitaly Kuznetsov | a150256 | 2015-12-14 19:01:55 -0800 | [diff] [blame] | 214 | mutex_unlock(&hvt->lock); |
Vitaly Kuznetsov | 14b50f8 | 2015-04-11 18:07:51 -0700 | [diff] [blame] | 215 | } |
| 216 | |
Vitaly Kuznetsov | e0fa3e5 | 2016-06-09 17:08:57 -0700 | [diff] [blame] | 217 | int hvutil_transport_send(struct hvutil_transport *hvt, void *msg, int len, |
| 218 | void (*on_read_cb)(void)) |
Vitaly Kuznetsov | 14b50f8 | 2015-04-11 18:07:51 -0700 | [diff] [blame] | 219 | { |
| 220 | struct cn_msg *cn_msg; |
| 221 | int ret = 0; |
| 222 | |
Vitaly Kuznetsov | a150256 | 2015-12-14 19:01:55 -0800 | [diff] [blame] | 223 | if (hvt->mode == HVUTIL_TRANSPORT_INIT || |
| 224 | hvt->mode == HVUTIL_TRANSPORT_DESTROY) { |
Vitaly Kuznetsov | 14b50f8 | 2015-04-11 18:07:51 -0700 | [diff] [blame] | 225 | return -EINVAL; |
| 226 | } else if (hvt->mode == HVUTIL_TRANSPORT_NETLINK) { |
| 227 | cn_msg = kzalloc(sizeof(*cn_msg) + len, GFP_ATOMIC); |
Dan Carpenter | 9dd6a06 | 2015-08-01 16:08:17 -0700 | [diff] [blame] | 228 | if (!cn_msg) |
Vitaly Kuznetsov | 14b50f8 | 2015-04-11 18:07:51 -0700 | [diff] [blame] | 229 | return -ENOMEM; |
| 230 | cn_msg->id.idx = hvt->cn_id.idx; |
| 231 | cn_msg->id.val = hvt->cn_id.val; |
| 232 | cn_msg->len = len; |
| 233 | memcpy(cn_msg->data, msg, len); |
| 234 | ret = cn_netlink_send(cn_msg, 0, 0, GFP_ATOMIC); |
| 235 | kfree(cn_msg); |
Vitaly Kuznetsov | e0fa3e5 | 2016-06-09 17:08:57 -0700 | [diff] [blame] | 236 | /* |
| 237 | * We don't know when netlink messages are delivered but unlike |
| 238 | * in CHARDEV mode we're not blocked and we can send next |
| 239 | * messages right away. |
| 240 | */ |
| 241 | if (on_read_cb) |
| 242 | on_read_cb(); |
Vitaly Kuznetsov | 14b50f8 | 2015-04-11 18:07:51 -0700 | [diff] [blame] | 243 | return ret; |
| 244 | } |
| 245 | /* HVUTIL_TRANSPORT_CHARDEV */ |
Vitaly Kuznetsov | a72f3a4 | 2015-12-14 19:01:54 -0800 | [diff] [blame] | 246 | mutex_lock(&hvt->lock); |
Vitaly Kuznetsov | a150256 | 2015-12-14 19:01:55 -0800 | [diff] [blame] | 247 | if (hvt->mode != HVUTIL_TRANSPORT_CHARDEV) { |
| 248 | ret = -EINVAL; |
| 249 | goto out_unlock; |
| 250 | } |
| 251 | |
Vitaly Kuznetsov | 14b50f8 | 2015-04-11 18:07:51 -0700 | [diff] [blame] | 252 | if (hvt->outmsg) { |
| 253 | /* Previous message wasn't received */ |
| 254 | ret = -EFAULT; |
| 255 | goto out_unlock; |
| 256 | } |
| 257 | hvt->outmsg = kzalloc(len, GFP_KERNEL); |
Olaf Hering | cdc0c0c | 2015-12-14 16:01:36 -0800 | [diff] [blame] | 258 | if (hvt->outmsg) { |
| 259 | memcpy(hvt->outmsg, msg, len); |
| 260 | hvt->outmsg_len = len; |
Vitaly Kuznetsov | e0fa3e5 | 2016-06-09 17:08:57 -0700 | [diff] [blame] | 261 | hvt->on_read = on_read_cb; |
Olaf Hering | cdc0c0c | 2015-12-14 16:01:36 -0800 | [diff] [blame] | 262 | wake_up_interruptible(&hvt->outmsg_q); |
| 263 | } else |
| 264 | ret = -ENOMEM; |
Vitaly Kuznetsov | 14b50f8 | 2015-04-11 18:07:51 -0700 | [diff] [blame] | 265 | out_unlock: |
Vitaly Kuznetsov | a72f3a4 | 2015-12-14 19:01:54 -0800 | [diff] [blame] | 266 | mutex_unlock(&hvt->lock); |
Vitaly Kuznetsov | 14b50f8 | 2015-04-11 18:07:51 -0700 | [diff] [blame] | 267 | return ret; |
| 268 | } |
| 269 | |
| 270 | struct hvutil_transport *hvutil_transport_init(const char *name, |
| 271 | u32 cn_idx, u32 cn_val, |
| 272 | int (*on_msg)(void *, int), |
| 273 | void (*on_reset)(void)) |
| 274 | { |
| 275 | struct hvutil_transport *hvt; |
| 276 | |
| 277 | hvt = kzalloc(sizeof(*hvt), GFP_KERNEL); |
| 278 | if (!hvt) |
| 279 | return NULL; |
| 280 | |
| 281 | hvt->cn_id.idx = cn_idx; |
| 282 | hvt->cn_id.val = cn_val; |
| 283 | |
| 284 | hvt->mdev.minor = MISC_DYNAMIC_MINOR; |
| 285 | hvt->mdev.name = name; |
| 286 | |
| 287 | hvt->fops.owner = THIS_MODULE; |
| 288 | hvt->fops.read = hvt_op_read; |
| 289 | hvt->fops.write = hvt_op_write; |
| 290 | hvt->fops.poll = hvt_op_poll; |
| 291 | hvt->fops.open = hvt_op_open; |
| 292 | hvt->fops.release = hvt_op_release; |
| 293 | |
| 294 | hvt->mdev.fops = &hvt->fops; |
| 295 | |
| 296 | init_waitqueue_head(&hvt->outmsg_q); |
Vitaly Kuznetsov | a72f3a4 | 2015-12-14 19:01:54 -0800 | [diff] [blame] | 297 | mutex_init(&hvt->lock); |
Vitaly Kuznetsov | e9c18ae | 2017-03-04 18:13:59 -0700 | [diff] [blame] | 298 | init_completion(&hvt->release); |
Vitaly Kuznetsov | 14b50f8 | 2015-04-11 18:07:51 -0700 | [diff] [blame] | 299 | |
| 300 | spin_lock(&hvt_list_lock); |
| 301 | list_add(&hvt->list, &hvt_list); |
| 302 | spin_unlock(&hvt_list_lock); |
| 303 | |
| 304 | hvt->on_msg = on_msg; |
| 305 | hvt->on_reset = on_reset; |
| 306 | |
| 307 | if (misc_register(&hvt->mdev)) |
| 308 | goto err_free_hvt; |
| 309 | |
| 310 | /* Use cn_id.idx/cn_id.val to determine if we need to setup netlink */ |
| 311 | if (hvt->cn_id.idx > 0 && hvt->cn_id.val > 0 && |
| 312 | cn_add_callback(&hvt->cn_id, name, hvt_cn_callback)) |
| 313 | goto err_free_hvt; |
| 314 | |
| 315 | return hvt; |
| 316 | |
| 317 | err_free_hvt: |
Alex Ng | e66853b | 2016-02-26 15:13:20 -0800 | [diff] [blame] | 318 | spin_lock(&hvt_list_lock); |
| 319 | list_del(&hvt->list); |
| 320 | spin_unlock(&hvt_list_lock); |
Vitaly Kuznetsov | 14b50f8 | 2015-04-11 18:07:51 -0700 | [diff] [blame] | 321 | kfree(hvt); |
| 322 | return NULL; |
| 323 | } |
| 324 | |
| 325 | void hvutil_transport_destroy(struct hvutil_transport *hvt) |
| 326 | { |
Vitaly Kuznetsov | 9420098 | 2015-12-14 19:01:56 -0800 | [diff] [blame] | 327 | int mode_old; |
| 328 | |
Vitaly Kuznetsov | a150256 | 2015-12-14 19:01:55 -0800 | [diff] [blame] | 329 | mutex_lock(&hvt->lock); |
Vitaly Kuznetsov | 9420098 | 2015-12-14 19:01:56 -0800 | [diff] [blame] | 330 | mode_old = hvt->mode; |
Vitaly Kuznetsov | a150256 | 2015-12-14 19:01:55 -0800 | [diff] [blame] | 331 | hvt->mode = HVUTIL_TRANSPORT_DESTROY; |
| 332 | wake_up_interruptible(&hvt->outmsg_q); |
| 333 | mutex_unlock(&hvt->lock); |
| 334 | |
Vitaly Kuznetsov | 9420098 | 2015-12-14 19:01:56 -0800 | [diff] [blame] | 335 | /* |
| 336 | * In case we were in 'chardev' mode we still have an open fd so we |
| 337 | * have to defer freeing the device. Netlink interface can be freed |
| 338 | * now. |
| 339 | */ |
Vitaly Kuznetsov | 14b50f8 | 2015-04-11 18:07:51 -0700 | [diff] [blame] | 340 | spin_lock(&hvt_list_lock); |
| 341 | list_del(&hvt->list); |
| 342 | spin_unlock(&hvt_list_lock); |
| 343 | if (hvt->cn_id.idx > 0 && hvt->cn_id.val > 0) |
| 344 | cn_del_callback(&hvt->cn_id); |
Vitaly Kuznetsov | 9420098 | 2015-12-14 19:01:56 -0800 | [diff] [blame] | 345 | |
Vitaly Kuznetsov | e9c18ae | 2017-03-04 18:13:59 -0700 | [diff] [blame] | 346 | if (mode_old == HVUTIL_TRANSPORT_CHARDEV) |
| 347 | wait_for_completion(&hvt->release); |
| 348 | |
| 349 | hvt_transport_free(hvt); |
Vitaly Kuznetsov | 14b50f8 | 2015-04-11 18:07:51 -0700 | [diff] [blame] | 350 | } |