All of lore.kernel.org
 help / color / mirror / Atom feed
* [alsa-devel] [PATCH] ASoC: max98373: Fix calls to free_gpio()
@ 2019-11-01 17:08 Yong Zhi
  2019-11-04 10:27 ` Kai Vehmanen
  2019-11-04 13:03 ` Daniel Baluta
  0 siblings, 2 replies; 5+ messages in thread
From: Yong Zhi @ 2019-11-01 17:08 UTC (permalink / raw)
  To: broonie, pierre-louis.bossart
  Cc: alsa-devel, sathyanarayana.nujella, ryans.lee, Yong Zhi

Don't Call free_gpio() when request_gpio() fails, call it
at error paths to avoid resource leak.

Signed-off-by: Yong Zhi <yong.zhi@intel.com>
---
 sound/soc/codecs/max98373.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/sound/soc/codecs/max98373.c b/sound/soc/codecs/max98373.c
index eb709d528259..83984b5244c5 100644
--- a/sound/soc/codecs/max98373.c
+++ b/sound/soc/codecs/max98373.c
@@ -964,7 +964,6 @@ static int max98373_i2c_probe(struct i2c_client *i2c,
 		if (ret) {
 			dev_err(&i2c->dev, "%s: Failed to request gpio %d\n",
 				__func__, max98373->reset_gpio);
-			gpio_free(max98373->reset_gpio);
 			return -EINVAL;
 		}
 		gpio_direction_output(max98373->reset_gpio, 0);
@@ -979,16 +978,23 @@ static int max98373_i2c_probe(struct i2c_client *i2c,
 	if (ret < 0) {
 		dev_err(&i2c->dev,
 			"Failed to read: 0x%02X\n", MAX98373_R21FF_REV_ID);
-		return ret;
+		goto err_gpio_free;
 	}
 	dev_info(&i2c->dev, "MAX98373 revisionID: 0x%02X\n", reg);
 
 	/* codec registeration */
 	ret = devm_snd_soc_register_component(&i2c->dev, &soc_codec_dev_max98373,
 		max98373_dai, ARRAY_SIZE(max98373_dai));
-	if (ret < 0)
+	if (ret < 0) {
 		dev_err(&i2c->dev, "Failed to register codec: %d\n", ret);
+		goto err_gpio_free;
+	}
+
+	return 0;
 
+err_gpio_free:
+	if (gpio_is_valid(max98373->reset_gpio))
+		gpio_free(max98373->reset_gpio);
 	return ret;
 }
 
-- 
2.7.4

_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

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

* Re: [alsa-devel] [PATCH] ASoC: max98373: Fix calls to free_gpio()
  2019-11-01 17:08 [alsa-devel] [PATCH] ASoC: max98373: Fix calls to free_gpio() Yong Zhi
@ 2019-11-04 10:27 ` Kai Vehmanen
  2019-11-04 13:03 ` Daniel Baluta
  1 sibling, 0 replies; 5+ messages in thread
From: Kai Vehmanen @ 2019-11-04 10:27 UTC (permalink / raw)
  To: Yong Zhi
  Cc: alsa-devel, broonie, pierre-louis.bossart, ryans.lee,
	sathyanarayana.nujella

Hi,

On Fri, 1 Nov 2019, Yong Zhi wrote:

> Don't Call free_gpio() when request_gpio() fails, call it
> at error paths to avoid resource leak.

patch looks good to me:

Reviewed-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>

PS This is good as a clear bugfix. For future, use of
   devm_gpiod_get_*() and friends is recommended.
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

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

* Re: [alsa-devel] [PATCH] ASoC: max98373: Fix calls to free_gpio()
  2019-11-01 17:08 [alsa-devel] [PATCH] ASoC: max98373: Fix calls to free_gpio() Yong Zhi
  2019-11-04 10:27 ` Kai Vehmanen
@ 2019-11-04 13:03 ` Daniel Baluta
  2019-11-04 13:17   ` Mark Brown
  1 sibling, 1 reply; 5+ messages in thread
From: Daniel Baluta @ 2019-11-04 13:03 UTC (permalink / raw)
  To: pierre-louis.bossart, yong.zhi, broonie
  Cc: alsa-devel, sathyanarayana.nujella, ryans.lee

Hi Yong,

On Fri, 2019-11-01 at 12:08 -0500, Yong Zhi wrote:
> Don't Call free_gpio() when request_gpio() fails, call it
> at error paths to avoid resource leak.
> 

Uosing devm_gpio_request will make the change cleaner.
What do you think?

thanks,
Daniel.
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

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

* Re: [alsa-devel] [PATCH] ASoC: max98373: Fix calls to free_gpio()
  2019-11-04 13:03 ` Daniel Baluta
@ 2019-11-04 13:17   ` Mark Brown
  2019-11-04 14:46     ` Zhi, Yong
  0 siblings, 1 reply; 5+ messages in thread
From: Mark Brown @ 2019-11-04 13:17 UTC (permalink / raw)
  To: Daniel Baluta
  Cc: sathyanarayana.nujella, alsa-devel, pierre-louis.bossart,
	ryans.lee, yong.zhi


[-- Attachment #1.1: Type: text/plain, Size: 326 bytes --]

On Mon, Nov 04, 2019 at 01:03:38PM +0000, Daniel Baluta wrote:
> On Fri, 2019-11-01 at 12:08 -0500, Yong Zhi wrote:
> > Don't Call free_gpio() when request_gpio() fails, call it
> > at error paths to avoid resource leak.

> Uosing devm_gpio_request will make the change cleaner.
> What do you think?

Yes, that's even better.

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

[-- Attachment #2: Type: text/plain, Size: 161 bytes --]

_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

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

* Re: [alsa-devel] [PATCH] ASoC: max98373: Fix calls to free_gpio()
  2019-11-04 13:17   ` Mark Brown
@ 2019-11-04 14:46     ` Zhi, Yong
  0 siblings, 0 replies; 5+ messages in thread
From: Zhi, Yong @ 2019-11-04 14:46 UTC (permalink / raw)
  To: Mark Brown, Daniel Baluta
  Cc: alsa-devel, pierre-louis.bossart, ryans.lee, Nujella, Sathyanarayana

Hi, Kai, Daniel and Mark, 

> -----Original Message-----
> From: Mark Brown <broonie@kernel.org>
> Sent: Monday, November 4, 2019 7:18 AM
> To: Daniel Baluta <daniel.baluta@nxp.com>
> Cc: pierre-louis.bossart@linux.intel.com; Zhi, Yong <yong.zhi@intel.com>;
> Nujella, Sathyanarayana <sathyanarayana.nujella@intel.com>;
> ryans.lee@maximintegrated.com; alsa-devel@alsa-project.org
> Subject: Re: [alsa-devel] [PATCH] ASoC: max98373: Fix calls to free_gpio()
> 
> On Mon, Nov 04, 2019 at 01:03:38PM +0000, Daniel Baluta wrote:
> > On Fri, 2019-11-01 at 12:08 -0500, Yong Zhi wrote:
> > > Don't Call free_gpio() when request_gpio() fails, call it at error
> > > paths to avoid resource leak.
> 
> > Uosing devm_gpio_request will make the change cleaner.
> > What do you think?
> 
> Yes, that's even better.

Acked, will use devm version which is more elegant, thanks for the code review. -Yong 

_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

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

end of thread, other threads:[~2019-11-04 14:48 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-01 17:08 [alsa-devel] [PATCH] ASoC: max98373: Fix calls to free_gpio() Yong Zhi
2019-11-04 10:27 ` Kai Vehmanen
2019-11-04 13:03 ` Daniel Baluta
2019-11-04 13:17   ` Mark Brown
2019-11-04 14:46     ` Zhi, Yong

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.