Multiple error paths have been added after initializing 'link' and
'node' via device_get_named_child_node(), which requires explicit calls
to fwnode_handle_put() when the variable is not longer required.
Instead of adding the missing calls to fwnode_handle_put(), and
considering that the bug was recently introduced, use the __free() macro
to automatically release the nodes when they go out of scope. This
approach removes the need for explicit calls to fwnode_handle_put() and
is more robust in case new error paths are added again.
Fixes: a489afc105ed ("soundwire: mipi-disco: add error handling for property array read")
Signed-off-by: Javier Carrasco <javier.carrasco.cruz@xxxxxxxxx>
---
drivers/soundwire/mipi_disco.c | 32 +++++++++-----------------------
1 file changed, 9 insertions(+), 23 deletions(-)
diff --git a/drivers/soundwire/mipi_disco.c b/drivers/soundwire/mipi_disco.c
index 9d59f486edbe..cd1f0f8d07da 100644
--- a/drivers/soundwire/mipi_disco.c
+++ b/drivers/soundwire/mipi_disco.c
@@ -50,7 +50,6 @@ static bool mipi_device_property_read_bool(const struct device *dev,
int sdw_master_read_prop(struct sdw_bus *bus)
{
struct sdw_master_prop *prop = &bus->prop;
- struct fwnode_handle *link;
const char *scales_prop;
char name[32];
int nval;
@@ -65,7 +64,8 @@ int sdw_master_read_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;
@@ -89,10 +89,8 @@ int sdw_master_read_prop(struct sdw_bus *bus)
prop->clk_freq = devm_kcalloc(bus->dev, prop->num_clk_freq,
sizeof(*prop->clk_freq),
GFP_KERNEL);
- if (!prop->clk_freq) {
- fwnode_handle_put(link);
+ if (!prop->clk_freq)
return -ENOMEM;
- }
ret = fwnode_property_read_u32_array(link,
"mipi-sdw-clock-frequencies-supported",
@@ -124,10 +122,8 @@ int sdw_master_read_prop(struct sdw_bus *bus)
prop->clk_gears = devm_kcalloc(bus->dev, prop->num_clk_gears,
sizeof(*prop->clk_gears),
GFP_KERNEL);
- if (!prop->clk_gears) {
- fwnode_handle_put(link);
+ if (!prop->clk_gears)
return -ENOMEM;
- }
ret = fwnode_property_read_u32_array(link,
scales_prop,
@@ -152,8 +148,6 @@ int sdw_master_read_prop(struct sdw_bus *bus)
fwnode_property_read_u32(link, "mipi-sdw-command-error-threshold",
&prop->err_threshold);
- fwnode_handle_put(link);
-
return 0;
}
EXPORT_SYMBOL(sdw_master_read_prop);
@@ -220,7 +214,6 @@ static int sdw_slave_read_dpn(struct sdw_slave *slave,
struct sdw_dpn_prop *dpn, int count, int ports,
char *type)
{
- struct fwnode_handle *node;
u32 bit, i = 0;
unsigned long addr;
char name[40];
@@ -237,7 +230,8 @@ static int sdw_slave_read_dpn(struct sdw_slave *slave,
dpn[i].num = bit;
- node = device_get_named_child_node(&slave->dev, name);
+ struct fwnode_handle *node __free(fwnode_handle) =
+ device_get_named_child_node(&slave->dev, name);
if (!node) {
dev_err(&slave->dev, "%s dpN not found\n", name);
return -EIO;
@@ -255,10 +249,8 @@ static int sdw_slave_read_dpn(struct sdw_slave *slave,
dpn[i].num_words,
sizeof(*dpn[i].words),
GFP_KERNEL);
- if (!dpn[i].words) {
- fwnode_handle_put(node);
+ if (!dpn[i].words)
return -ENOMEM;
- }
ret = fwnode_property_read_u32_array(node,
"mipi-sdw-port-wordlength-configs",
@@ -298,10 +290,8 @@ static int sdw_slave_read_dpn(struct sdw_slave *slave,
dpn[i].num_channels,
sizeof(*dpn[i].channels),
GFP_KERNEL);
- if (!dpn[i].channels) {
- fwnode_handle_put(node);
+ if (!dpn[i].channels)
return -ENOMEM;
- }
ret = fwnode_property_read_u32_array(node,
"mipi-sdw-channel-number-list",
@@ -317,10 +307,8 @@ static int sdw_slave_read_dpn(struct sdw_slave *slave,
dpn[i].num_ch_combinations,
sizeof(*dpn[i].ch_combinations),
GFP_KERNEL);
- if (!dpn[i].ch_combinations) {
- fwnode_handle_put(node);
+ if (!dpn[i].ch_combinations)
return -ENOMEM;
- }
ret = fwnode_property_read_u32_array(node,
"mipi-sdw-channel-combination-list",
@@ -358,8 +346,6 @@ static int sdw_slave_read_dpn(struct sdw_slave *slave,
return ret;
}
- fwnode_handle_put(node);
-
i++;
}
---
base-commit: f2493655d2d3d5c6958ed996b043c821c23ae8d3
change-id: 20241019-mipi_disco-of_node_put-89547baf2157
Best regards,
--
Javier Carrasco <javier.carrasco.cruz@xxxxxxxxx>
[Index of Archives]
[Pulseaudio]
[Linux Audio Users]
[ALSA Devel]
[Fedora Desktop]
[Fedora SELinux]
[Big List of Linux Books]
[Yosemite News]
[KDE Users]