2 * Copyright(c) 2013-2015 Intel Corporation. All rights reserved.
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.
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.
13 #include <linux/libnvdimm.h>
14 #include <linux/export.h>
15 #include <linux/module.h>
16 #include <linux/device.h>
17 #include <linux/slab.h>
20 static DEFINE_IDA(nd_ida
);
22 static void nvdimm_bus_release(struct device
*dev
)
24 struct nvdimm_bus
*nvdimm_bus
;
26 nvdimm_bus
= container_of(dev
, struct nvdimm_bus
, dev
);
27 ida_simple_remove(&nd_ida
, nvdimm_bus
->id
);
31 struct nvdimm_bus
*nvdimm_bus_register(struct device
*parent
,
32 struct nvdimm_bus_descriptor
*nd_desc
)
34 struct nvdimm_bus
*nvdimm_bus
;
37 nvdimm_bus
= kzalloc(sizeof(*nvdimm_bus
), GFP_KERNEL
);
40 nvdimm_bus
->id
= ida_simple_get(&nd_ida
, 0, 0, GFP_KERNEL
);
41 if (nvdimm_bus
->id
< 0) {
45 nvdimm_bus
->nd_desc
= nd_desc
;
46 nvdimm_bus
->dev
.parent
= parent
;
47 nvdimm_bus
->dev
.release
= nvdimm_bus_release
;
48 dev_set_name(&nvdimm_bus
->dev
, "ndbus%d", nvdimm_bus
->id
);
49 rc
= device_register(&nvdimm_bus
->dev
);
51 dev_dbg(&nvdimm_bus
->dev
, "registration failed: %d\n", rc
);
52 put_device(&nvdimm_bus
->dev
);
58 EXPORT_SYMBOL_GPL(nvdimm_bus_register
);
60 void nvdimm_bus_unregister(struct nvdimm_bus
*nvdimm_bus
)
64 device_unregister(&nvdimm_bus
->dev
);
66 EXPORT_SYMBOL_GPL(nvdimm_bus_unregister
);
68 MODULE_LICENSE("GPL v2");
69 MODULE_AUTHOR("Intel Corporation");
This page took 0.03244 seconds and 5 git commands to generate.