Skip to contentSkip to conversation

iio: adc: mcp3564.c: Use device_for_each_child_node_scoped() to simplify error paths

PATCH In review Vinícius Lima 2 participants 2 messages May 23, 2024

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

PATCH 1/1 iio: adc: mcp3564.c: Use device_for_each_child_node_scoped() to simplify error paths

From: Vinícius Henrique Ferraz Lima <[email protected]>

Use another method to automatically release the handle on early exit, reducing leaks.

---
 drivers/iio/adc/mcp3564.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/iio/adc/mcp3564.c +1 -4
index 311b613b6..52c864974 100644
@@ -998,7 +998,6 @@ static int mcp3564_parse_fw_children(struct iio_dev *indio_dev)
 	struct mcp3564_state *adc = iio_priv(indio_dev);
 	struct device *dev = &adc->spi->dev;
 	struct iio_chan_spec *channels;
-	struct fwnode_handle *child;
 	struct iio_chan_spec chanspec = mcp3564_channel_template;
 	struct iio_chan_spec temp_chanspec = mcp3564_temp_channel_template;
 	struct iio_chan_spec burnout_chanspec = mcp3564_burnout_channel_template;
@@ -1025,7 +1024,7 @@ static int mcp3564_parse_fw_children(struct iio_dev *indio_dev)
 	if (!channels)
 		return dev_err_probe(dev, -ENOMEM, "Can't allocate memory\n");
 
-	device_for_each_child_node(dev, child) {
+	device_for_each_child_node_scoped(dev, child) {
 		node_name = fwnode_get_name(child);
 
 		if (fwnode_property_present(child, "diff-channels")) {
@@ -1041,13 +1040,11 @@ static int mcp3564_parse_fw_children(struct iio_dev *indio_dev)
 			inputs[1] = MCP3564_AGND;
 		}
 		if (ret) {
-			fwnode_handle_put(child);
 			return ret;
 		}
 
 		if (inputs[0] > MCP3564_INTERNAL_VCM ||
 		    inputs[1] > MCP3564_INTERNAL_VCM) {
-			fwnode_handle_put(child);
 			return dev_err_probe(&indio_dev->dev, -EINVAL,
 					     "Channel index > %d, for %s\n",
 					     MCP3564_INTERNAL_VCM + 1,
Signature · 1 line
2.45.0
#1 lore raw
Quoted 34 lines · On Thu, 23 May 2024 13:24:35 -0300 Vinícius Lima <[email protected]> wrote:

From: Vinícius Henrique Ferraz Lima <[email protected]>

Use another method to automatically release the handle on early exit, reducing leaks.

---
 drivers/iio/adc/mcp3564.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/iio/adc/mcp3564.c +1 -2
index 311b613b6..52c864974 100644
@@ -998,7 +998,6 @@ static int mcp3564_parse_fw_children(struct iio_dev *indio_dev)
 	struct mcp3564_state *adc = iio_priv(indio_dev);
 	struct device *dev = &adc->spi->dev;
 	struct iio_chan_spec *channels;
-	struct fwnode_handle *child;
 	struct iio_chan_spec chanspec = mcp3564_channel_template;
 	struct iio_chan_spec temp_chanspec = mcp3564_temp_channel_template;
 	struct iio_chan_spec burnout_chanspec = mcp3564_burnout_channel_template;
@@ -1025,7 +1024,7 @@ static int mcp3564_parse_fw_children(struct iio_dev *indio_dev)
 	if (!channels)
 		return dev_err_probe(dev, -ENOMEM, "Can't allocate memory\n");
 
-	device_for_each_child_node(dev, child) {
+	device_for_each_child_node_scoped(dev, child) {
 		node_name = fwnode_get_name(child);
 
 		if (fwnode_property_present(child, "diff-channels")) {

drivers/iio/adc/mcp3564.c static int mcp3564_parse_fw_children(struct iio_dev *indio_dev) · line 1044

Quoted 4 lines
drivers/iio/adc/mcp3564.c +0 -1
@@ -1041,13 +1040,11 @@ static int mcp3564_parse_fw_children(struct iio_dev *indio_dev)
 			inputs[1] = MCP3564_AGND;
 		}
 		if (ret) {
-			fwnode_handle_put(child);

Drop the {} as well if there is only one statement left after removing the fwnode_handle_put()

drivers/iio/adc/mcp3564.c static int mcp3564_parse_fw_children(struct iio_dev *indio_dev) · line 1047

Quoted 5 lines
drivers/iio/adc/mcp3564.c +0 -0
 			return ret;
 		}
 
 		if (inputs[0] > MCP3564_INTERNAL_VCM ||
 		    inputs[1] > MCP3564_INTERNAL_VCM) {

{} can go here as well,

Otherwise looks good.

Thanks,

Jonathan

Quoted 4 lines
drivers/iio/adc/mcp3564.c +0 -1
-			fwnode_handle_put(child);
 			return dev_err_probe(&indio_dev->dev, -EINVAL,
 					     "Channel index > %d, for %s\n",
 					     MCP3564_INTERNAL_VCM + 1,