Greg Kroah-Hartman | 5fd54ac | 2017-11-03 11:28:30 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Takahiro Hirofuchi | 4d7b5c7 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2003-2008 Takahiro Hirofuchi |
Takahiro Hirofuchi | 4d7b5c7 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 4 | */ |
| 5 | |
matt mooney | 7aaacb4 | 2011-05-11 22:33:43 -0700 | [diff] [blame] | 6 | #include <linux/string.h> |
Paul Gortmaker | 99c9785 | 2011-07-03 15:49:50 -0400 | [diff] [blame] | 7 | #include <linux/module.h> |
Valentina Manea | a46034c | 2014-03-08 14:53:33 +0200 | [diff] [blame] | 8 | #include <linux/device.h> |
Takahiro Hirofuchi | 4d7b5c7 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 9 | |
| 10 | #include "usbip_common.h" |
| 11 | #include "stub.h" |
| 12 | |
Takahiro Hirofuchi | 4d7b5c7 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 13 | #define DRIVER_AUTHOR "Takahiro Hirofuchi" |
matt mooney | 64e6242 | 2011-05-11 22:33:44 -0700 | [diff] [blame] | 14 | #define DRIVER_DESC "USB/IP Host Driver" |
Takahiro Hirofuchi | 4d7b5c7 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 15 | |
Takahiro Hirofuchi | 4d7b5c7 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 16 | struct kmem_cache *stub_priv_cache; |
Takahiro Hirofuchi | 4d7b5c7 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 17 | /* |
| 18 | * busid_tables defines matching busids that usbip can grab. A user can change |
| 19 | * dynamically what device is locally used and what device is exported to a |
| 20 | * remote host. |
| 21 | */ |
| 22 | #define MAX_BUSID 16 |
Endre Kollar | aa5873e | 2010-07-27 12:39:30 +0200 | [diff] [blame] | 23 | static struct bus_id_priv busid_table[MAX_BUSID]; |
Takahiro Hirofuchi | 4d7b5c7 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 24 | static spinlock_t busid_table_lock; |
| 25 | |
matt mooney | efad25e | 2011-05-19 21:36:57 -0700 | [diff] [blame] | 26 | static void init_busid_table(void) |
| 27 | { |
Kurt Kanzenbach | 521e1e7 | 2013-04-04 16:03:10 +0200 | [diff] [blame] | 28 | /* |
| 29 | * This also sets the bus_table[i].status to |
| 30 | * STUB_BUSID_OTHER, which is 0. |
| 31 | */ |
matt mooney | 0a186be | 2011-05-27 01:49:24 -0700 | [diff] [blame] | 32 | memset(busid_table, 0, sizeof(busid_table)); |
matt mooney | efad25e | 2011-05-19 21:36:57 -0700 | [diff] [blame] | 33 | |
| 34 | spin_lock_init(&busid_table_lock); |
| 35 | } |
| 36 | |
matt mooney | 41e02f0 | 2011-05-19 21:36:58 -0700 | [diff] [blame] | 37 | /* |
| 38 | * Find the index of the busid by name. |
| 39 | * Must be called with busid_table_lock held. |
| 40 | */ |
| 41 | static int get_busid_idx(const char *busid) |
Takahiro Hirofuchi | 4d7b5c7 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 42 | { |
| 43 | int i; |
matt mooney | 41e02f0 | 2011-05-19 21:36:58 -0700 | [diff] [blame] | 44 | int idx = -1; |
Takahiro Hirofuchi | 4d7b5c7 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 45 | |
Takahiro Hirofuchi | 4d7b5c7 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 46 | for (i = 0; i < MAX_BUSID; i++) |
Endre Kollar | aa5873e | 2010-07-27 12:39:30 +0200 | [diff] [blame] | 47 | if (busid_table[i].name[0]) |
| 48 | if (!strncmp(busid_table[i].name, busid, BUSID_SIZE)) { |
matt mooney | 41e02f0 | 2011-05-19 21:36:58 -0700 | [diff] [blame] | 49 | idx = i; |
| 50 | break; |
Takahiro Hirofuchi | 4d7b5c7 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 51 | } |
matt mooney | 41e02f0 | 2011-05-19 21:36:58 -0700 | [diff] [blame] | 52 | return idx; |
Takahiro Hirofuchi | 4d7b5c7 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 53 | } |
| 54 | |
Endre Kollar | aa5873e | 2010-07-27 12:39:30 +0200 | [diff] [blame] | 55 | struct bus_id_priv *get_busid_priv(const char *busid) |
| 56 | { |
matt mooney | 41e02f0 | 2011-05-19 21:36:58 -0700 | [diff] [blame] | 57 | int idx; |
| 58 | struct bus_id_priv *bid = NULL; |
Endre Kollar | aa5873e | 2010-07-27 12:39:30 +0200 | [diff] [blame] | 59 | |
| 60 | spin_lock(&busid_table_lock); |
matt mooney | 41e02f0 | 2011-05-19 21:36:58 -0700 | [diff] [blame] | 61 | idx = get_busid_idx(busid); |
| 62 | if (idx >= 0) |
| 63 | bid = &(busid_table[idx]); |
Endre Kollar | aa5873e | 2010-07-27 12:39:30 +0200 | [diff] [blame] | 64 | spin_unlock(&busid_table_lock); |
| 65 | |
matt mooney | 41e02f0 | 2011-05-19 21:36:58 -0700 | [diff] [blame] | 66 | return bid; |
Endre Kollar | aa5873e | 2010-07-27 12:39:30 +0200 | [diff] [blame] | 67 | } |
| 68 | |
Takahiro Hirofuchi | 4d7b5c7 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 69 | static int add_match_busid(char *busid) |
| 70 | { |
| 71 | int i; |
matt mooney | 41e02f0 | 2011-05-19 21:36:58 -0700 | [diff] [blame] | 72 | int ret = -1; |
Takahiro Hirofuchi | 4d7b5c7 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 73 | |
| 74 | spin_lock(&busid_table_lock); |
matt mooney | 41e02f0 | 2011-05-19 21:36:58 -0700 | [diff] [blame] | 75 | /* already registered? */ |
| 76 | if (get_busid_idx(busid) >= 0) { |
| 77 | ret = 0; |
| 78 | goto out; |
| 79 | } |
| 80 | |
Takahiro Hirofuchi | 4d7b5c7 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 81 | for (i = 0; i < MAX_BUSID; i++) |
Endre Kollar | aa5873e | 2010-07-27 12:39:30 +0200 | [diff] [blame] | 82 | if (!busid_table[i].name[0]) { |
Rickard Strandqvist | 96955ed | 2014-07-26 16:43:20 +0200 | [diff] [blame] | 83 | strlcpy(busid_table[i].name, busid, BUSID_SIZE); |
Endre Kollar | aa5873e | 2010-07-27 12:39:30 +0200 | [diff] [blame] | 84 | if ((busid_table[i].status != STUB_BUSID_ALLOC) && |
| 85 | (busid_table[i].status != STUB_BUSID_REMOV)) |
| 86 | busid_table[i].status = STUB_BUSID_ADDED; |
matt mooney | 41e02f0 | 2011-05-19 21:36:58 -0700 | [diff] [blame] | 87 | ret = 0; |
| 88 | break; |
Takahiro Hirofuchi | 4d7b5c7 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 89 | } |
matt mooney | 41e02f0 | 2011-05-19 21:36:58 -0700 | [diff] [blame] | 90 | |
| 91 | out: |
Takahiro Hirofuchi | 4d7b5c7 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 92 | spin_unlock(&busid_table_lock); |
| 93 | |
matt mooney | 41e02f0 | 2011-05-19 21:36:58 -0700 | [diff] [blame] | 94 | return ret; |
Takahiro Hirofuchi | 4d7b5c7 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 95 | } |
| 96 | |
Endre Kollar | aa5873e | 2010-07-27 12:39:30 +0200 | [diff] [blame] | 97 | int del_match_busid(char *busid) |
Takahiro Hirofuchi | 4d7b5c7 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 98 | { |
matt mooney | 41e02f0 | 2011-05-19 21:36:58 -0700 | [diff] [blame] | 99 | int idx; |
| 100 | int ret = -1; |
Takahiro Hirofuchi | 4d7b5c7 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 101 | |
| 102 | spin_lock(&busid_table_lock); |
matt mooney | 41e02f0 | 2011-05-19 21:36:58 -0700 | [diff] [blame] | 103 | idx = get_busid_idx(busid); |
| 104 | if (idx < 0) |
| 105 | goto out; |
| 106 | |
| 107 | /* found */ |
| 108 | ret = 0; |
| 109 | |
| 110 | if (busid_table[idx].status == STUB_BUSID_OTHER) |
| 111 | memset(busid_table[idx].name, 0, BUSID_SIZE); |
| 112 | |
| 113 | if ((busid_table[idx].status != STUB_BUSID_OTHER) && |
| 114 | (busid_table[idx].status != STUB_BUSID_ADDED)) |
| 115 | busid_table[idx].status = STUB_BUSID_REMOV; |
| 116 | |
| 117 | out: |
Takahiro Hirofuchi | 4d7b5c7 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 118 | spin_unlock(&busid_table_lock); |
| 119 | |
matt mooney | 41e02f0 | 2011-05-19 21:36:58 -0700 | [diff] [blame] | 120 | return ret; |
Takahiro Hirofuchi | 4d7b5c7 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 121 | } |
matt mooney | 6c033b4 | 2011-05-06 03:47:42 -0700 | [diff] [blame] | 122 | |
Greg Kroah-Hartman | cc3d53d | 2017-06-09 11:03:14 +0200 | [diff] [blame] | 123 | static ssize_t match_busid_show(struct device_driver *drv, char *buf) |
Endre Kollar | aa5873e | 2010-07-27 12:39:30 +0200 | [diff] [blame] | 124 | { |
| 125 | int i; |
matt mooney | efad25e | 2011-05-19 21:36:57 -0700 | [diff] [blame] | 126 | char *out = buf; |
Endre Kollar | aa5873e | 2010-07-27 12:39:30 +0200 | [diff] [blame] | 127 | |
matt mooney | efad25e | 2011-05-19 21:36:57 -0700 | [diff] [blame] | 128 | spin_lock(&busid_table_lock); |
| 129 | for (i = 0; i < MAX_BUSID; i++) |
| 130 | if (busid_table[i].name[0]) |
| 131 | out += sprintf(out, "%s ", busid_table[i].name); |
| 132 | spin_unlock(&busid_table_lock); |
matt mooney | efad25e | 2011-05-19 21:36:57 -0700 | [diff] [blame] | 133 | out += sprintf(out, "\n"); |
matt mooney | 41e02f0 | 2011-05-19 21:36:58 -0700 | [diff] [blame] | 134 | |
matt mooney | efad25e | 2011-05-19 21:36:57 -0700 | [diff] [blame] | 135 | return out - buf; |
Endre Kollar | aa5873e | 2010-07-27 12:39:30 +0200 | [diff] [blame] | 136 | } |
Takahiro Hirofuchi | 4d7b5c7 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 137 | |
Greg Kroah-Hartman | cc3d53d | 2017-06-09 11:03:14 +0200 | [diff] [blame] | 138 | static ssize_t match_busid_store(struct device_driver *dev, const char *buf, |
matt mooney | 6c033b4 | 2011-05-06 03:47:42 -0700 | [diff] [blame] | 139 | size_t count) |
Takahiro Hirofuchi | 4d7b5c7 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 140 | { |
| 141 | int len; |
Kay Sievers | e913397 | 2008-10-30 01:59:32 +0100 | [diff] [blame] | 142 | char busid[BUSID_SIZE]; |
Takahiro Hirofuchi | 4d7b5c7 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 143 | |
| 144 | if (count < 5) |
| 145 | return -EINVAL; |
| 146 | |
Takahiro Hirofuchi | 4d7b5c7 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 147 | /* busid needs to include \0 termination */ |
Rickard Strandqvist | 96955ed | 2014-07-26 16:43:20 +0200 | [diff] [blame] | 148 | len = strlcpy(busid, buf + 4, BUSID_SIZE); |
| 149 | if (sizeof(busid) <= len) |
Takahiro Hirofuchi | 4d7b5c7 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 150 | return -EINVAL; |
| 151 | |
Takahiro Hirofuchi | 4d7b5c7 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 152 | if (!strncmp(buf, "add ", 4)) { |
Kurt Kanzenbach | 2183b77 | 2013-04-04 16:03:09 +0200 | [diff] [blame] | 153 | if (add_match_busid(busid) < 0) |
Takahiro Hirofuchi | 4d7b5c7 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 154 | return -ENOMEM; |
Kurt Kanzenbach | 2183b77 | 2013-04-04 16:03:09 +0200 | [diff] [blame] | 155 | |
| 156 | pr_debug("add busid %s\n", busid); |
| 157 | return count; |
matt mooney | 41e02f0 | 2011-05-19 21:36:58 -0700 | [diff] [blame] | 158 | } |
Kurt Kanzenbach | 2183b77 | 2013-04-04 16:03:09 +0200 | [diff] [blame] | 159 | |
| 160 | if (!strncmp(buf, "del ", 4)) { |
| 161 | if (del_match_busid(busid) < 0) |
| 162 | return -ENODEV; |
| 163 | |
| 164 | pr_debug("del busid %s\n", busid); |
| 165 | return count; |
| 166 | } |
| 167 | |
| 168 | return -EINVAL; |
Takahiro Hirofuchi | 4d7b5c7 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 169 | } |
Greg Kroah-Hartman | cc3d53d | 2017-06-09 11:03:14 +0200 | [diff] [blame] | 170 | static DRIVER_ATTR_RW(match_busid); |
Takahiro Hirofuchi | 4d7b5c7 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 171 | |
Valentina Manea | a46034c | 2014-03-08 14:53:33 +0200 | [diff] [blame] | 172 | static ssize_t rebind_store(struct device_driver *dev, const char *buf, |
| 173 | size_t count) |
| 174 | { |
| 175 | int ret; |
| 176 | int len; |
| 177 | struct bus_id_priv *bid; |
| 178 | |
| 179 | /* buf length should be less that BUSID_SIZE */ |
| 180 | len = strnlen(buf, BUSID_SIZE); |
| 181 | |
| 182 | if (!(len < BUSID_SIZE)) |
| 183 | return -EINVAL; |
| 184 | |
| 185 | bid = get_busid_priv(buf); |
| 186 | if (!bid) |
| 187 | return -ENODEV; |
| 188 | |
| 189 | ret = device_attach(&bid->udev->dev); |
| 190 | if (ret < 0) { |
| 191 | dev_err(&bid->udev->dev, "rebind failed\n"); |
| 192 | return ret; |
| 193 | } |
| 194 | |
| 195 | return count; |
| 196 | } |
| 197 | |
| 198 | static DRIVER_ATTR_WO(rebind); |
| 199 | |
Takahiro Hirofuchi | 4d7b5c7 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 200 | static struct stub_priv *stub_priv_pop_from_listhead(struct list_head *listhead) |
| 201 | { |
| 202 | struct stub_priv *priv, *tmp; |
| 203 | |
| 204 | list_for_each_entry_safe(priv, tmp, listhead, list) { |
| 205 | list_del(&priv->list); |
| 206 | return priv; |
| 207 | } |
| 208 | |
| 209 | return NULL; |
| 210 | } |
| 211 | |
| 212 | static struct stub_priv *stub_priv_pop(struct stub_device *sdev) |
| 213 | { |
| 214 | unsigned long flags; |
| 215 | struct stub_priv *priv; |
| 216 | |
| 217 | spin_lock_irqsave(&sdev->priv_lock, flags); |
| 218 | |
| 219 | priv = stub_priv_pop_from_listhead(&sdev->priv_init); |
matt mooney | 41e02f0 | 2011-05-19 21:36:58 -0700 | [diff] [blame] | 220 | if (priv) |
| 221 | goto done; |
Takahiro Hirofuchi | 4d7b5c7 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 222 | |
| 223 | priv = stub_priv_pop_from_listhead(&sdev->priv_tx); |
matt mooney | 41e02f0 | 2011-05-19 21:36:58 -0700 | [diff] [blame] | 224 | if (priv) |
| 225 | goto done; |
Takahiro Hirofuchi | 4d7b5c7 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 226 | |
| 227 | priv = stub_priv_pop_from_listhead(&sdev->priv_free); |
Takahiro Hirofuchi | 4d7b5c7 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 228 | |
matt mooney | 41e02f0 | 2011-05-19 21:36:58 -0700 | [diff] [blame] | 229 | done: |
Takahiro Hirofuchi | 4d7b5c7 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 230 | spin_unlock_irqrestore(&sdev->priv_lock, flags); |
matt mooney | 41e02f0 | 2011-05-19 21:36:58 -0700 | [diff] [blame] | 231 | |
| 232 | return priv; |
Takahiro Hirofuchi | 4d7b5c7 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | void stub_device_cleanup_urbs(struct stub_device *sdev) |
| 236 | { |
| 237 | struct stub_priv *priv; |
matt mooney | 41e02f0 | 2011-05-19 21:36:58 -0700 | [diff] [blame] | 238 | struct urb *urb; |
Takahiro Hirofuchi | 4d7b5c7 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 239 | |
Shuah Khan | 248a220 | 2017-12-18 17:23:37 -0700 | [diff] [blame] | 240 | dev_dbg(&sdev->udev->dev, "Stub device cleaning up urbs\n"); |
Takahiro Hirofuchi | 4d7b5c7 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 241 | |
| 242 | while ((priv = stub_priv_pop(sdev))) { |
matt mooney | 41e02f0 | 2011-05-19 21:36:58 -0700 | [diff] [blame] | 243 | urb = priv->urb; |
Shuah Khan | 248a220 | 2017-12-18 17:23:37 -0700 | [diff] [blame] | 244 | dev_dbg(&sdev->udev->dev, "free urb seqnum %lu\n", |
| 245 | priv->seqnum); |
Takahiro Hirofuchi | 4d7b5c7 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 246 | usb_kill_urb(urb); |
| 247 | |
| 248 | kmem_cache_free(stub_priv_cache, priv); |
| 249 | |
Ilia Mirkin | 06dde50 | 2011-03-13 00:29:12 -0500 | [diff] [blame] | 250 | kfree(urb->transfer_buffer); |
Michael Grzeschik | b3b5141 | 2017-05-22 13:02:44 +0200 | [diff] [blame] | 251 | urb->transfer_buffer = NULL; |
| 252 | |
Ilia Mirkin | 06dde50 | 2011-03-13 00:29:12 -0500 | [diff] [blame] | 253 | kfree(urb->setup_packet); |
Michael Grzeschik | b3b5141 | 2017-05-22 13:02:44 +0200 | [diff] [blame] | 254 | urb->setup_packet = NULL; |
| 255 | |
Takahiro Hirofuchi | 4d7b5c7 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 256 | usb_free_urb(urb); |
| 257 | } |
| 258 | } |
| 259 | |
matt mooney | 27ed5da | 2011-05-19 21:36:59 -0700 | [diff] [blame] | 260 | static int __init usbip_host_init(void) |
Takahiro Hirofuchi | 4d7b5c7 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 261 | { |
| 262 | int ret; |
| 263 | |
Bart Westgeest | 737912e | 2012-01-25 13:46:32 -0500 | [diff] [blame] | 264 | init_busid_table(); |
matt mooney | 7d4de89 | 2011-05-19 21:37:00 -0700 | [diff] [blame] | 265 | |
Bart Westgeest | 737912e | 2012-01-25 13:46:32 -0500 | [diff] [blame] | 266 | stub_priv_cache = KMEM_CACHE(stub_priv, SLAB_HWCACHE_ALIGN); |
Takahiro Hirofuchi | 4d7b5c7 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 267 | if (!stub_priv_cache) { |
matt mooney | 41e02f0 | 2011-05-19 21:36:58 -0700 | [diff] [blame] | 268 | pr_err("kmem_cache_create failed\n"); |
Takahiro Hirofuchi | 4d7b5c7 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 269 | return -ENOMEM; |
| 270 | } |
| 271 | |
Valentina Manea | b7945b7 | 2014-01-23 23:12:29 +0200 | [diff] [blame] | 272 | ret = usb_register_device_driver(&stub_driver, THIS_MODULE); |
navin patidar | 1583aeb | 2013-09-10 10:44:07 +0530 | [diff] [blame] | 273 | if (ret) { |
matt mooney | 1a4b6f6 | 2011-05-19 16:47:32 -0700 | [diff] [blame] | 274 | pr_err("usb_register failed %d\n", ret); |
matt mooney | 41e02f0 | 2011-05-19 21:36:58 -0700 | [diff] [blame] | 275 | goto err_usb_register; |
Takahiro Hirofuchi | 4d7b5c7 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 276 | } |
| 277 | |
Takahiro Hirofuchi | 4d7b5c7 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 278 | ret = driver_create_file(&stub_driver.drvwrap.driver, |
| 279 | &driver_attr_match_busid); |
navin patidar | 1583aeb | 2013-09-10 10:44:07 +0530 | [diff] [blame] | 280 | if (ret) { |
matt mooney | 41e02f0 | 2011-05-19 21:36:58 -0700 | [diff] [blame] | 281 | pr_err("driver_create_file failed\n"); |
| 282 | goto err_create_file; |
Takahiro Hirofuchi | 4d7b5c7 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 283 | } |
| 284 | |
Valentina Manea | a46034c | 2014-03-08 14:53:33 +0200 | [diff] [blame] | 285 | ret = driver_create_file(&stub_driver.drvwrap.driver, |
| 286 | &driver_attr_rebind); |
| 287 | if (ret) { |
| 288 | pr_err("driver_create_file failed\n"); |
| 289 | goto err_create_file; |
| 290 | } |
| 291 | |
Takahiro Hirofuchi | 4d7b5c7 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 292 | return ret; |
matt mooney | 41e02f0 | 2011-05-19 21:36:58 -0700 | [diff] [blame] | 293 | |
| 294 | err_create_file: |
Valentina Manea | b7945b7 | 2014-01-23 23:12:29 +0200 | [diff] [blame] | 295 | usb_deregister_device_driver(&stub_driver); |
matt mooney | 41e02f0 | 2011-05-19 21:36:58 -0700 | [diff] [blame] | 296 | err_usb_register: |
Takahiro Hirofuchi | 4d7b5c7 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 297 | kmem_cache_destroy(stub_priv_cache); |
| 298 | return ret; |
| 299 | } |
| 300 | |
matt mooney | 27ed5da | 2011-05-19 21:36:59 -0700 | [diff] [blame] | 301 | static void __exit usbip_host_exit(void) |
Takahiro Hirofuchi | 4d7b5c7 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 302 | { |
| 303 | driver_remove_file(&stub_driver.drvwrap.driver, |
| 304 | &driver_attr_match_busid); |
| 305 | |
Valentina Manea | a46034c | 2014-03-08 14:53:33 +0200 | [diff] [blame] | 306 | driver_remove_file(&stub_driver.drvwrap.driver, |
| 307 | &driver_attr_rebind); |
| 308 | |
Takahiro Hirofuchi | 4d7b5c7 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 309 | /* |
| 310 | * deregister() calls stub_disconnect() for all devices. Device |
| 311 | * specific data is cleared in stub_disconnect(). |
| 312 | */ |
Valentina Manea | b7945b7 | 2014-01-23 23:12:29 +0200 | [diff] [blame] | 313 | usb_deregister_device_driver(&stub_driver); |
Takahiro Hirofuchi | 4d7b5c7 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 314 | |
| 315 | kmem_cache_destroy(stub_priv_cache); |
| 316 | } |
| 317 | |
matt mooney | 27ed5da | 2011-05-19 21:36:59 -0700 | [diff] [blame] | 318 | module_init(usbip_host_init); |
| 319 | module_exit(usbip_host_exit); |
Takahiro Hirofuchi | 4d7b5c7 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 320 | |
| 321 | MODULE_AUTHOR(DRIVER_AUTHOR); |
| 322 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 323 | MODULE_LICENSE("GPL"); |