Skip to content

Commit e199bf5

Browse files
krzkvinodkoul
authored andcommitted
soundwire: stream: fix NULL pointer dereference for multi_link
If bus is marked as multi_link, but number of masters in the stream is not higher than bus->hw_sync_min_links (bus->multi_link && m_rt_count >= bus->hw_sync_min_links), bank switching should not happen. The first part of do_bank_switch() code properly takes these conditions into account, but second part (sdw_ml_sync_bank_switch()) relies purely on bus->multi_link property. This is not balanced and leads to NULL pointer dereference: Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000 ... Call trace: wait_for_completion_timeout+0x124/0x1f0 do_bank_switch+0x370/0x6f8 sdw_prepare_stream+0x2d0/0x438 qcom_snd_sdw_prepare+0xa0/0x118 sm8450_snd_prepare+0x128/0x148 snd_soc_link_prepare+0x5c/0xe8 __soc_pcm_prepare+0x28/0x1ec dpcm_be_dai_prepare+0x1e0/0x2c0 dpcm_fe_dai_prepare+0x108/0x28c snd_pcm_do_prepare+0x44/0x68 snd_pcm_action_single+0x54/0xc0 snd_pcm_action_nonatomic+0xe4/0xec snd_pcm_prepare+0xc4/0x114 snd_pcm_common_ioctl+0x1154/0x1cc0 snd_pcm_ioctl+0x54/0x74 Fixes: ce6e74d ("soundwire: Add support for multi link bank switch") Cc: stable@vger.kernel.org Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org> Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com> Link: https://lore.kernel.org/r/20231124180136.390621-1-krzysztof.kozlowski@linaro.org Signed-off-by: Vinod Koul <vkoul@kernel.org>
1 parent b85ea95 commit e199bf5

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

drivers/soundwire/stream.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -742,14 +742,15 @@ static int sdw_bank_switch(struct sdw_bus *bus, int m_rt_count)
742742
* sdw_ml_sync_bank_switch: Multilink register bank switch
743743
*
744744
* @bus: SDW bus instance
745+
* @multi_link: whether this is a multi-link stream with hardware-based sync
745746
*
746747
* Caller function should free the buffers on error
747748
*/
748-
static int sdw_ml_sync_bank_switch(struct sdw_bus *bus)
749+
static int sdw_ml_sync_bank_switch(struct sdw_bus *bus, bool multi_link)
749750
{
750751
unsigned long time_left;
751752

752-
if (!bus->multi_link)
753+
if (!multi_link)
753754
return 0;
754755

755756
/* Wait for completion of transfer */
@@ -847,7 +848,7 @@ static int do_bank_switch(struct sdw_stream_runtime *stream)
847848
bus->bank_switch_timeout = DEFAULT_BANK_SWITCH_TIMEOUT;
848849

849850
/* Check if bank switch was successful */
850-
ret = sdw_ml_sync_bank_switch(bus);
851+
ret = sdw_ml_sync_bank_switch(bus, multi_link);
851852
if (ret < 0) {
852853
dev_err(bus->dev,
853854
"multi link bank switch failed: %d\n", ret);

0 commit comments

Comments
 (0)