Skip to contentSkip to conversation

ASoC: max98373: Fix calls to free_gpio()

PATCH In review Yong Zhi 4 participants 5 messages Nov 1, 2019 – Nov 4, 2019

Subsystems (2)
lore
Share & tools
lore

Yong Zhi

author
#0 lore raw

PATCH 1/1 ASoC: max98373: Fix calls to free_gpio()

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

---
 sound/soc/codecs/max98373.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
sound/soc/codecs/max98373.c +9 -3
index eb709d528259..83984b5244c5 100644
@@ -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;
 }
 
Signature · 6 lines
2.7.4

_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Reviewed-by on v1 1/1
#1 lore raw

Hi,

Quoted 2 lines · Yong Zhi

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

patch looks good to me:

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

author
#4 lore raw

Hi, Kai, Daniel and Mark,

Quoted 10 lines

-----Original Message-----
From: Mark Brown <[email protected]>
Sent: Monday, November 4, 2019 7:18 AM
To: Daniel Baluta <[email protected]>
Cc: [email protected]; Zhi, Yong <[email protected]>; Nujella, Sathyanarayana <[email protected]>; [email protected]; [email protected]
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:

Quoted 8 lines
Quoted 6 lines · Yong Zhi
Quoted 2 lines

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
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel