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; }