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