treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / nvdimm / e820.c
blobe02f60ad6c99fc02f91d75274eb32eccc2867548
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Copyright (c) 2015, Christoph Hellwig.
4 * Copyright (c) 2015, Intel Corporation.
5 */
6 #include <linux/platform_device.h>
7 #include <linux/memory_hotplug.h>
8 #include <linux/libnvdimm.h>
9 #include <linux/module.h>
11 static int e820_pmem_remove(struct platform_device *pdev)
13 struct nvdimm_bus *nvdimm_bus = platform_get_drvdata(pdev);
15 nvdimm_bus_unregister(nvdimm_bus);
16 return 0;
19 #ifdef CONFIG_MEMORY_HOTPLUG
20 static int e820_range_to_nid(resource_size_t addr)
22 return memory_add_physaddr_to_nid(addr);
24 #else
25 static int e820_range_to_nid(resource_size_t addr)
27 return NUMA_NO_NODE;
29 #endif
31 static int e820_register_one(struct resource *res, void *data)
33 struct nd_region_desc ndr_desc;
34 struct nvdimm_bus *nvdimm_bus = data;
36 memset(&ndr_desc, 0, sizeof(ndr_desc));
37 ndr_desc.res = res;
38 ndr_desc.numa_node = e820_range_to_nid(res->start);
39 ndr_desc.target_node = ndr_desc.numa_node;
40 set_bit(ND_REGION_PAGEMAP, &ndr_desc.flags);
41 if (!nvdimm_pmem_region_create(nvdimm_bus, &ndr_desc))
42 return -ENXIO;
43 return 0;
46 static int e820_pmem_probe(struct platform_device *pdev)
48 static struct nvdimm_bus_descriptor nd_desc;
49 struct device *dev = &pdev->dev;
50 struct nvdimm_bus *nvdimm_bus;
51 int rc = -ENXIO;
53 nd_desc.provider_name = "e820";
54 nd_desc.module = THIS_MODULE;
55 nvdimm_bus = nvdimm_bus_register(dev, &nd_desc);
56 if (!nvdimm_bus)
57 goto err;
58 platform_set_drvdata(pdev, nvdimm_bus);
60 rc = walk_iomem_res_desc(IORES_DESC_PERSISTENT_MEMORY_LEGACY,
61 IORESOURCE_MEM, 0, -1, nvdimm_bus, e820_register_one);
62 if (rc)
63 goto err;
64 return 0;
65 err:
66 nvdimm_bus_unregister(nvdimm_bus);
67 dev_err(dev, "failed to register legacy persistent memory ranges\n");
68 return rc;
71 static struct platform_driver e820_pmem_driver = {
72 .probe = e820_pmem_probe,
73 .remove = e820_pmem_remove,
74 .driver = {
75 .name = "e820_pmem",
79 module_platform_driver(e820_pmem_driver);
81 MODULE_ALIAS("platform:e820_pmem*");
82 MODULE_LICENSE("GPL v2");
83 MODULE_AUTHOR("Intel Corporation");