Skip to contentSkip to conversation

soundwire: Use scope-based resource management in five functions

PATCH New Markus Elfring 1 participant 1 message Jun 4, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 soundwire: Use scope-based resource management in five functions

From: Markus Elfring <[email protected]>
Date: Tue, 4 Jun 2024 12:30:40 +0200

Scope-based resource management became supported also for another programming interface by contributions of Jonathan Cameron on 2024-02-17. See also the commit 59ed5e2d505bf5f9b4af64d0021cd0c96aec1f7c ("device
property: Add cleanup.h based fwnode_handle_put() scope based cleanup.").

* Thus use the attribute “__free(fwnode_handle)” at more places.

* Reduce scopes for corresponding local variables.

* Omit explicit fwnode_handle_put() calls accordingly.

---

Previous clarification approach:
soundwire: fix usages of device_get_named_child_node()
https://lore.kernel.org/lkml/[email protected]/
https://lkml.org/lkml/2024/5/28/1138

 drivers/soundwire/amd_manager.c     |  9 ++---
 drivers/soundwire/intel_auxdevice.c | 12 ++----
 drivers/soundwire/mipi_disco.c      | 62 +++++++++++------------------
 3 files changed, 31 insertions(+), 52 deletions(-)
drivers/soundwire/amd_manager.c +4 -5
index 795e223f7e5c..94b867700b2d 100644
@@ -15,6 +15,7 @@
 #include <linux/soundwire/sdw.h>
 #include <linux/soundwire/sdw_registers.h>
 #include <linux/pm_runtime.h>
+#include <linux/property.h>
 #include <linux/wait.h>
 #include <sound/pcm_params.h>
 #include <sound/soc.h>
@@ -546,7 +547,6 @@ static int amd_sdw_port_enable(struct sdw_bus *bus,
 static int sdw_master_read_amd_prop(struct sdw_bus *bus)
 {
 	struct amd_sdw_manager *amd_manager = to_amd_sdw(bus);
-	struct fwnode_handle *link;
 	struct sdw_master_prop *prop;
 	u32 quirk_mask = 0;
 	u32 wake_en_mask = 0;
@@ -556,7 +556,9 @@ static int sdw_master_read_amd_prop(struct sdw_bus *bus)
 	prop = &bus->prop;
 	/* Find manager handle */
 	snprintf(name, sizeof(name), "mipi-sdw-link-%d-subproperties", bus->link_id);
-	link = device_get_named_child_node(bus->dev, name);
+
+	struct fwnode_handle *link __free(fwnode_handle)
+				   = device_get_named_child_node(bus->dev, name);
 	if (!link) {
 		dev_err(bus->dev, "Manager node %s not found\n", name);
 		return -EIO;
@@ -571,9 +573,6 @@ static int sdw_master_read_amd_prop(struct sdw_bus *bus)
 	amd_manager->wake_en_mask = wake_en_mask;
 	fwnode_property_read_u32(link, "amd-sdw-power-mode", &power_mode_mask);
 	amd_manager->power_mode_mask = power_mode_mask;
-
-	fwnode_handle_put(link);
-
 	return 0;
 }
 
drivers/soundwire/intel_auxdevice.c +4 -8
index fd29f4ee6970..17ad3191ecc3 100644
@@ -14,6 +14,7 @@
 #include <linux/auxiliary_bus.h>
 #include <sound/pcm_params.h>
 #include <linux/pm_runtime.h>
+#include <linux/property.h>
 #include <sound/soc.h>
 #include <linux/soundwire/sdw_registers.h>
 #include <linux/soundwire/sdw.h>
@@ -123,7 +124,6 @@ static int sdw_master_read_intel_prop(struct sdw_bus *bus)
 {
 	struct sdw_master_prop *prop = &bus->prop;
 	struct sdw_intel_prop *intel_prop;
-	struct fwnode_handle *link;
 	char name[32];
 	u32 quirk_mask;
 
@@ -131,7 +131,8 @@ static int sdw_master_read_intel_prop(struct sdw_bus *bus)
 	snprintf(name, sizeof(name),
 		 "mipi-sdw-link-%d-subproperties", bus->link_id);
 
-	link = device_get_named_child_node(bus->dev, name);
+	struct fwnode_handle *link __free(fwnode_handle)
+				   = device_get_named_child_node(bus->dev, name);
 	if (!link) {
 		dev_err(bus->dev, "Master node %s not found\n", name);
 		return -EIO;
@@ -155,10 +156,8 @@ static int sdw_master_read_intel_prop(struct sdw_bus *bus)
 		SDW_MASTER_QUIRKS_CLEAR_INITIAL_PARITY;
 
 	intel_prop = devm_kzalloc(bus->dev, sizeof(*intel_prop), GFP_KERNEL);
-	if (!intel_prop) {
-		fwnode_handle_put(link);
+	if (!intel_prop)
 		return -ENOMEM;
-	}
 
 	/* initialize with hardware defaults, in case the properties are not found */
 	intel_prop->clde = 0x0;
@@ -205,9 +204,6 @@ static int sdw_master_read_intel_prop(struct sdw_bus *bus)
 		intel_prop->doais,
 		intel_prop->dodse,
 		intel_prop->dods);
-
-	fwnode_handle_put(link);
-
 	return 0;
 }
 
drivers/soundwire/mipi_disco.c +23 -39

146 lines not on this page · raw message

--
2.45.1