ASoC: Intel: sof_sdw: avoid oops in error handling
authorPierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Fri, 15 Jul 2022 14:41:41 +0000 (09:41 -0500)
committerMark Brown <broonie@kernel.org>
Fri, 15 Jul 2022 16:10:54 +0000 (17:10 +0100)
commit8116483407076b81af0efb14f6d69aefaecbf3d8
treea99369df9998e164457b05c450b860038120f5e5
parente1d1ffeda697dedf0859f963bc4180b5bb7bf150
ASoC: Intel: sof_sdw: avoid oops in error handling

While tinkering with ACPI work-arounds for the HP Omen 16 support, we
identified a corner case where the headset codec device properties are
not set in the codec .init when -EPROBE_DEFER is returned, but
released unconditionally in the .exit().

This leads to a kernel oops

[    4.186891] sof_sdw sof_sdw: snd_soc_register_card failed -517
[    4.186896] BUG: kernel NULL pointer dereference, address: 00000000000003f0
[    4.186914] Oops: 0000 [#1] PREEMPT SMP NOPTI
[    4.186926] RIP: 0010:dev_fwnode+0x5/0x20
[    4.186974]  device_remove_software_node+0x10/0x80
[    4.186982]  sof_sdw_rt711_exit+0x19/0x30 [snd_soc_sof_sdw]
[    4.186990]  mc_dailink_exit_loop+0x94/0xc0 [snd_soc_sof_sdw]
[    4.186996]  ? rt711_rtd_init+0x170/0x170 [snd_soc_sof_sdw]

A similar error case can occur if the addition of the device property
fails. We need to test if the property was successfully added before
removing it.

BugLink: https://github.com/thesofproject/linux/issues/3727
Fixes: 768ad6d80db2d ("ASoC: Intel: sof_sdw: handle errors on card registration")
Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Reviewed-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Reviewed-by: Bard Liao <yung-chuan.liao@linux.intel.com>
Link: https://lore.kernel.org/r/20220715144144.274770-2-pierre-louis.bossart@linux.intel.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/intel/boards/sof_sdw_rt711.c
sound/soc/intel/boards/sof_sdw_rt711_sdca.c