diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c
index dda6092e6d3a..3c693b091ecf 100644
--- a/drivers/of/dynamic.c
+++ b/drivers/of/dynamic.c
@@ -492,21 +492,29 @@ struct device_node *__of_node_dup(const struct
device_node *np,
* a given changeset.
*
* @ocs: Pointer to changeset
+ * @np: Pointer to device node. If it is not null, init it directly instead
of
+ * allocate a new node.
* @parent: Pointer to parent device node
* @full_name: Node full name
*
* Return: Pointer to the created device node or NULL in case of an error.
*/
struct device_node *of_changeset_create_node(struct of_changeset *ocs,
+ struct device_node *np,
struct device_node *parent,
const char *full_name)
{
- struct device_node *np;
int ret;
- np = __of_node_dup(NULL, full_name);
- if (!np)
- return NULL;
+ if (!np) {
+ np = __of_node_dup(NULL, full_name);
+ if (!np)
+ return NULL;
+ } else {
+ of_node_set_flag(np, OF_DYNAMIC);
+ of_node_set_flag(np, OF_DETACHED);
+ }
+
np->parent = parent;
ret = of_changeset_attach_node(ocs, np);
diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c
index 445ad13dab98..087de26852cc 100644
--- a/drivers/of/unittest.c
+++ b/drivers/of/unittest.c
@@ -871,7 +871,7 @@ static void __init of_unittest_changeset(void)
unittest(!of_changeset_add_property(&chgset, parent, ppadd), "fail
add prop prop-add\n");
unittest(!of_changeset_update_property(&chgset, parent, ppupdate),
"fail update prop\n");
unittest(!of_changeset_remove_property(&chgset, parent, ppremove),
"fail remove prop\n");
- n22 = of_changeset_create_node(&chgset, n2, "n22");
+ n22 = of_changeset_create_node(&chgset, NULL, n2, "n22");
unittest(n22, "fail create n22\n");
unittest(!of_changeset_add_prop_string(&chgset, n22, "prop-str",
"abcd"),
"fail add prop prop-str");
diff --git a/drivers/pci/of.c b/drivers/pci/of.c
index 51e3dd0ea5ab..92c079b2e570 100644
--- a/drivers/pci/of.c
+++ b/drivers/pci/of.c
@@ -608,18 +608,28 @@ int devm_of_pci_bridge_init(struct device *dev, struct
pci_host_bridge *bridge)
#ifdef CONFIG_PCI_DYNAMIC_OF_NODES
+void of_pci_free_node(struct device_node *np)
+{
+ struct of_changeset *cset;
+
+ cset = (struct of_changeset *)(np + 1);
+
+ np->data = NULL;
+ of_changeset_revert(cset);
+ of_changeset_destroy(cset);
+ of_node_put(np);
+}
+
void of_pci_remove_node(struct pci_dev *pdev)
{
struct device_node *np;
np = pci_device_to_OF_node(pdev);
- if (!np || !of_node_check_flag(np, OF_DYNAMIC))
+ if (!np || np->data != of_pci_free_node)
return;
pdev->dev.of_node = NULL;
- of_changeset_revert(np->data);
- of_changeset_destroy(np->data);
- of_node_put(np);
+ of_pci_free_node(np);
}
void of_pci_make_dev_node(struct pci_dev *pdev)
@@ -655,14 +665,18 @@ void of_pci_make_dev_node(struct pci_dev *pdev)
if (!name)
return;
- cset = kmalloc(sizeof(*cset), GFP_KERNEL);
- if (!cset)
+ np = kzalloc(sizeof(*np) + sizeof(*cset), GFP_KERNEL);
+ if (!np)
goto out_free_name;
+ np->full_name = name;
+ of_node_init(np);
+
+ cset = (struct of_changeset *)(np + 1);
of_changeset_init(cset);
- np = of_changeset_create_node(cset, ppnode, name);
+ np = of_changeset_create_node(cset, np, ppnode, NULL);
if (!np)
- goto out_destroy_cset;
+ goto out_free_node;
ret = of_pci_add_properties(pdev, cset, np);
if (ret)
@@ -672,9 +686,8 @@ void of_pci_make_dev_node(struct pci_dev *pdev)
if (ret)
goto out_free_node;
- np->data = cset;
+ np->data = of_pci_free_node;
pdev->dev.of_node = np;
- kfree(name);
return;
diff --git a/include/linux/of.h b/include/linux/of.h
index a0bedd038a05..f774459d0d84 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -1631,6 +1631,7 @@ static inline int of_changeset_update_property(struct
of_changeset *ocs,
}
struct device_node *of_changeset_create_node(struct of_changeset *ocs,
+ struct device_node *np,
struct device_node *parent,
const char *full_name);
int of_changeset_add_prop_string(struct of_changeset *ocs,
Thanks,
Lizhi
---
drivers/pci/remove.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/pci/remove.c b/drivers/pci/remove.c
index d749ea8250d6..4e51c64af416 100644
--- a/drivers/pci/remove.c
+++ b/drivers/pci/remove.c
@@ -22,7 +22,8 @@ static void pci_stop_dev(struct pci_dev *dev)
device_release_driver(&dev->dev);
pci_proc_detach_device(dev);
pci_remove_sysfs_dev_files(dev);
- of_pci_remove_node(dev);
+ if (pci_is_bridge(dev))
+ of_pci_remove_node(dev);
IIUC, this basically undoes the work that was done by
of_pci_make_dev_node().
The call of of_pci_make_dev_node() from pci_bus_add_device() was added
by 407d1a51921e and is conditional on pci_is_bridge(), so it makes
sense to me that the remove needs a similar condition.
pci_dev_assign_added(dev, false);
}
base-commit: e9d22f7a6655941fc8b2b942ed354ec780936b3e
--
2.45.2