ASoC: Intel: sof_sdw_rt711: remove properties in card remove
authorPierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Fri, 17 Jul 2020 21:13:33 +0000 (16:13 -0500)
committerMark Brown <broonie@kernel.org>
Mon, 20 Jul 2020 15:08:20 +0000 (16:08 +0100)
The rt711 jack detection properties are set from the machine drivers
during the card probe, as done in other ASoC examples.

KASAN reports a use-after-free error when unbinding drivers due to a
confusing sequence between the ACPI core, the device core and the
SoundWire device cleanups.

Rather than fixing this sequence, follow the recommendation to have
the same caller add and remove properties, add an explicit
device_remove_properties() in the card .remove() callback.

In future patches the use of device_add/remove_properties will be
replaced by a direct handling of a swnode, but the sequence will
remain the same.

Signed-off-by: Bard Liao <yung-chuan.liao@linux.intel.com>
Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Reviewed-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
Link: https://lore.kernel.org/r/20200717211337.31956-3-pierre-louis.bossart@linux.intel.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/intel/boards/sof_sdw.c
sound/soc/intel/boards/sof_sdw_common.h
sound/soc/intel/boards/sof_sdw_rt711.c

index be8eccb504504905cf45d04d3a7445c72684aa62..9b6059905dbeeeb5875d3ad97806fad6b06d747b 100644 (file)
@@ -217,6 +217,7 @@ static struct sof_sdw_codec_info codec_info_list[] = {
                .direction = {true, true},
                .dai_name = "rt711-aif1",
                .init = sof_sdw_rt711_init,
+               .exit = sof_sdw_rt711_exit,
        },
        {
                .id = 0x1308,
index 426017626b16ed6ea9edcb22ac181aa3fdd030df..c64c5d801d26796b101642e4db1b87cb49ff1855 100644 (file)
@@ -91,6 +91,7 @@ int sof_sdw_rt711_init(const struct snd_soc_acpi_link_adr *link,
                       struct snd_soc_dai_link *dai_links,
                       struct sof_sdw_codec_info *info,
                       bool playback);
+int sof_sdw_rt711_exit(struct device *dev, struct snd_soc_dai_link *dai_link);
 
 /* RT700 support */
 int sof_sdw_rt700_init(const struct snd_soc_acpi_link_adr *link,
index c8f84e9a3e4e05bbe61cb22187a5ba495dd84115..606009fa390107662f4a0ed5a240bd6a6732be33 100644 (file)
@@ -133,6 +133,21 @@ static int rt711_rtd_init(struct snd_soc_pcm_runtime *rtd)
        return ret;
 }
 
+int sof_sdw_rt711_exit(struct device *dev, struct snd_soc_dai_link *dai_link)
+{
+       struct device *sdw_dev;
+
+       sdw_dev = bus_find_device_by_name(&sdw_bus_type, NULL,
+                                         dai_link->codecs[0].name);
+       if (!sdw_dev)
+               return -EINVAL;
+
+       device_remove_properties(sdw_dev);
+       put_device(sdw_dev);
+
+       return 0;
+}
+
 int sof_sdw_rt711_init(const struct snd_soc_acpi_link_adr *link,
                       struct snd_soc_dai_link *dai_links,
                       struct sof_sdw_codec_info *info,