Re: [PATCH] ASoC: Intel: bytcht_es8316: Add missed put_device()

From: Hans de Goede
Date: Tue Jul 14 2020 - 15:29:44 EST


Hi,

On 7/14/20 5:32 PM, Pierre-Louis Bossart wrote:


On 7/14/20 8:33 AM, Hans de Goede wrote:
Hi,

On 7/14/20 10:09 AM, Jing Xiangfeng wrote:
snd_byt_cht_es8316_mc_probe() misses to call put_device() in an error
path. Add the missed function call to fix it.

Fixes: ba49cf6f8e4a ("ASoC: Intel: bytcht_es8316: Add quirk for inverted jack detect")
Signed-off-by: Jing Xiangfeng <jingxiangfeng@xxxxxxxxxx>

Patch looks good to me:

Reviewed-by: Hans de Goede <hdegoede@xxxxxxxxxx>

Actually the existing code looks quite odd to me:

if (cnt) {
ÂÂÂÂret = device_add_properties(codec_dev, props);
ÂÂÂÂif (ret)
ÂÂÂÂÂÂÂ return ret;
}

devm_acpi_dev_add_driver_gpios(codec_dev, byt_cht_es8316_gpios);
priv->speaker_en_gpio =
ÂÂÂÂgpiod_get_index(codec_dev, "speaker-enable", 0,
ÂÂÂÂÂÂÂÂÂÂÂ /* see comment in byt_cht_es8316_resume */
ÂÂÂÂÂÂÂÂÂÂÂ GPIOD_OUT_LOW | GPIOD_FLAGS_BIT_NONEXCLUSIVE);
put_device(codec_dev);

if the first branch is not taken the put_device() will not be balanced.

The get_device() does not come from the device_add_properties, it comes
from the earlier:

codec_dev = bus_find_device_by_name(&i2c_bus_type, NULL, codec_name);

call.

Regards,

Hans




Shouldn't this be:

if (cnt) {
ÂÂÂÂret = device_add_properties(codec_dev, props);
ÂÂÂÂput_device(codec_dev);
ÂÂÂÂif (ret)
ÂÂÂÂÂÂÂ return ret;
}

devm_acpi_dev_add_driver_gpios(codec_dev, byt_cht_es8316_gpios);
priv->speaker_en_gpio =
ÂÂÂÂgpiod_get_index(codec_dev, "speaker-enable", 0,
ÂÂÂÂÂÂÂÂÂÂÂ /* see comment in byt_cht_es8316_resume */
ÂÂÂÂÂÂÂÂÂÂÂ GPIOD_OUT_LOW | GPIOD_FLAGS_BIT_NONEXCLUSIVE);
/* removed put_device(codec_dev); */


Regards,

Hans


---
 sound/soc/intel/boards/bytcht_es8316.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/sound/soc/intel/boards/bytcht_es8316.c b/sound/soc/intel/boards/bytcht_es8316.c
index 9e5fc9430628..ecbc58e8a37f 100644
--- a/sound/soc/intel/boards/bytcht_es8316.c
+++ b/sound/soc/intel/boards/bytcht_es8316.c
@@ -543,8 +543,10 @@ static int snd_byt_cht_es8316_mc_probe(struct platform_device *pdev)
ÂÂÂÂÂ if (cnt) {
ÂÂÂÂÂÂÂÂÂ ret = device_add_properties(codec_dev, props);
-ÂÂÂÂÂÂÂ if (ret)
+ÂÂÂÂÂÂÂ if (ret) {
+ÂÂÂÂÂÂÂÂÂÂÂ put_device(codec_dev);
ÂÂÂÂÂÂÂÂÂÂÂÂÂ return ret;
+ÂÂÂÂÂÂÂ }
ÂÂÂÂÂ }
ÂÂÂÂÂ devm_acpi_dev_add_driver_gpios(codec_dev, byt_cht_es8316_gpios);