mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ilia Snezhkov via B4 Relay <devnull+iasnezhkov.gmail.com@kernel.org>
To: broonie@kernel.org, lgirdwood@gmail.com
Cc: perex@perex.cz, tiwai@suse.com, matthias.bgg@gmail.com,
	 angelogioacchino.delregno@collabora.com,
	linux-sound@vger.kernel.org,  linux-mediatek@lists.infradead.org,
	linux-arm-kernel@lists.infradead.org,
	 linux-kernel@vger.kernel.org
Subject: [PATCH v2 1/2] ASoC: mediatek: mtk-btcvsd: check bt_reg_pkt_w for 0xdeadfeed in btcvsd_tx_clean_buffer()
Date: Thu, 26 Nov 2026 00:53:15 +0000	[thread overview]
Message-ID: <20261126005314.71606-2-iasnezhkov@gmail.com> (raw)
In-Reply-To: <20261126005314.71606-1-iasnezhkov@gmail.com>

From: Ilia Snezhkov <iasnezhkov@gmail.com>

mtk_btcvsd_read_from_bt(), mtk_btcvsd_write_to_bt(), and the loopback
path in mtk_btcvsd_snd_irq_handler() all read *bt->bt_reg_pkt_w and
bail out on the 0xdeadfeed sentinel returned when BT connsys SRAM is
unpowered or resetting.

btcvsd_tx_clean_buffer(), called from mtk_pcm_btcvsd_hw_free() and the
TX mute path, writes mute frames directly to previously cached
bt_sram_addr[] addresses without checking whether BT connsys SRAM is
still powered. If BT entered sleep or reset after those addresses were
recorded, writing to the cached SRAM addresses accesses unpowered BT
SRAM under tx_lock.

Return 0 early when num_valid_addr is zero so closing an unused stream
does not touch BT registers, and otherwise verify *bt->bt_reg_pkt_w !=
0xdeadfeed under tx_lock before writing mute frames.

Found and drafted with an AI coding assistant while bringing up MT6789.

Fixes: 4bd8597dc36c ("ASoC: mediatek: add btcvsd driver")
Signed-off-by: Ilia Snezhkov <iasnezhkov@gmail.com>
---
 sound/soc/mediatek/common/mtk-btcvsd.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/sound/soc/mediatek/common/mtk-btcvsd.c b/sound/soc/mediatek/common/mtk-btcvsd.c
index 19329dd..752856a 100644
--- a/sound/soc/mediatek/common/mtk-btcvsd.c
+++ b/sound/soc/mediatek/common/mtk-btcvsd.c
@@ -335,6 +335,15 @@ static int btcvsd_tx_clean_buffer(struct mtk_btcvsd_snd *bt)
 	dev_info(bt->dev, "%s(), band %d, num_valid_addr %u\n",
 		 __func__, band, num_valid_addr);
 
+	if (!num_valid_addr)
+		return 0;
+
+	if (*bt->bt_reg_pkt_w == 0xdeadfeed) {
+		dev_warn(bt->dev, "%s(), connsys_addr_tx == 0xdeadfeed\n",
+			 __func__);
+		return -EIO;
+	}
+
 	for (i = 0; i < num_valid_addr; i++) {
 		void *dst;
 
-- 
2.54.0 (Apple Git-157)




  reply	other threads:[~2026-11-26  0:53 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26  0:53 [PATCH v2 0/2] ASoC: mediatek: mtk-btcvsd: fix 0xdeadfeed check and bt_sram_addr bounds Ilia Snezhkov via B4 Relay
2026-11-26  0:53 ` Ilia Snezhkov via B4 Relay [this message]
2026-11-26  0:53 ` [PATCH v2 2/2] ASoC: mediatek: mtk-btcvsd: bound bt_sram_addr[] writes in mtk_btcvsd_write_to_bt() Ilia Snezhkov via B4 Relay

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261126005314.71606-2-iasnezhkov@gmail.com \
    --to=devnull+iasnezhkov.gmail.com@kernel.org \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=broonie@kernel.org \
    --cc=iasnezhkov@gmail.com \
    --cc=lgirdwood@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=matthias.bgg@gmail.com \
    --cc=perex@perex.cz \
    --cc=tiwai@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®