treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / nvdimm / of_pmem.c
blob8224d1431ea9412c55eeda35f16d252c51fee9e1
1 // SPDX-License-Identifier: GPL-2.0+
3 #define pr_fmt(fmt) "of_pmem: " fmt
5 #include <linux/of_platform.h>
6 #include <linux/of_address.h>
7 #include <linux/libnvdimm.h>
8 #include <linux/module.h>
9 #include <linux/ioport.h>
10 #include <linux/slab.h>
12 struct of_pmem_private {
13 struct nvdimm_bus_descriptor bus_desc;
14 struct nvdimm_bus *bus;
17 static int of_pmem_region_probe(struct platform_device *pdev)
19 struct of_pmem_private *priv;
20 struct device_node *np;
21 struct nvdimm_bus *bus;
22 bool is_volatile;
23 int i;
25 np = dev_of_node(&pdev->dev);
26 if (!np)
27 return -ENXIO;
29 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
30 if (!priv)
31 return -ENOMEM;
33 priv->bus_desc.provider_name = kstrdup(pdev->name, GFP_KERNEL);
34 priv->bus_desc.module = THIS_MODULE;
35 priv->bus_desc.of_node = np;
37 priv->bus = bus = nvdimm_bus_register(&pdev->dev, &priv->bus_desc);
38 if (!bus) {
39 kfree(priv);
40 return -ENODEV;
42 platform_set_drvdata(pdev, priv);
44 is_volatile = !!of_find_property(np, "volatile", NULL);
45 dev_dbg(&pdev->dev, "Registering %s regions from %pOF\n",
46 is_volatile ? "volatile" : "non-volatile", np);
48 for (i = 0; i < pdev->num_resources; i++) {
49 struct nd_region_desc ndr_desc;
50 struct nd_region *region;
53 * NB: libnvdimm copies the data from ndr_desc into it's own
54 * structures so passing a stack pointer is fine.
56 memset(&ndr_desc, 0, sizeof(ndr_desc));
57 ndr_desc.numa_node = dev_to_node(&pdev->dev);
58 ndr_desc.target_node = ndr_desc.numa_node;
59 ndr_desc.res = &pdev->resource[i];
60 ndr_desc.of_node = np;
61 set_bit(ND_REGION_PAGEMAP, &ndr_desc.flags);
63 if (is_volatile)
64 region = nvdimm_volatile_region_create(bus, &ndr_desc);
65 else
66 region = nvdimm_pmem_region_create(bus, &ndr_desc);
68 if (!region)
69 dev_warn(&pdev->dev, "Unable to register region %pR from %pOF\n",
70 ndr_desc.res, np);
71 else
72 dev_dbg(&pdev->dev, "Registered region %pR from %pOF\n",
73 ndr_desc.res, np);
76 return 0;
79 static int of_pmem_region_remove(struct platform_device *pdev)
81 struct of_pmem_private *priv = platform_get_drvdata(pdev);
83 nvdimm_bus_unregister(priv->bus);
84 kfree(priv);
86 return 0;
89 static const struct of_device_id of_pmem_region_match[] = {
90 { .compatible = "pmem-region" },
91 { },
94 static struct platform_driver of_pmem_region_driver = {
95 .probe = of_pmem_region_probe,
96 .remove = of_pmem_region_remove,
97 .driver = {
98 .name = "of_pmem",
99 .of_match_table = of_pmem_region_match,
103 module_platform_driver(of_pmem_region_driver);
104 MODULE_DEVICE_TABLE(of, of_pmem_region_match);
105 MODULE_LICENSE("GPL");
106 MODULE_AUTHOR("IBM Corporation");