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