linux-hwmon.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 1/1] hwmon: (ltc2992) Put fwnode in error case during ->probe()
@ 2021-05-10 10:01 Andy Shevchenko
  2021-05-10 15:02 ` Guenter Roeck
  0 siblings, 1 reply; 2+ messages in thread
From: Andy Shevchenko @ 2021-05-10 10:01 UTC (permalink / raw)
  To: Guenter Roeck, Alexandru Tachici, linux-hwmon, linux-kernel
  Cc: Jean Delvare, Andy Shevchenko

In each iteration fwnode_for_each_available_child_node() bumps a reference
counting of a loop variable followed by dropping in on a next iteration,

Since in error case the loop is broken, we have to drop a reference count
by ourselves. Do it for port_fwnode in error case during ->probe().

Fixes: b0bd407e94b0 ("hwmon: (ltc2992) Add support")
Cc: Alexandru Tachici <alexandru.tachici@analog.com>
Signed-off-by: Andy Shevchenko <andy.shevchenko@gmail.com>
---
 drivers/hwmon/ltc2992.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/hwmon/ltc2992.c b/drivers/hwmon/ltc2992.c
index 4382105bf142..2a4bed0ab226 100644
--- a/drivers/hwmon/ltc2992.c
+++ b/drivers/hwmon/ltc2992.c
@@ -900,11 +900,15 @@ static int ltc2992_parse_dt(struct ltc2992_state *st)
 
 	fwnode_for_each_available_child_node(fwnode, child) {
 		ret = fwnode_property_read_u32(child, "reg", &addr);
-		if (ret < 0)
+		if (ret < 0) {
+			fwnode_handle_put(child);
 			return ret;
+		}
 
-		if (addr > 1)
+		if (addr > 1) {
+			fwnode_handle_put(child);
 			return -EINVAL;
+		}
 
 		ret = fwnode_property_read_u32(child, "shunt-resistor-micro-ohms", &val);
 		if (!ret)
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v1 1/1] hwmon: (ltc2992) Put fwnode in error case during ->probe()
  2021-05-10 10:01 [PATCH v1 1/1] hwmon: (ltc2992) Put fwnode in error case during ->probe() Andy Shevchenko
@ 2021-05-10 15:02 ` Guenter Roeck
  0 siblings, 0 replies; 2+ messages in thread
From: Guenter Roeck @ 2021-05-10 15:02 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Alexandru Tachici, linux-hwmon, linux-kernel, Jean Delvare

On Mon, May 10, 2021 at 01:01:36PM +0300, Andy Shevchenko wrote:
> In each iteration fwnode_for_each_available_child_node() bumps a reference
> counting of a loop variable followed by dropping in on a next iteration,
> 
> Since in error case the loop is broken, we have to drop a reference count
> by ourselves. Do it for port_fwnode in error case during ->probe().
> 
> Fixes: b0bd407e94b0 ("hwmon: (ltc2992) Add support")
> Cc: Alexandru Tachici <alexandru.tachici@analog.com>
> Signed-off-by: Andy Shevchenko <andy.shevchenko@gmail.com>

Applied.

Thanks,
Guenter

> ---
>  drivers/hwmon/ltc2992.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/hwmon/ltc2992.c b/drivers/hwmon/ltc2992.c
> index 4382105bf142..2a4bed0ab226 100644
> --- a/drivers/hwmon/ltc2992.c
> +++ b/drivers/hwmon/ltc2992.c
> @@ -900,11 +900,15 @@ static int ltc2992_parse_dt(struct ltc2992_state *st)
>  
>  	fwnode_for_each_available_child_node(fwnode, child) {
>  		ret = fwnode_property_read_u32(child, "reg", &addr);
> -		if (ret < 0)
> +		if (ret < 0) {
> +			fwnode_handle_put(child);
>  			return ret;
> +		}
>  
> -		if (addr > 1)
> +		if (addr > 1) {
> +			fwnode_handle_put(child);
>  			return -EINVAL;
> +		}
>  
>  		ret = fwnode_property_read_u32(child, "shunt-resistor-micro-ohms", &val);
>  		if (!ret)

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-05-10 15:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-10 10:01 [PATCH v1 1/1] hwmon: (ltc2992) Put fwnode in error case during ->probe() Andy Shevchenko
2021-05-10 15:02 ` Guenter Roeck

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).