libnvdimm: write blk label set
[linux-2.6-block.git] / drivers / nvdimm / bus.c
CommitLineData
45def22c
DW
1/*
2 * Copyright(c) 2013-2015 Intel Corporation. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 */
13#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
62232e45 14#include <linux/vmalloc.h>
45def22c 15#include <linux/uaccess.h>
3d88002e 16#include <linux/module.h>
45def22c 17#include <linux/fcntl.h>
e6dfb2de 18#include <linux/async.h>
62232e45 19#include <linux/ndctl.h>
4d88a97a 20#include <linux/sched.h>
45def22c
DW
21#include <linux/slab.h>
22#include <linux/fs.h>
23#include <linux/io.h>
62232e45 24#include <linux/mm.h>
4d88a97a 25#include <linux/nd.h>
45def22c 26#include "nd-core.h"
4d88a97a 27#include "nd.h"
45def22c 28
62232e45 29int nvdimm_major;
45def22c
DW
30static int nvdimm_bus_major;
31static struct class *nd_class;
32
4d88a97a
DW
33static int to_nd_device_type(struct device *dev)
34{
35 if (is_nvdimm(dev))
36 return ND_DEVICE_DIMM;
3d88002e
DW
37 else if (is_nd_pmem(dev))
38 return ND_DEVICE_REGION_PMEM;
39 else if (is_nd_blk(dev))
40 return ND_DEVICE_REGION_BLK;
41 else if (is_nd_pmem(dev->parent) || is_nd_blk(dev->parent))
42 return nd_region_to_nstype(to_nd_region(dev->parent));
4d88a97a
DW
43
44 return 0;
45}
46
47static int nvdimm_bus_uevent(struct device *dev, struct kobj_uevent_env *env)
48{
49 return add_uevent_var(env, "MODALIAS=" ND_DEVICE_MODALIAS_FMT,
50 to_nd_device_type(dev));
51}
52
53static int nvdimm_bus_match(struct device *dev, struct device_driver *drv)
54{
55 struct nd_device_driver *nd_drv = to_nd_device_driver(drv);
56
57 return test_bit(to_nd_device_type(dev), &nd_drv->type);
58}
59
3d88002e
DW
60static struct module *to_bus_provider(struct device *dev)
61{
62 /* pin bus providers while regions are enabled */
63 if (is_nd_pmem(dev) || is_nd_blk(dev)) {
64 struct nvdimm_bus *nvdimm_bus = walk_to_nvdimm_bus(dev);
65
66 return nvdimm_bus->module;
67 }
68 return NULL;
69}
70
eaf96153
DW
71static void nvdimm_bus_probe_start(struct nvdimm_bus *nvdimm_bus)
72{
73 nvdimm_bus_lock(&nvdimm_bus->dev);
74 nvdimm_bus->probe_active++;
75 nvdimm_bus_unlock(&nvdimm_bus->dev);
76}
77
78static void nvdimm_bus_probe_end(struct nvdimm_bus *nvdimm_bus)
79{
80 nvdimm_bus_lock(&nvdimm_bus->dev);
81 if (--nvdimm_bus->probe_active == 0)
82 wake_up(&nvdimm_bus->probe_wait);
83 nvdimm_bus_unlock(&nvdimm_bus->dev);
84}
85
4d88a97a
DW
86static int nvdimm_bus_probe(struct device *dev)
87{
88 struct nd_device_driver *nd_drv = to_nd_device_driver(dev->driver);
3d88002e 89 struct module *provider = to_bus_provider(dev);
4d88a97a
DW
90 struct nvdimm_bus *nvdimm_bus = walk_to_nvdimm_bus(dev);
91 int rc;
92
3d88002e
DW
93 if (!try_module_get(provider))
94 return -ENXIO;
95
eaf96153 96 nvdimm_bus_probe_start(nvdimm_bus);
4d88a97a 97 rc = nd_drv->probe(dev);
eaf96153
DW
98 if (rc == 0)
99 nd_region_probe_success(nvdimm_bus, dev);
bf9bccc1
DW
100 else
101 nd_region_disable(nvdimm_bus, dev);
eaf96153
DW
102 nvdimm_bus_probe_end(nvdimm_bus);
103
4d88a97a
DW
104 dev_dbg(&nvdimm_bus->dev, "%s.probe(%s) = %d\n", dev->driver->name,
105 dev_name(dev), rc);
3d88002e
DW
106 if (rc != 0)
107 module_put(provider);
4d88a97a
DW
108 return rc;
109}
110
111static int nvdimm_bus_remove(struct device *dev)
112{
113 struct nd_device_driver *nd_drv = to_nd_device_driver(dev->driver);
3d88002e 114 struct module *provider = to_bus_provider(dev);
4d88a97a
DW
115 struct nvdimm_bus *nvdimm_bus = walk_to_nvdimm_bus(dev);
116 int rc;
117
118 rc = nd_drv->remove(dev);
eaf96153
DW
119 nd_region_disable(nvdimm_bus, dev);
120
4d88a97a
DW
121 dev_dbg(&nvdimm_bus->dev, "%s.remove(%s) = %d\n", dev->driver->name,
122 dev_name(dev), rc);
3d88002e 123 module_put(provider);
4d88a97a
DW
124 return rc;
125}
126
127static struct bus_type nvdimm_bus_type = {
e6dfb2de 128 .name = "nd",
4d88a97a
DW
129 .uevent = nvdimm_bus_uevent,
130 .match = nvdimm_bus_match,
131 .probe = nvdimm_bus_probe,
132 .remove = nvdimm_bus_remove,
133};
134
135static ASYNC_DOMAIN_EXCLUSIVE(nd_async_domain);
136
137void nd_synchronize(void)
138{
139 async_synchronize_full_domain(&nd_async_domain);
140}
141EXPORT_SYMBOL_GPL(nd_synchronize);
142
143static void nd_async_device_register(void *d, async_cookie_t cookie)
144{
145 struct device *dev = d;
146
147 if (device_add(dev) != 0) {
148 dev_err(dev, "%s: failed\n", __func__);
149 put_device(dev);
150 }
151 put_device(dev);
152}
153
154static void nd_async_device_unregister(void *d, async_cookie_t cookie)
155{
156 struct device *dev = d;
157
0ba1c634
DW
158 /* flush bus operations before delete */
159 nvdimm_bus_lock(dev);
160 nvdimm_bus_unlock(dev);
161
4d88a97a
DW
162 device_unregister(dev);
163 put_device(dev);
164}
165
166void nd_device_register(struct device *dev)
167{
168 dev->bus = &nvdimm_bus_type;
169 device_initialize(dev);
170 get_device(dev);
171 async_schedule_domain(nd_async_device_register, dev,
172 &nd_async_domain);
173}
174EXPORT_SYMBOL(nd_device_register);
175
176void nd_device_unregister(struct device *dev, enum nd_async_mode mode)
177{
178 switch (mode) {
179 case ND_ASYNC:
180 get_device(dev);
181 async_schedule_domain(nd_async_device_unregister, dev,
182 &nd_async_domain);
183 break;
184 case ND_SYNC:
185 nd_synchronize();
186 device_unregister(dev);
187 break;
188 }
189}
190EXPORT_SYMBOL(nd_device_unregister);
191
192/**
193 * __nd_driver_register() - register a region or a namespace driver
194 * @nd_drv: driver to register
195 * @owner: automatically set by nd_driver_register() macro
196 * @mod_name: automatically set by nd_driver_register() macro
197 */
198int __nd_driver_register(struct nd_device_driver *nd_drv, struct module *owner,
199 const char *mod_name)
200{
201 struct device_driver *drv = &nd_drv->drv;
202
203 if (!nd_drv->type) {
204 pr_debug("driver type bitmask not set (%pf)\n",
205 __builtin_return_address(0));
206 return -EINVAL;
207 }
208
209 if (!nd_drv->probe || !nd_drv->remove) {
210 pr_debug("->probe() and ->remove() must be specified\n");
211 return -EINVAL;
212 }
213
214 drv->bus = &nvdimm_bus_type;
215 drv->owner = owner;
216 drv->mod_name = mod_name;
217
218 return driver_register(drv);
219}
220EXPORT_SYMBOL(__nd_driver_register);
221
222static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
223 char *buf)
224{
225 return sprintf(buf, ND_DEVICE_MODALIAS_FMT "\n",
226 to_nd_device_type(dev));
227}
228static DEVICE_ATTR_RO(modalias);
229
230static ssize_t devtype_show(struct device *dev, struct device_attribute *attr,
231 char *buf)
232{
233 return sprintf(buf, "%s\n", dev->type->name);
234}
235static DEVICE_ATTR_RO(devtype);
236
237static struct attribute *nd_device_attributes[] = {
238 &dev_attr_modalias.attr,
239 &dev_attr_devtype.attr,
240 NULL,
241};
242
243/**
244 * nd_device_attribute_group - generic attributes for all devices on an nd bus
245 */
246struct attribute_group nd_device_attribute_group = {
247 .attrs = nd_device_attributes,
e6dfb2de 248};
4d88a97a 249EXPORT_SYMBOL_GPL(nd_device_attribute_group);
e6dfb2de 250
45def22c
DW
251int nvdimm_bus_create_ndctl(struct nvdimm_bus *nvdimm_bus)
252{
253 dev_t devt = MKDEV(nvdimm_bus_major, nvdimm_bus->id);
254 struct device *dev;
255
256 dev = device_create(nd_class, &nvdimm_bus->dev, devt, nvdimm_bus,
257 "ndctl%d", nvdimm_bus->id);
258
259 if (IS_ERR(dev)) {
260 dev_dbg(&nvdimm_bus->dev, "failed to register ndctl%d: %ld\n",
261 nvdimm_bus->id, PTR_ERR(dev));
262 return PTR_ERR(dev);
263 }
264 return 0;
265}
266
267void nvdimm_bus_destroy_ndctl(struct nvdimm_bus *nvdimm_bus)
268{
269 device_destroy(nd_class, MKDEV(nvdimm_bus_major, nvdimm_bus->id));
270}
271
62232e45
DW
272static const struct nd_cmd_desc __nd_cmd_dimm_descs[] = {
273 [ND_CMD_IMPLEMENTED] = { },
274 [ND_CMD_SMART] = {
275 .out_num = 2,
276 .out_sizes = { 4, 8, },
277 },
278 [ND_CMD_SMART_THRESHOLD] = {
279 .out_num = 2,
280 .out_sizes = { 4, 8, },
281 },
282 [ND_CMD_DIMM_FLAGS] = {
283 .out_num = 2,
284 .out_sizes = { 4, 4 },
285 },
286 [ND_CMD_GET_CONFIG_SIZE] = {
287 .out_num = 3,
288 .out_sizes = { 4, 4, 4, },
289 },
290 [ND_CMD_GET_CONFIG_DATA] = {
291 .in_num = 2,
292 .in_sizes = { 4, 4, },
293 .out_num = 2,
294 .out_sizes = { 4, UINT_MAX, },
295 },
296 [ND_CMD_SET_CONFIG_DATA] = {
297 .in_num = 3,
298 .in_sizes = { 4, 4, UINT_MAX, },
299 .out_num = 1,
300 .out_sizes = { 4, },
301 },
302 [ND_CMD_VENDOR] = {
303 .in_num = 3,
304 .in_sizes = { 4, 4, UINT_MAX, },
305 .out_num = 3,
306 .out_sizes = { 4, 4, UINT_MAX, },
307 },
308};
309
310const struct nd_cmd_desc *nd_cmd_dimm_desc(int cmd)
311{
312 if (cmd < ARRAY_SIZE(__nd_cmd_dimm_descs))
313 return &__nd_cmd_dimm_descs[cmd];
314 return NULL;
315}
316EXPORT_SYMBOL_GPL(nd_cmd_dimm_desc);
317
318static const struct nd_cmd_desc __nd_cmd_bus_descs[] = {
319 [ND_CMD_IMPLEMENTED] = { },
320 [ND_CMD_ARS_CAP] = {
321 .in_num = 2,
322 .in_sizes = { 8, 8, },
323 .out_num = 2,
324 .out_sizes = { 4, 4, },
325 },
326 [ND_CMD_ARS_START] = {
327 .in_num = 4,
328 .in_sizes = { 8, 8, 2, 6, },
329 .out_num = 1,
330 .out_sizes = { 4, },
331 },
332 [ND_CMD_ARS_STATUS] = {
333 .out_num = 2,
334 .out_sizes = { 4, UINT_MAX, },
335 },
336};
337
338const struct nd_cmd_desc *nd_cmd_bus_desc(int cmd)
339{
340 if (cmd < ARRAY_SIZE(__nd_cmd_bus_descs))
341 return &__nd_cmd_bus_descs[cmd];
342 return NULL;
343}
344EXPORT_SYMBOL_GPL(nd_cmd_bus_desc);
345
346u32 nd_cmd_in_size(struct nvdimm *nvdimm, int cmd,
347 const struct nd_cmd_desc *desc, int idx, void *buf)
348{
349 if (idx >= desc->in_num)
350 return UINT_MAX;
351
352 if (desc->in_sizes[idx] < UINT_MAX)
353 return desc->in_sizes[idx];
354
355 if (nvdimm && cmd == ND_CMD_SET_CONFIG_DATA && idx == 2) {
356 struct nd_cmd_set_config_hdr *hdr = buf;
357
358 return hdr->in_length;
359 } else if (nvdimm && cmd == ND_CMD_VENDOR && idx == 2) {
360 struct nd_cmd_vendor_hdr *hdr = buf;
361
362 return hdr->in_length;
363 }
364
365 return UINT_MAX;
366}
367EXPORT_SYMBOL_GPL(nd_cmd_in_size);
368
369u32 nd_cmd_out_size(struct nvdimm *nvdimm, int cmd,
370 const struct nd_cmd_desc *desc, int idx, const u32 *in_field,
371 const u32 *out_field)
372{
373 if (idx >= desc->out_num)
374 return UINT_MAX;
375
376 if (desc->out_sizes[idx] < UINT_MAX)
377 return desc->out_sizes[idx];
378
379 if (nvdimm && cmd == ND_CMD_GET_CONFIG_DATA && idx == 1)
380 return in_field[1];
381 else if (nvdimm && cmd == ND_CMD_VENDOR && idx == 2)
382 return out_field[1];
383 else if (!nvdimm && cmd == ND_CMD_ARS_STATUS && idx == 1)
384 return ND_CMD_ARS_STATUS_MAX;
385
386 return UINT_MAX;
387}
388EXPORT_SYMBOL_GPL(nd_cmd_out_size);
389
bf9bccc1 390void wait_nvdimm_bus_probe_idle(struct device *dev)
eaf96153 391{
bf9bccc1
DW
392 struct nvdimm_bus *nvdimm_bus = walk_to_nvdimm_bus(dev);
393
eaf96153
DW
394 do {
395 if (nvdimm_bus->probe_active == 0)
396 break;
397 nvdimm_bus_unlock(&nvdimm_bus->dev);
398 wait_event(nvdimm_bus->probe_wait,
399 nvdimm_bus->probe_active == 0);
400 nvdimm_bus_lock(&nvdimm_bus->dev);
401 } while (true);
402}
403
404/* set_config requires an idle interleave set */
405static int nd_cmd_clear_to_send(struct nvdimm *nvdimm, unsigned int cmd)
406{
407 struct nvdimm_bus *nvdimm_bus;
408
409 if (!nvdimm || cmd != ND_CMD_SET_CONFIG_DATA)
410 return 0;
411
412 nvdimm_bus = walk_to_nvdimm_bus(&nvdimm->dev);
bf9bccc1 413 wait_nvdimm_bus_probe_idle(&nvdimm_bus->dev);
eaf96153
DW
414
415 if (atomic_read(&nvdimm->busy))
416 return -EBUSY;
417 return 0;
418}
419
62232e45
DW
420static int __nd_ioctl(struct nvdimm_bus *nvdimm_bus, struct nvdimm *nvdimm,
421 int read_only, unsigned int ioctl_cmd, unsigned long arg)
422{
423 struct nvdimm_bus_descriptor *nd_desc = nvdimm_bus->nd_desc;
424 size_t buf_len = 0, in_len = 0, out_len = 0;
425 static char out_env[ND_CMD_MAX_ENVELOPE];
426 static char in_env[ND_CMD_MAX_ENVELOPE];
427 const struct nd_cmd_desc *desc = NULL;
428 unsigned int cmd = _IOC_NR(ioctl_cmd);
429 void __user *p = (void __user *) arg;
430 struct device *dev = &nvdimm_bus->dev;
431 const char *cmd_name, *dimm_name;
432 unsigned long dsm_mask;
433 void *buf;
434 int rc, i;
435
436 if (nvdimm) {
437 desc = nd_cmd_dimm_desc(cmd);
438 cmd_name = nvdimm_cmd_name(cmd);
439 dsm_mask = nvdimm->dsm_mask ? *(nvdimm->dsm_mask) : 0;
440 dimm_name = dev_name(&nvdimm->dev);
441 } else {
442 desc = nd_cmd_bus_desc(cmd);
443 cmd_name = nvdimm_bus_cmd_name(cmd);
444 dsm_mask = nd_desc->dsm_mask;
445 dimm_name = "bus";
446 }
447
448 if (!desc || (desc->out_num + desc->in_num == 0) ||
449 !test_bit(cmd, &dsm_mask))
450 return -ENOTTY;
451
452 /* fail write commands (when read-only) */
453 if (read_only)
454 switch (ioctl_cmd) {
455 case ND_IOCTL_VENDOR:
456 case ND_IOCTL_SET_CONFIG_DATA:
457 case ND_IOCTL_ARS_START:
458 dev_dbg(&nvdimm_bus->dev, "'%s' command while read-only.\n",
459 nvdimm ? nvdimm_cmd_name(cmd)
460 : nvdimm_bus_cmd_name(cmd));
461 return -EPERM;
462 default:
463 break;
464 }
465
466 /* process an input envelope */
467 for (i = 0; i < desc->in_num; i++) {
468 u32 in_size, copy;
469
470 in_size = nd_cmd_in_size(nvdimm, cmd, desc, i, in_env);
471 if (in_size == UINT_MAX) {
472 dev_err(dev, "%s:%s unknown input size cmd: %s field: %d\n",
473 __func__, dimm_name, cmd_name, i);
474 return -ENXIO;
475 }
476 if (!access_ok(VERIFY_READ, p + in_len, in_size))
477 return -EFAULT;
478 if (in_len < sizeof(in_env))
479 copy = min_t(u32, sizeof(in_env) - in_len, in_size);
480 else
481 copy = 0;
482 if (copy && copy_from_user(&in_env[in_len], p + in_len, copy))
483 return -EFAULT;
484 in_len += in_size;
485 }
486
487 /* process an output envelope */
488 for (i = 0; i < desc->out_num; i++) {
489 u32 out_size = nd_cmd_out_size(nvdimm, cmd, desc, i,
490 (u32 *) in_env, (u32 *) out_env);
491 u32 copy;
492
493 if (out_size == UINT_MAX) {
494 dev_dbg(dev, "%s:%s unknown output size cmd: %s field: %d\n",
495 __func__, dimm_name, cmd_name, i);
496 return -EFAULT;
497 }
498 if (!access_ok(VERIFY_WRITE, p + in_len + out_len, out_size))
499 return -EFAULT;
500 if (out_len < sizeof(out_env))
501 copy = min_t(u32, sizeof(out_env) - out_len, out_size);
502 else
503 copy = 0;
504 if (copy && copy_from_user(&out_env[out_len],
505 p + in_len + out_len, copy))
506 return -EFAULT;
507 out_len += out_size;
508 }
509
510 buf_len = out_len + in_len;
511 if (!access_ok(VERIFY_WRITE, p, sizeof(buf_len)))
512 return -EFAULT;
513
514 if (buf_len > ND_IOCTL_MAX_BUFLEN) {
515 dev_dbg(dev, "%s:%s cmd: %s buf_len: %zu > %d\n", __func__,
516 dimm_name, cmd_name, buf_len,
517 ND_IOCTL_MAX_BUFLEN);
518 return -EINVAL;
519 }
520
521 buf = vmalloc(buf_len);
522 if (!buf)
523 return -ENOMEM;
524
525 if (copy_from_user(buf, p, buf_len)) {
526 rc = -EFAULT;
527 goto out;
528 }
529
eaf96153
DW
530 nvdimm_bus_lock(&nvdimm_bus->dev);
531 rc = nd_cmd_clear_to_send(nvdimm, cmd);
532 if (rc)
533 goto out_unlock;
534
62232e45
DW
535 rc = nd_desc->ndctl(nd_desc, nvdimm, cmd, buf, buf_len);
536 if (rc < 0)
eaf96153 537 goto out_unlock;
62232e45
DW
538 if (copy_to_user(p, buf, buf_len))
539 rc = -EFAULT;
eaf96153
DW
540 out_unlock:
541 nvdimm_bus_unlock(&nvdimm_bus->dev);
62232e45
DW
542 out:
543 vfree(buf);
544 return rc;
545}
546
45def22c
DW
547static long nd_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
548{
62232e45
DW
549 long id = (long) file->private_data;
550 int rc = -ENXIO, read_only;
551 struct nvdimm_bus *nvdimm_bus;
552
553 read_only = (O_RDWR != (file->f_flags & O_ACCMODE));
554 mutex_lock(&nvdimm_bus_list_mutex);
555 list_for_each_entry(nvdimm_bus, &nvdimm_bus_list, list) {
556 if (nvdimm_bus->id == id) {
557 rc = __nd_ioctl(nvdimm_bus, NULL, read_only, cmd, arg);
558 break;
559 }
560 }
561 mutex_unlock(&nvdimm_bus_list_mutex);
562
563 return rc;
564}
565
566static int match_dimm(struct device *dev, void *data)
567{
568 long id = (long) data;
569
570 if (is_nvdimm(dev)) {
571 struct nvdimm *nvdimm = to_nvdimm(dev);
572
573 return nvdimm->id == id;
574 }
575
576 return 0;
577}
578
579static long nvdimm_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
580{
581 int rc = -ENXIO, read_only;
582 struct nvdimm_bus *nvdimm_bus;
583
584 read_only = (O_RDWR != (file->f_flags & O_ACCMODE));
585 mutex_lock(&nvdimm_bus_list_mutex);
586 list_for_each_entry(nvdimm_bus, &nvdimm_bus_list, list) {
587 struct device *dev = device_find_child(&nvdimm_bus->dev,
588 file->private_data, match_dimm);
589 struct nvdimm *nvdimm;
590
591 if (!dev)
592 continue;
593
594 nvdimm = to_nvdimm(dev);
595 rc = __nd_ioctl(nvdimm_bus, nvdimm, read_only, cmd, arg);
596 put_device(dev);
597 break;
598 }
599 mutex_unlock(&nvdimm_bus_list_mutex);
600
601 return rc;
602}
603
604static int nd_open(struct inode *inode, struct file *file)
605{
606 long minor = iminor(inode);
607
608 file->private_data = (void *) minor;
609 return 0;
45def22c
DW
610}
611
612static const struct file_operations nvdimm_bus_fops = {
613 .owner = THIS_MODULE,
62232e45 614 .open = nd_open,
45def22c
DW
615 .unlocked_ioctl = nd_ioctl,
616 .compat_ioctl = nd_ioctl,
617 .llseek = noop_llseek,
618};
619
62232e45
DW
620static const struct file_operations nvdimm_fops = {
621 .owner = THIS_MODULE,
622 .open = nd_open,
623 .unlocked_ioctl = nvdimm_ioctl,
624 .compat_ioctl = nvdimm_ioctl,
625 .llseek = noop_llseek,
626};
627
45def22c
DW
628int __init nvdimm_bus_init(void)
629{
630 int rc;
631
e6dfb2de
DW
632 rc = bus_register(&nvdimm_bus_type);
633 if (rc)
634 return rc;
635
45def22c
DW
636 rc = register_chrdev(0, "ndctl", &nvdimm_bus_fops);
637 if (rc < 0)
62232e45 638 goto err_bus_chrdev;
45def22c
DW
639 nvdimm_bus_major = rc;
640
62232e45
DW
641 rc = register_chrdev(0, "dimmctl", &nvdimm_fops);
642 if (rc < 0)
643 goto err_dimm_chrdev;
644 nvdimm_major = rc;
645
45def22c
DW
646 nd_class = class_create(THIS_MODULE, "nd");
647 if (IS_ERR(nd_class))
648 goto err_class;
649
650 return 0;
651
652 err_class:
62232e45
DW
653 unregister_chrdev(nvdimm_major, "dimmctl");
654 err_dimm_chrdev:
45def22c 655 unregister_chrdev(nvdimm_bus_major, "ndctl");
62232e45 656 err_bus_chrdev:
e6dfb2de 657 bus_unregister(&nvdimm_bus_type);
45def22c
DW
658
659 return rc;
660}
661
4d88a97a 662void nvdimm_bus_exit(void)
45def22c
DW
663{
664 class_destroy(nd_class);
665 unregister_chrdev(nvdimm_bus_major, "ndctl");
62232e45 666 unregister_chrdev(nvdimm_major, "dimmctl");
e6dfb2de 667 bus_unregister(&nvdimm_bus_type);
45def22c 668}