ASoC: Intel: bytcht_es8316: Drop reference count of ACPI device after use
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Thu, 12 Jan 2023 11:28:48 +0000 (13:28 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 9 Feb 2023 10:26:32 +0000 (11:26 +0100)
[ Upstream commit 6b1c0bd6fdefbf3c3d75680c2708f5423ef72e46 ]

Theoretically the device might gone if its reference count drops to 0.
This might be the case when we try to find the first physical node of
the ACPI device. We need to keep reference to it until we get a result
of the above mentioned call. Refactor the code to drop the reference
count at the correct place.

While at it, move to acpi_dev_put() as symmetrical call to the
acpi_dev_get_first_match_dev().

Fixes: 3c22a73fb873 ("ASoC: Intel: bytcht_es8316: fix HID handling")
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Acked-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Link: https://lore.kernel.org/r/20230112112852.67714-2-andriy.shevchenko@linux.intel.com
Signed-off-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
sound/soc/intel/boards/bytcht_es8316.c

index 95058398b1be5e13cb748b9d67d363b80760ddd8..b5c97d35864a6157fe1b19d94db9055619584713 100644 (file)
@@ -497,21 +497,28 @@ static int snd_byt_cht_es8316_mc_probe(struct platform_device *pdev)
        if (adev) {
                snprintf(codec_name, sizeof(codec_name),
                         "i2c-%s", acpi_dev_name(adev));
-               put_device(&adev->dev);
                byt_cht_es8316_dais[dai_index].codecs->name = codec_name;
        } else {
                dev_err(dev, "Error cannot find '%s' dev\n", mach->id);
                return -ENXIO;
        }
 
+       codec_dev = acpi_get_first_physical_node(adev);
+       acpi_dev_put(adev);
+       if (!codec_dev)
+               return -EPROBE_DEFER;
+       priv->codec_dev = get_device(codec_dev);
+
        /* override platform name, if required */
        byt_cht_es8316_card.dev = dev;
        platform_name = mach->mach_params.platform;
 
        ret = snd_soc_fixup_dai_links_platform_name(&byt_cht_es8316_card,
                                                    platform_name);
-       if (ret)
+       if (ret) {
+               put_device(codec_dev);
                return ret;
+       }
 
        /* Check for BYTCR or other platform and setup quirks */
        dmi_id = dmi_first_match(byt_cht_es8316_quirk_table);
@@ -539,13 +546,10 @@ static int snd_byt_cht_es8316_mc_probe(struct platform_device *pdev)
 
        /* get the clock */
        priv->mclk = devm_clk_get(dev, "pmc_plt_clk_3");
-       if (IS_ERR(priv->mclk))
+       if (IS_ERR(priv->mclk)) {
+               put_device(codec_dev);
                return dev_err_probe(dev, PTR_ERR(priv->mclk), "clk_get pmc_plt_clk_3 failed\n");
-
-       codec_dev = acpi_get_first_physical_node(adev);
-       if (!codec_dev)
-               return -EPROBE_DEFER;
-       priv->codec_dev = get_device(codec_dev);
+       }
 
        if (quirk & BYT_CHT_ES8316_JD_INVERTED)
                props[cnt++] = PROPERTY_ENTRY_BOOL("everest,jack-detect-inverted");