Patch "software node: Provide replacement for device_add_properties()" has been added to the 5.10-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    software node: Provide replacement for device_add_properties()

to the 5.10-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     software-node-provide-replacement-for-device_add_pro.patch
and it can be found in the queue-5.10 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 3995588dbe6584f277a9a6d92164ade46144c9dc
Author: Heikki Krogerus <heikki.krogerus@xxxxxxxxxxxxxxx>
Date:   Thu Feb 4 17:17:06 2021 +0300

    software node: Provide replacement for device_add_properties()
    
    [ Upstream commit 151f6ff78cdf1d6de76e90556cfc43f1e48abe18 ]
    
    At the moment the function device_del() is calling
    device_remove_properties() unconditionally. That will result into the
    reference count of the software node attached to the device being
    decremented, and in most cases it will hit 0 at that point. So in
    practice device_del() will unregister the software node attached to
    the device, even if that was not the intention of the caller. Right
    now software nodes can not be reused or shared because of that.
    
    So device_del() can not unregister the software nodes unconditionally
    like that. Unfortunately some of the users of device_add_properties()
    are now relying on this behaviour. Because of that, and also in
    general, we do need a function that can offer similar behaviour where
    the lifetime of the software node is bound to the lifetime of the
    device. But it just has to be a separate function so the behaviour is
    optional. We can not remove the device_remove_properties() call from
    device_del() before we have that new function, and before we have
    replaced device_add_properties() calls with it in all the places that
    require that behaviour.
    
    This adds function device_create_managed_software_node() that can be
    used for exactly that purpose. Software nodes created with it are
    declared "managed", and separate handling for those nodes is added to
    the software node code. The reference count of the "managed" nodes is
    decremented when the device they are attached to is removed. This will
    not affect the other nodes that are not declared "managed".
    
    The function device_create_managed_software_node() has also one
    additional feature that device_add_properties() does not have. It
    allows the software nodes created with it to be part of a node
    hierarchy by taking also an optional parent node as parameter.
    
    Reviewed-by: Rafael J. Wysocki <rafael.j.wysocki@xxxxxxxxx>
    Signed-off-by: Heikki Krogerus <heikki.krogerus@xxxxxxxxxxxxxxx>
    Link: https://lore.kernel.org/r/20210204141711.53775-2-heikki.krogerus@xxxxxxxxxxxxxxx
    Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
    Stable-dep-of: dbcbfd662a72 ("platform/x86: touchscreen_dmi: Allow partial (prefix) matches for ACPI names")
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c
index ad66d7c545f92..f9069180f2428 100644
--- a/drivers/base/swnode.c
+++ b/drivers/base/swnode.c
@@ -24,6 +24,7 @@ struct swnode {
 	struct swnode *parent;
 
 	unsigned int allocated:1;
+	unsigned int managed:1;
 };
 
 static DEFINE_IDA(swnode_root_ids);
@@ -913,6 +914,43 @@ void device_remove_software_node(struct device *dev)
 }
 EXPORT_SYMBOL_GPL(device_remove_software_node);
 
+/**
+ * device_create_managed_software_node - Create a software node for a device
+ * @dev: The device the software node is assigned to.
+ * @properties: Device properties for the software node.
+ * @parent: Parent of the software node.
+ *
+ * Creates a software node as a managed resource for @dev, which means the
+ * lifetime of the newly created software node is tied to the lifetime of @dev.
+ * Software nodes created with this function should not be reused or shared
+ * because of that. The function takes a deep copy of @properties for the
+ * software node.
+ *
+ * Since the new software node is assigned directly to @dev, and since it should
+ * not be shared, it is not returned to the caller. The function returns 0 on
+ * success, and errno in case of an error.
+ */
+int device_create_managed_software_node(struct device *dev,
+					const struct property_entry *properties,
+					const struct software_node *parent)
+{
+	struct fwnode_handle *p = software_node_fwnode(parent);
+	struct fwnode_handle *fwnode;
+
+	if (parent && !p)
+		return -EINVAL;
+
+	fwnode = fwnode_create_software_node(properties, p);
+	if (IS_ERR(fwnode))
+		return PTR_ERR(fwnode);
+
+	to_swnode(fwnode)->managed = true;
+	set_secondary_fwnode(dev, fwnode);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(device_create_managed_software_node);
+
 int software_node_notify(struct device *dev, unsigned long action)
 {
 	struct swnode *swnode;
@@ -941,6 +979,11 @@ int software_node_notify(struct device *dev, unsigned long action)
 		sysfs_remove_link(&swnode->kobj, dev_name(dev));
 		sysfs_remove_link(&dev->kobj, "software_node");
 		kobject_put(&swnode->kobj);
+
+		if (swnode->managed) {
+			set_secondary_fwnode(dev, NULL);
+			kobject_put(&swnode->kobj);
+		}
 		break;
 	default:
 		break;
diff --git a/include/linux/property.h b/include/linux/property.h
index 3b6093f6bd04c..d339b835c7766 100644
--- a/include/linux/property.h
+++ b/include/linux/property.h
@@ -488,4 +488,8 @@ void fwnode_remove_software_node(struct fwnode_handle *fwnode);
 int device_add_software_node(struct device *dev, const struct software_node *swnode);
 void device_remove_software_node(struct device *dev);
 
+int device_create_managed_software_node(struct device *dev,
+					const struct property_entry *properties,
+					const struct software_node *parent);
+
 #endif /* _LINUX_PROPERTY_H_ */




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux