/** * pset_copy_set - copies property set * @pset: Property set to copy * * This function takes a deep copy of the given property set and returns * pointer to the copy. Call device_free_property_set() to free resources * allocated in this function. * * Return: Pointer to the new property set or error pointer. */ static struct property_set *pset_copy_set(const struct property_set *pset) { const struct property_entry *entry; struct property_set *p; size_t i, n = 0; p = kzalloc(sizeof(*p), GFP_KERNEL); if (!p) return ERR_PTR(-ENOMEM); while (pset->properties[n].name) n++; p->properties = kcalloc(n + 1, sizeof(*entry), GFP_KERNEL); if (!p->properties) { kfree(p); return ERR_PTR(-ENOMEM); } for (i = 0; i < n; i++) { int ret = pset_copy_entry(&p->properties[i], &pset->properties[i]); if (ret) { pset_free_set(p); return ERR_PTR(ret); } } return p; }
/** * device_remove_properties - Remove properties from a device object. * @dev: Device whose properties to remove. * * The function removes properties previously associated to the device * secondary firmware node with device_add_properties(). Memory allocated * to the properties will also be released. */ void device_remove_properties(struct device *dev) { struct fwnode_handle *fwnode; fwnode = dev_fwnode(dev); if (!fwnode) return; /* * Pick either primary or secondary node depending which one holds * the pset. If there is no real firmware node (ACPI/DT) primary * will hold the pset. */ if (is_pset_node(fwnode)) { set_primary_fwnode(dev, NULL); pset_free_set(to_pset_node(fwnode)); } else { fwnode = fwnode->secondary; if (!IS_ERR(fwnode) && is_pset_node(fwnode)) { set_secondary_fwnode(dev, NULL); pset_free_set(to_pset_node(fwnode)); } } }