Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * driver.c - device id matching, driver model, etc. |
| 4 | * |
| 5 | * Copyright 2002 Adam Belay <ambx1@neo.rr.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | */ |
| 7 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | #include <linux/string.h> |
| 9 | #include <linux/list.h> |
| 10 | #include <linux/module.h> |
| 11 | #include <linux/ctype.h> |
| 12 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/pnp.h> |
| 14 | #include "base.h" |
| 15 | |
| 16 | static int compare_func(const char *ida, const char *idb) |
| 17 | { |
| 18 | int i; |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 19 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | /* we only need to compare the last 4 chars */ |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 21 | for (i = 3; i < 7; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | if (ida[i] != 'X' && |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 23 | idb[i] != 'X' && toupper(ida[i]) != toupper(idb[i])) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | return 0; |
| 25 | } |
| 26 | return 1; |
| 27 | } |
| 28 | |
| 29 | int compare_pnp_id(struct pnp_id *pos, const char *id) |
| 30 | { |
| 31 | if (!pos || !id || (strlen(id) != 7)) |
| 32 | return 0; |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 33 | if (memcmp(id, "ANYDEVS", 7) == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | return 1; |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 35 | while (pos) { |
| 36 | if (memcmp(pos->id, id, 3) == 0) |
| 37 | if (compare_func(pos->id, id) == 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | return 1; |
| 39 | pos = pos->next; |
| 40 | } |
| 41 | return 0; |
| 42 | } |
| 43 | |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 44 | static const struct pnp_device_id *match_device(struct pnp_driver *drv, |
| 45 | struct pnp_dev *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | { |
| 47 | const struct pnp_device_id *drv_id = drv->id_table; |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 48 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | if (!drv_id) |
| 50 | return NULL; |
| 51 | |
| 52 | while (*drv_id->id) { |
| 53 | if (compare_pnp_id(dev->id, drv_id->id)) |
| 54 | return drv_id; |
| 55 | drv_id++; |
| 56 | } |
| 57 | return NULL; |
| 58 | } |
| 59 | |
| 60 | int pnp_device_attach(struct pnp_dev *pnp_dev) |
| 61 | { |
Rafael J. Wysocki | 38f6b38 | 2015-03-18 22:39:55 +0100 | [diff] [blame] | 62 | mutex_lock(&pnp_lock); |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 63 | if (pnp_dev->status != PNP_READY) { |
Rafael J. Wysocki | 38f6b38 | 2015-03-18 22:39:55 +0100 | [diff] [blame] | 64 | mutex_unlock(&pnp_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | return -EBUSY; |
| 66 | } |
| 67 | pnp_dev->status = PNP_ATTACHED; |
Rafael J. Wysocki | 38f6b38 | 2015-03-18 22:39:55 +0100 | [diff] [blame] | 68 | mutex_unlock(&pnp_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | return 0; |
| 70 | } |
Jinchao Wang | d02908a | 2021-06-24 10:09:29 +0800 | [diff] [blame] | 71 | EXPORT_SYMBOL(pnp_device_attach); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | |
| 73 | void pnp_device_detach(struct pnp_dev *pnp_dev) |
| 74 | { |
Rafael J. Wysocki | 38f6b38 | 2015-03-18 22:39:55 +0100 | [diff] [blame] | 75 | mutex_lock(&pnp_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | if (pnp_dev->status == PNP_ATTACHED) |
| 77 | pnp_dev->status = PNP_READY; |
Rafael J. Wysocki | 38f6b38 | 2015-03-18 22:39:55 +0100 | [diff] [blame] | 78 | mutex_unlock(&pnp_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | } |
Jinchao Wang | d02908a | 2021-06-24 10:09:29 +0800 | [diff] [blame] | 80 | EXPORT_SYMBOL(pnp_device_detach); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | |
| 82 | static int pnp_device_probe(struct device *dev) |
| 83 | { |
| 84 | int error; |
| 85 | struct pnp_driver *pnp_drv; |
| 86 | struct pnp_dev *pnp_dev; |
| 87 | const struct pnp_device_id *dev_id = NULL; |
| 88 | pnp_dev = to_pnp_dev(dev); |
| 89 | pnp_drv = to_pnp_driver(dev->driver); |
| 90 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | error = pnp_device_attach(pnp_dev); |
| 92 | if (error < 0) |
| 93 | return error; |
| 94 | |
| 95 | if (pnp_dev->active == 0) { |
| 96 | if (!(pnp_drv->flags & PNP_DRIVER_RES_DO_NOT_CHANGE)) { |
| 97 | error = pnp_activate_dev(pnp_dev); |
| 98 | if (error < 0) |
| 99 | return error; |
| 100 | } |
| 101 | } else if ((pnp_drv->flags & PNP_DRIVER_RES_DISABLE) |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 102 | == PNP_DRIVER_RES_DISABLE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | error = pnp_disable_dev(pnp_dev); |
| 104 | if (error < 0) |
| 105 | return error; |
| 106 | } |
| 107 | error = 0; |
| 108 | if (pnp_drv->probe) { |
| 109 | dev_id = match_device(pnp_drv, pnp_dev); |
| 110 | if (dev_id != NULL) |
| 111 | error = pnp_drv->probe(pnp_dev, dev_id); |
| 112 | } |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 113 | if (error >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | pnp_dev->driver = pnp_drv; |
| 115 | error = 0; |
| 116 | } else |
| 117 | goto fail; |
Bjorn Helgaas | a05d078 | 2007-10-16 23:31:10 -0700 | [diff] [blame] | 118 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | return error; |
| 120 | |
Bjorn Helgaas | 1e0aa9a | 2007-08-15 10:32:08 -0600 | [diff] [blame] | 121 | fail: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | pnp_device_detach(pnp_dev); |
| 123 | return error; |
| 124 | } |
| 125 | |
Uwe Kleine-König | fc7a620 | 2021-07-13 21:35:22 +0200 | [diff] [blame] | 126 | static void pnp_device_remove(struct device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | { |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 128 | struct pnp_dev *pnp_dev = to_pnp_dev(dev); |
| 129 | struct pnp_driver *drv = pnp_dev->driver; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | |
| 131 | if (drv) { |
| 132 | if (drv->remove) |
| 133 | drv->remove(pnp_dev); |
| 134 | pnp_dev->driver = NULL; |
| 135 | } |
Heiner Kallweit | e0f03e8 | 2015-12-16 07:33:22 +0100 | [diff] [blame] | 136 | |
| 137 | if (pnp_dev->active && |
| 138 | (!drv || !(drv->flags & PNP_DRIVER_RES_DO_NOT_CHANGE))) |
| 139 | pnp_disable_dev(pnp_dev); |
| 140 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | pnp_device_detach(pnp_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | } |
| 143 | |
David Härdeman | abd6633 | 2009-09-21 17:04:52 -0700 | [diff] [blame] | 144 | static void pnp_device_shutdown(struct device *dev) |
| 145 | { |
| 146 | struct pnp_dev *pnp_dev = to_pnp_dev(dev); |
| 147 | struct pnp_driver *drv = pnp_dev->driver; |
| 148 | |
| 149 | if (drv && drv->shutdown) |
| 150 | drv->shutdown(pnp_dev); |
| 151 | } |
| 152 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | static int pnp_bus_match(struct device *dev, struct device_driver *drv) |
| 154 | { |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 155 | struct pnp_dev *pnp_dev = to_pnp_dev(dev); |
| 156 | struct pnp_driver *pnp_drv = to_pnp_driver(drv); |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 157 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | if (match_device(pnp_drv, pnp_dev) == NULL) |
| 159 | return 0; |
| 160 | return 1; |
| 161 | } |
| 162 | |
Shuah Khan | eaf140b | 2013-07-26 15:07:26 -0600 | [diff] [blame] | 163 | static int __pnp_bus_suspend(struct device *dev, pm_message_t state) |
Takashi Iwai | 4c98cfe | 2005-11-29 09:09:32 +0100 | [diff] [blame] | 164 | { |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 165 | struct pnp_dev *pnp_dev = to_pnp_dev(dev); |
| 166 | struct pnp_driver *pnp_drv = pnp_dev->driver; |
Pierre Ossman | 68094e3 | 2005-11-29 09:09:32 +0100 | [diff] [blame] | 167 | int error; |
Takashi Iwai | 4c98cfe | 2005-11-29 09:09:32 +0100 | [diff] [blame] | 168 | |
Pierre Ossman | 68094e3 | 2005-11-29 09:09:32 +0100 | [diff] [blame] | 169 | if (!pnp_drv) |
| 170 | return 0; |
| 171 | |
Shuah Khan | 729377d | 2013-09-11 14:23:09 -0700 | [diff] [blame] | 172 | if (pnp_drv->driver.pm && pnp_drv->driver.pm->suspend) { |
| 173 | error = pnp_drv->driver.pm->suspend(dev); |
| 174 | suspend_report_result(pnp_drv->driver.pm->suspend, error); |
| 175 | if (error) |
| 176 | return error; |
| 177 | } |
| 178 | |
Pierre Ossman | 68094e3 | 2005-11-29 09:09:32 +0100 | [diff] [blame] | 179 | if (pnp_drv->suspend) { |
| 180 | error = pnp_drv->suspend(pnp_dev, state); |
| 181 | if (error) |
| 182 | return error; |
| 183 | } |
| 184 | |
Rene Herman | 5d38998 | 2008-02-06 01:40:05 -0800 | [diff] [blame] | 185 | if (pnp_can_disable(pnp_dev)) { |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 186 | error = pnp_stop_dev(pnp_dev); |
| 187 | if (error) |
| 188 | return error; |
Pierre Ossman | 68094e3 | 2005-11-29 09:09:32 +0100 | [diff] [blame] | 189 | } |
| 190 | |
Peter Hurley | 01395d7 | 2015-01-22 11:50:24 -0500 | [diff] [blame] | 191 | if (pnp_can_suspend(pnp_dev)) |
Shaohua Li | fc30e68 | 2007-07-20 10:03:20 +0800 | [diff] [blame] | 192 | pnp_dev->protocol->suspend(pnp_dev, state); |
Takashi Iwai | 4c98cfe | 2005-11-29 09:09:32 +0100 | [diff] [blame] | 193 | return 0; |
| 194 | } |
| 195 | |
Shuah Khan | eaf140b | 2013-07-26 15:07:26 -0600 | [diff] [blame] | 196 | static int pnp_bus_suspend(struct device *dev) |
| 197 | { |
| 198 | return __pnp_bus_suspend(dev, PMSG_SUSPEND); |
| 199 | } |
| 200 | |
| 201 | static int pnp_bus_freeze(struct device *dev) |
| 202 | { |
| 203 | return __pnp_bus_suspend(dev, PMSG_FREEZE); |
| 204 | } |
| 205 | |
Dmitry Torokhov | 8a37ea5 | 2013-12-05 02:01:55 +0100 | [diff] [blame] | 206 | static int pnp_bus_poweroff(struct device *dev) |
| 207 | { |
| 208 | return __pnp_bus_suspend(dev, PMSG_HIBERNATE); |
| 209 | } |
| 210 | |
Pierre Ossman | 68094e3 | 2005-11-29 09:09:32 +0100 | [diff] [blame] | 211 | static int pnp_bus_resume(struct device *dev) |
Takashi Iwai | 4c98cfe | 2005-11-29 09:09:32 +0100 | [diff] [blame] | 212 | { |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 213 | struct pnp_dev *pnp_dev = to_pnp_dev(dev); |
| 214 | struct pnp_driver *pnp_drv = pnp_dev->driver; |
Pierre Ossman | 68094e3 | 2005-11-29 09:09:32 +0100 | [diff] [blame] | 215 | int error; |
Takashi Iwai | 4c98cfe | 2005-11-29 09:09:32 +0100 | [diff] [blame] | 216 | |
Pierre Ossman | 68094e3 | 2005-11-29 09:09:32 +0100 | [diff] [blame] | 217 | if (!pnp_drv) |
| 218 | return 0; |
| 219 | |
Rafael J. Wysocki | cc8e7a3 | 2011-01-10 21:23:16 +0100 | [diff] [blame] | 220 | if (pnp_dev->protocol->resume) { |
| 221 | error = pnp_dev->protocol->resume(pnp_dev); |
| 222 | if (error) |
| 223 | return error; |
| 224 | } |
Shaohua Li | fc30e68 | 2007-07-20 10:03:20 +0800 | [diff] [blame] | 225 | |
Rene Herman | 5d38998 | 2008-02-06 01:40:05 -0800 | [diff] [blame] | 226 | if (pnp_can_write(pnp_dev)) { |
Pierre Ossman | 68094e3 | 2005-11-29 09:09:32 +0100 | [diff] [blame] | 227 | error = pnp_start_dev(pnp_dev); |
| 228 | if (error) |
| 229 | return error; |
| 230 | } |
| 231 | |
Shuah Khan | 729377d | 2013-09-11 14:23:09 -0700 | [diff] [blame] | 232 | if (pnp_drv->driver.pm && pnp_drv->driver.pm->resume) { |
| 233 | error = pnp_drv->driver.pm->resume(dev); |
| 234 | if (error) |
| 235 | return error; |
| 236 | } |
| 237 | |
Rene Herman | 5d38998 | 2008-02-06 01:40:05 -0800 | [diff] [blame] | 238 | if (pnp_drv->resume) { |
| 239 | error = pnp_drv->resume(pnp_dev); |
| 240 | if (error) |
| 241 | return error; |
| 242 | } |
Pierre Ossman | 68094e3 | 2005-11-29 09:09:32 +0100 | [diff] [blame] | 243 | |
| 244 | return 0; |
Takashi Iwai | 4c98cfe | 2005-11-29 09:09:32 +0100 | [diff] [blame] | 245 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | |
Shuah Khan | eaf140b | 2013-07-26 15:07:26 -0600 | [diff] [blame] | 247 | static const struct dev_pm_ops pnp_bus_dev_pm_ops = { |
Dmitry Torokhov | 8a37ea5 | 2013-12-05 02:01:55 +0100 | [diff] [blame] | 248 | /* Suspend callbacks */ |
Shuah Khan | eaf140b | 2013-07-26 15:07:26 -0600 | [diff] [blame] | 249 | .suspend = pnp_bus_suspend, |
Shuah Khan | eaf140b | 2013-07-26 15:07:26 -0600 | [diff] [blame] | 250 | .resume = pnp_bus_resume, |
Dmitry Torokhov | 8a37ea5 | 2013-12-05 02:01:55 +0100 | [diff] [blame] | 251 | /* Hibernate callbacks */ |
| 252 | .freeze = pnp_bus_freeze, |
| 253 | .thaw = pnp_bus_resume, |
| 254 | .poweroff = pnp_bus_poweroff, |
| 255 | .restore = pnp_bus_resume, |
Shuah Khan | eaf140b | 2013-07-26 15:07:26 -0600 | [diff] [blame] | 256 | }; |
| 257 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | struct bus_type pnp_bus_type = { |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 259 | .name = "pnp", |
| 260 | .match = pnp_bus_match, |
| 261 | .probe = pnp_device_probe, |
| 262 | .remove = pnp_device_remove, |
David Härdeman | abd6633 | 2009-09-21 17:04:52 -0700 | [diff] [blame] | 263 | .shutdown = pnp_device_shutdown, |
Shuah Khan | eaf140b | 2013-07-26 15:07:26 -0600 | [diff] [blame] | 264 | .pm = &pnp_bus_dev_pm_ops, |
Greg Kroah-Hartman | 2df4390 | 2013-10-06 23:55:42 -0700 | [diff] [blame] | 265 | .dev_groups = pnp_dev_groups, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | }; |
| 267 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | int pnp_register_driver(struct pnp_driver *drv) |
| 269 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | drv->driver.name = drv->name; |
| 271 | drv->driver.bus = &pnp_bus_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | |
Bjorn Helgaas | 982c609 | 2006-03-27 01:17:08 -0800 | [diff] [blame] | 273 | return driver_register(&drv->driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | } |
Jinchao Wang | d02908a | 2021-06-24 10:09:29 +0800 | [diff] [blame] | 275 | EXPORT_SYMBOL(pnp_register_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | |
| 277 | void pnp_unregister_driver(struct pnp_driver *drv) |
| 278 | { |
| 279 | driver_unregister(&drv->driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | } |
Jinchao Wang | d02908a | 2021-06-24 10:09:29 +0800 | [diff] [blame] | 281 | EXPORT_SYMBOL(pnp_unregister_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | |
| 283 | /** |
| 284 | * pnp_add_id - adds an EISA id to the specified device |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | * @dev: pointer to the desired device |
Bjorn Helgaas | 772defc | 2008-04-28 16:33:52 -0600 | [diff] [blame] | 286 | * @id: pointer to an EISA id string |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | */ |
Thomas Renninger | 620e112 | 2010-10-01 10:54:00 +0200 | [diff] [blame] | 288 | struct pnp_id *pnp_add_id(struct pnp_dev *dev, const char *id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | { |
Bjorn Helgaas | 772defc | 2008-04-28 16:33:52 -0600 | [diff] [blame] | 290 | struct pnp_id *dev_id, *ptr; |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 291 | |
Bjorn Helgaas | 772defc | 2008-04-28 16:33:52 -0600 | [diff] [blame] | 292 | dev_id = kzalloc(sizeof(struct pnp_id), GFP_KERNEL); |
| 293 | if (!dev_id) |
| 294 | return NULL; |
| 295 | |
| 296 | dev_id->id[0] = id[0]; |
| 297 | dev_id->id[1] = id[1]; |
| 298 | dev_id->id[2] = id[2]; |
| 299 | dev_id->id[3] = tolower(id[3]); |
| 300 | dev_id->id[4] = tolower(id[4]); |
| 301 | dev_id->id[5] = tolower(id[5]); |
| 302 | dev_id->id[6] = tolower(id[6]); |
| 303 | dev_id->id[7] = '\0'; |
| 304 | |
| 305 | dev_id->next = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | ptr = dev->id; |
| 307 | while (ptr && ptr->next) |
| 308 | ptr = ptr->next; |
| 309 | if (ptr) |
Bjorn Helgaas | 772defc | 2008-04-28 16:33:52 -0600 | [diff] [blame] | 310 | ptr->next = dev_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | else |
Bjorn Helgaas | 772defc | 2008-04-28 16:33:52 -0600 | [diff] [blame] | 312 | dev->id = dev_id; |
| 313 | |
| 314 | return dev_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | } |