Skip to content

Commit

Permalink
ASoC: SOF: Intel: fix page fault at probe if i915 init fails
Browse files Browse the repository at this point in the history
The earlier commit to fix runtime PM in case i915 init fails,
introduces a possibility to hit a page fault.

snd_hdac_ext_bus_device_exit() is designed to be called from
dev.release(). Calling it outside device reference counting, is
not safe and may lead to calling the device_exit() function
twice. Additionally, as part of ext_bus_device_init(), the device
is also registered with snd_hdac_device_register(). Thus before
calling device_exit(), the device must be removed from device
hierarchy first.

Fix the issue by rolling back init actions by calling
hdac_device_unregister() and then releasing device with put_device().
This matches with existing code in hdac-ext module.

To complete the fix, add handling for the case where
hda_codec_load_module() returns -ENODEV, and clean up the hdac_ext
resources also in this case.

In future work, hdac-ext interface should be extended to allow clients
more flexibility to handle the life-cycle of individual devices, beyond
just the current snd_hdac_ext_bus_device_remove(), which removes all
devices.

BugLink: thesofproject#2646
Reported-by: Jaroslav Kysela <[email protected]>
Fixes: 6c63c95 ("ASoC: SOF: fix a runtime pm issue in SOF when HDMI codec doesn't work")
Signed-off-by: Kai Vehmanen <[email protected]>
Reviewed-by: Rander Wang <[email protected]>
Reviewed-by: Libin Yang <[email protected]>
Reviewed-by: Bard Liao <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Mark Brown <[email protected]>
  • Loading branch information
kv2019i authored and broonie committed Jan 13, 2021
1 parent ef4d764 commit 9c25af2
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions sound/soc/sof/intel/hda-codec.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ static int hda_codec_probe(struct snd_sof_dev *sdev, int address,
if (!hdev->bus->audio_component) {
dev_dbg(sdev->dev,
"iDisp hw present but no driver\n");
goto error;
ret = -ENOENT;
goto out;
}
hda_priv->need_display_power = true;
}
Expand All @@ -170,24 +171,23 @@ static int hda_codec_probe(struct snd_sof_dev *sdev, int address,
* other return codes without modification
*/
if (ret == 0)
goto error;
ret = -ENOENT;
}

return ret;

error:
snd_hdac_ext_bus_device_exit(hdev);
return -ENOENT;

out:
if (ret < 0) {
snd_hdac_device_unregister(hdev);
put_device(&hdev->dev);
}
#else
hdev = devm_kzalloc(sdev->dev, sizeof(*hdev), GFP_KERNEL);
if (!hdev)
return -ENOMEM;

ret = snd_hdac_ext_bus_device_init(&hbus->core, address, hdev, HDA_DEV_ASOC);
#endif

return ret;
#endif
}

/* Codec initialization */
Expand Down

0 comments on commit 9c25af2

Please sign in to comment.