LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] power: supply: ltc2941-battery-gauge: Release device_node in ltc294x_i2c_probe()
@ 2018-04-28 22:35 Alexey Khoroshilov
  2018-05-01 12:39 ` Sebastian Reichel
  0 siblings, 1 reply; 4+ messages in thread
From: Alexey Khoroshilov @ 2018-04-28 22:35 UTC (permalink / raw)
  To: Sebastian Reichel, Mike Looijmans
  Cc: Alexey Khoroshilov, linux-pm, linux-kernel, ldv-project,
	Julia Lawall, sil2review

There is of_node_get(client->dev.of_node) in ltc294x_i2c_probe(),
but these is no of_node_put() somethere in the driver.

The patch adds one on error and normal paths.

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
---
 drivers/power/supply/ltc2941-battery-gauge.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/drivers/power/supply/ltc2941-battery-gauge.c b/drivers/power/supply/ltc2941-battery-gauge.c
index 4f129bb4c972..7854a89b3332 100644
--- a/drivers/power/supply/ltc2941-battery-gauge.c
+++ b/drivers/power/supply/ltc2941-battery-gauge.c
@@ -481,7 +481,7 @@ static int ltc294x_i2c_probe(struct i2c_client *client,
 	if (ret < 0) {
 		dev_err(&client->dev,
 			"Could not find lltc,resistor-sense in devicetree\n");
-		return ret;
+		goto err_node_put;
 	}
 	info->r_sense = r_sense;
 
@@ -511,7 +511,7 @@ static int ltc294x_i2c_probe(struct i2c_client *client,
 		if (ret < 0) {
 			dev_err(&client->dev,
 				"Could not read status register\n");
-			return ret;
+			goto err_node_put;
 		}
 		if (status & LTC2941_REG_STATUS_CHIP_ID)
 			info->id = LTC2941_ID;
@@ -550,19 +550,25 @@ static int ltc294x_i2c_probe(struct i2c_client *client,
 	ret = ltc294x_reset(info, prescaler_exp);
 	if (ret < 0) {
 		dev_err(&client->dev, "Communication with chip failed\n");
-		return ret;
+		goto err_node_put;
 	}
 
 	info->supply = power_supply_register(&client->dev, &info->supply_desc,
 					     &psy_cfg);
 	if (IS_ERR(info->supply)) {
 		dev_err(&client->dev, "failed to register ltc2941\n");
-		return PTR_ERR(info->supply);
+		ret = PTR_ERR(info->supply);
+		goto err_node_put;
 	} else {
 		schedule_delayed_work(&info->work, LTC294X_WORK_DELAY * HZ);
 	}
 
+	of_node_put(np);
 	return 0;
+
+err_node_put:
+	of_node_put(np);
+	return ret;
 }
 
 static void ltc294x_i2c_shutdown(struct i2c_client *client)
-- 
2.7.4

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

* Re: [PATCH] power: supply: ltc2941-battery-gauge: Release device_node in ltc294x_i2c_probe()
  2018-04-28 22:35 [PATCH] power: supply: ltc2941-battery-gauge: Release device_node in ltc294x_i2c_probe() Alexey Khoroshilov
@ 2018-05-01 12:39 ` Sebastian Reichel
  2018-05-08 19:16   ` Alexey Khoroshilov
  0 siblings, 1 reply; 4+ messages in thread
From: Sebastian Reichel @ 2018-05-01 12:39 UTC (permalink / raw)
  To: Alexey Khoroshilov
  Cc: Mike Looijmans, linux-pm, linux-kernel, ldv-project,
	Julia Lawall, sil2review

[-- Attachment #1: Type: text/plain, Size: 2354 bytes --]

Hi,

On Sun, Apr 29, 2018 at 01:35:55AM +0300, Alexey Khoroshilov wrote:
> There is of_node_get(client->dev.of_node) in ltc294x_i2c_probe(),
> but these is no of_node_put() somethere in the driver.
> 
> The patch adds one on error and normal paths.
> 
> Found by Linux Driver Verification project (linuxtesting.org).
> 
> Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>

That is ugly. Let's replace of_property_read_u32(np, ...) with
device_property_read_u32(dev, ...) and get rid of np instead.

-- Sebastian

> ---
>  drivers/power/supply/ltc2941-battery-gauge.c | 14 ++++++++++----
>  1 file changed, 10 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/power/supply/ltc2941-battery-gauge.c b/drivers/power/supply/ltc2941-battery-gauge.c
> index 4f129bb4c972..7854a89b3332 100644
> --- a/drivers/power/supply/ltc2941-battery-gauge.c
> +++ b/drivers/power/supply/ltc2941-battery-gauge.c
> @@ -481,7 +481,7 @@ static int ltc294x_i2c_probe(struct i2c_client *client,
>  	if (ret < 0) {
>  		dev_err(&client->dev,
>  			"Could not find lltc,resistor-sense in devicetree\n");
> -		return ret;
> +		goto err_node_put;
>  	}
>  	info->r_sense = r_sense;
>  
> @@ -511,7 +511,7 @@ static int ltc294x_i2c_probe(struct i2c_client *client,
>  		if (ret < 0) {
>  			dev_err(&client->dev,
>  				"Could not read status register\n");
> -			return ret;
> +			goto err_node_put;
>  		}
>  		if (status & LTC2941_REG_STATUS_CHIP_ID)
>  			info->id = LTC2941_ID;
> @@ -550,19 +550,25 @@ static int ltc294x_i2c_probe(struct i2c_client *client,
>  	ret = ltc294x_reset(info, prescaler_exp);
>  	if (ret < 0) {
>  		dev_err(&client->dev, "Communication with chip failed\n");
> -		return ret;
> +		goto err_node_put;
>  	}
>  
>  	info->supply = power_supply_register(&client->dev, &info->supply_desc,
>  					     &psy_cfg);
>  	if (IS_ERR(info->supply)) {
>  		dev_err(&client->dev, "failed to register ltc2941\n");
> -		return PTR_ERR(info->supply);
> +		ret = PTR_ERR(info->supply);
> +		goto err_node_put;
>  	} else {
>  		schedule_delayed_work(&info->work, LTC294X_WORK_DELAY * HZ);
>  	}
>  
> +	of_node_put(np);
>  	return 0;
> +
> +err_node_put:
> +	of_node_put(np);
> +	return ret;
>  }
>  
>  static void ltc294x_i2c_shutdown(struct i2c_client *client)
> -- 
> 2.7.4
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH] power: supply: ltc2941-battery-gauge: Release device_node in ltc294x_i2c_probe()
  2018-05-01 12:39 ` Sebastian Reichel
@ 2018-05-08 19:16   ` Alexey Khoroshilov
  2018-07-06 17:04     ` Sebastian Reichel
  0 siblings, 1 reply; 4+ messages in thread
From: Alexey Khoroshilov @ 2018-05-08 19:16 UTC (permalink / raw)
  To: Sebastian Reichel
  Cc: Mike Looijmans, linux-pm, linux-kernel, ldv-project,
	Julia Lawall, sil2review


Hi,

On 01.05.2018 15:39, Sebastian Reichel wrote:
> Hi,
> 
> On Sun, Apr 29, 2018 at 01:35:55AM +0300, Alexey Khoroshilov wrote:
>> There is of_node_get(client->dev.of_node) in ltc294x_i2c_probe(),
>> but these is no of_node_put() somethere in the driver.
>>
>> The patch adds one on error and normal paths.
>>
>> Found by Linux Driver Verification project (linuxtesting.org).
>>
>> Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
> 
> That is ugly. Let's replace of_property_read_u32(np, ...) with
> device_property_read_u32(dev, ...) and get rid of np instead.
> 

Ok, I will prepare v2.

What is the right way to replace
info->supply_desc.name = np->name;
?

If lifetime of 'client->dev.of_node' = 'np' cannot be less than lifetime
of 'client->dev', should we use just
info->supply_desc.name = client->dev.of_node->name;
?

Thank you,
Alexey

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

* Re: [PATCH] power: supply: ltc2941-battery-gauge: Release device_node in ltc294x_i2c_probe()
  2018-05-08 19:16   ` Alexey Khoroshilov
@ 2018-07-06 17:04     ` Sebastian Reichel
  0 siblings, 0 replies; 4+ messages in thread
From: Sebastian Reichel @ 2018-07-06 17:04 UTC (permalink / raw)
  To: Alexey Khoroshilov
  Cc: Mike Looijmans, linux-pm, linux-kernel, ldv-project,
	Julia Lawall, sil2review

[-- Attachment #1: Type: text/plain, Size: 1078 bytes --]

Hi,

On Tue, May 08, 2018 at 10:16:31PM +0300, Alexey Khoroshilov wrote:
> On 01.05.2018 15:39, Sebastian Reichel wrote:
> > On Sun, Apr 29, 2018 at 01:35:55AM +0300, Alexey Khoroshilov wrote:
> >> There is of_node_get(client->dev.of_node) in ltc294x_i2c_probe(),
> >> but these is no of_node_put() somethere in the driver.
> >>
> >> The patch adds one on error and normal paths.
> >>
> >> Found by Linux Driver Verification project (linuxtesting.org).
> >>
> >> Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
> > 
> > That is ugly. Let's replace of_property_read_u32(np, ...) with
> > device_property_read_u32(dev, ...) and get rid of np instead.
> 
> Ok, I will prepare v2.
> 
> What is the right way to replace
> info->supply_desc.name = np->name;
> ?
> 
> If lifetime of 'client->dev.of_node' = 'np' cannot be less than lifetime
> of 'client->dev', should we use just
> info->supply_desc.name = client->dev.of_node->name;
> ?

It looks like I never responsed to this, sorry for the delay.
Your suggestion looks fine.

-- Sebastian

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

end of thread, other threads:[~2018-07-06 17:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-28 22:35 [PATCH] power: supply: ltc2941-battery-gauge: Release device_node in ltc294x_i2c_probe() Alexey Khoroshilov
2018-05-01 12:39 ` Sebastian Reichel
2018-05-08 19:16   ` Alexey Khoroshilov
2018-07-06 17:04     ` Sebastian Reichel

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).