mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ryan Murray <ryan@aurorasilicon.org>
To: patches@opensource.cirrus.com, linux-sound@vger.kernel.org
Cc: david.rhodes@cirrus.com, rf@opensource.cirrus.com,
	lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz,
	tiwai@suse.com, james.schulman@cirrus.com, povik+lin@cutebit.org,
	asahi@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: [RFC PATCH 1/2] ASoC: cs42l42: handle jack interrupt I/O and resume errors
Date: Thu, 17 Sep 2026 17:23:37 +1000	[thread overview]
Message-ID: <c7b09816b41cc3246153de5023c3542e940cdb26.1789620334.git.ryan@aurorasilicon.org> (raw)
In-Reply-To: <cover.1789620318.git.ryan@aurorasilicon.org>

A failed status or mask read leaves part of the interrupt snapshot
uninitialized. The handler can then interpret that data as headset or
button events. It also attempts register access after a failed runtime
resume.

Check the runtime-PM acquisition and each snapshot read before processing
any events. Use the transparent autosuspend guard so the always-powered
I2C transport continues to work when runtime PM is disabled. Keep the
existing scoped mutex and PM cleanup on every return path.

An extracted-handler fault-injection test reproduces event processing on
failed reads before this change and checks all 24 snapshot read failures
after it, together with resume failure and disabled-runtime-PM cases.

Fixes: 2c394ca79604 ("ASoC: Add support for CS42L42 codec")
Assisted-by: LLM
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
---
 sound/soc/codecs/cs42l42.c | 23 +++++++++++++++++------
 1 file changed, 17 insertions(+), 6 deletions(-)

diff --git a/sound/soc/codecs/cs42l42.c b/sound/soc/codecs/cs42l42.c
index fadf68860..2d1b45ea1 100644
--- a/sound/soc/codecs/cs42l42.c
+++ b/sound/soc/codecs/cs42l42.c
@@ -1667,18 +1667,25 @@ irqreturn_t cs42l42_irq_thread(int irq, void *data)
 	unsigned int current_plug_status;
 	unsigned int current_button_status;
 	unsigned int i;
+	int ret;
 
-	guard(pm_runtime_active_auto)(cs42l42->dev);
+	PM_RUNTIME_ACQUIRE_AUTOSUSPEND(cs42l42->dev, pm);
+	if (PM_RUNTIME_ACQUIRE_ERR(&pm))
+		return IRQ_NONE;
 	guard(mutex)(&cs42l42->irq_lock);
 	if (cs42l42->suspended || !cs42l42->init_done)
 		return IRQ_NONE;
 
-	/* Read sticky registers to clear interurpt */
+	/* Read sticky registers to clear interrupt */
 	for (i = 0; i < ARRAY_SIZE(stickies); i++) {
-		regmap_read(cs42l42->regmap, irq_params_table[i].status_addr,
-				&(stickies[i]));
-		regmap_read(cs42l42->regmap, irq_params_table[i].mask_addr,
-				&(masks[i]));
+		ret = regmap_read(cs42l42->regmap, irq_params_table[i].status_addr,
+				  &stickies[i]);
+		if (ret)
+			goto out_error;
+		ret = regmap_read(cs42l42->regmap, irq_params_table[i].mask_addr,
+				  &masks[i]);
+		if (ret)
+			goto out_error;
 		stickies[i] = stickies[i] & (~masks[i]) &
 				irq_params_table[i].mask;
 	}
@@ -1772,6 +1779,10 @@ irqreturn_t cs42l42_irq_thread(int irq, void *data)
 	}
 
 	return IRQ_HANDLED;
+
+out_error:
+	dev_err_ratelimited(cs42l42->dev, "Failed to read jack interrupt state: %d\n", ret);
+	return IRQ_NONE;
 }
 EXPORT_SYMBOL_NS_GPL(cs42l42_irq_thread, "SND_SOC_CS42L42_CORE");
 

  reply	other threads:[~2026-09-17  7:23 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-17  7:23 [RFC PATCH 0/2] ASoC: CS42L83 Apple headset remote support Ryan Murray
2026-09-17  7:23 ` Ryan Murray [this message]
2026-09-17 20:20   ` [RFC PATCH 1/2] ASoC: cs42l42: handle jack interrupt I/O and resume errors Mark Brown
2026-09-17  7:23 ` [RFC PATCH 2/2] ASoC: cs42l42: support Apple headset remotes on CS42L83 Ryan Murray

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=c7b09816b41cc3246153de5023c3542e940cdb26.1789620334.git.ryan@aurorasilicon.org \
    --to=ryan@aurorasilicon.org \
    --cc=asahi@lists.linux.dev \
    --cc=broonie@kernel.org \
    --cc=david.rhodes@cirrus.com \
    --cc=james.schulman@cirrus.com \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=patches@opensource.cirrus.com \
    --cc=perex@perex.cz \
    --cc=povik+lin@cutebit.org \
    --cc=rf@opensource.cirrus.com \
    --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®