Skip to content

Commit 6b1c0bd

Browse files
andy-shevbroonie
authored andcommitted
ASoC: Intel: bytcht_es8316: Drop reference count of ACPI device after use
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: 3c22a73 ("ASoC: Intel: bytcht_es8316: fix HID handling") Signed-off-by: Andy Shevchenko <[email protected]> Acked-by: Pierre-Louis Bossart <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent d784fc8 commit 6b1c0bd

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

sound/soc/intel/boards/bytcht_es8316.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -497,21 +497,28 @@ static int snd_byt_cht_es8316_mc_probe(struct platform_device *pdev)
497497
if (adev) {
498498
snprintf(codec_name, sizeof(codec_name),
499499
"i2c-%s", acpi_dev_name(adev));
500-
put_device(&adev->dev);
501500
byt_cht_es8316_dais[dai_index].codecs->name = codec_name;
502501
} else {
503502
dev_err(dev, "Error cannot find '%s' dev\n", mach->id);
504503
return -ENXIO;
505504
}
506505

506+
codec_dev = acpi_get_first_physical_node(adev);
507+
acpi_dev_put(adev);
508+
if (!codec_dev)
509+
return -EPROBE_DEFER;
510+
priv->codec_dev = get_device(codec_dev);
511+
507512
/* override platform name, if required */
508513
byt_cht_es8316_card.dev = dev;
509514
platform_name = mach->mach_params.platform;
510515

511516
ret = snd_soc_fixup_dai_links_platform_name(&byt_cht_es8316_card,
512517
platform_name);
513-
if (ret)
518+
if (ret) {
519+
put_device(codec_dev);
514520
return ret;
521+
}
515522

516523
/* Check for BYTCR or other platform and setup quirks */
517524
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)
539546

540547
/* get the clock */
541548
priv->mclk = devm_clk_get(dev, "pmc_plt_clk_3");
542-
if (IS_ERR(priv->mclk))
549+
if (IS_ERR(priv->mclk)) {
550+
put_device(codec_dev);
543551
return dev_err_probe(dev, PTR_ERR(priv->mclk), "clk_get pmc_plt_clk_3 failed\n");
544-
545-
codec_dev = acpi_get_first_physical_node(adev);
546-
if (!codec_dev)
547-
return -EPROBE_DEFER;
548-
priv->codec_dev = get_device(codec_dev);
552+
}
549553

550554
if (quirk & BYT_CHT_ES8316_JD_INVERTED)
551555
props[cnt++] = PROPERTY_ENTRY_BOOL("everest,jack-detect-inverted");

0 commit comments

Comments
 (0)