* [PATCH] iio: adc: mcp3564.c: Use device_for_each_child_node_scoped() to simplify error paths
@ 2024-05-23 16:24 Vinícius Lima
2024-05-23 16:39 ` Jonathan Cameron
0 siblings, 1 reply; 2+ messages in thread
From: Vinícius Lima @ 2024-05-23 16:24 UTC (permalink / raw)
To: marius.cristea, jic23
Cc: Vinícius Henrique Ferraz Lima, Lucas Quaresma, linux-iio
From: Vinícius Henrique Ferraz Lima <viniciusflima@usp.br>
Use another method to automatically release the handle on early exit,
reducing leaks.
Co-developed-by: Lucas Quaresma <lucasqml08@usp.br>
Signed-off-by: Lucas Quaresma <lucasqml08@usp.br>
Signed-off-by: Vinícius Lima <viniciusflima@usp.br>
---
drivers/iio/adc/mcp3564.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/drivers/iio/adc/mcp3564.c b/drivers/iio/adc/mcp3564.c
index 311b613b6..52c864974 100644
--- a/drivers/iio/adc/mcp3564.c
+++ b/drivers/iio/adc/mcp3564.c
@@ -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,
--
2.45.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] iio: adc: mcp3564.c: Use device_for_each_child_node_scoped() to simplify error paths
2024-05-23 16:24 [PATCH] iio: adc: mcp3564.c: Use device_for_each_child_node_scoped() to simplify error paths Vinícius Lima
@ 2024-05-23 16:39 ` Jonathan Cameron
0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Cameron @ 2024-05-23 16:39 UTC (permalink / raw)
To: Vinícius Lima; +Cc: marius.cristea, jic23, Lucas Quaresma, linux-iio
On Thu, 23 May 2024 13:24:35 -0300
Vinícius Lima <viniciusflima@usp.br> wrote:
> From: Vinícius Henrique Ferraz Lima <viniciusflima@usp.br>
>
> Use another method to automatically release the handle on early exit,
> reducing leaks.
>
> Co-developed-by: Lucas Quaresma <lucasqml08@usp.br>
> Signed-off-by: Lucas Quaresma <lucasqml08@usp.br>
> Signed-off-by: Vinícius Lima <viniciusflima@usp.br>
> ---
> drivers/iio/adc/mcp3564.c | 5 +----
> 1 file changed, 1 insertion(+), 4 deletions(-)
>
> diff --git a/drivers/iio/adc/mcp3564.c b/drivers/iio/adc/mcp3564.c
> index 311b613b6..52c864974 100644
> --- a/drivers/iio/adc/mcp3564.c
> +++ b/drivers/iio/adc/mcp3564.c
> @@ -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);
Drop the {} as well if there is only one statement left after removing
the fwnode_handle_put()
> return ret;
> }
>
> if (inputs[0] > MCP3564_INTERNAL_VCM ||
> inputs[1] > MCP3564_INTERNAL_VCM) {
{} can go here as well,
Otherwise looks good.
Thanks,
Jonathan
> - fwnode_handle_put(child);
> return dev_err_probe(&indio_dev->dev, -EINVAL,
> "Channel index > %d, for %s\n",
> MCP3564_INTERNAL_VCM + 1,
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-05-23 16:39 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-23 16:24 [PATCH] iio: adc: mcp3564.c: Use device_for_each_child_node_scoped() to simplify error paths Vinícius Lima
2024-05-23 16:39 ` Jonathan Cameron
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox