From: sashiko-bot@kernel.org
To: "Gopi Chandra Sekhar Reddy Kanala" <gopi.kanala@oss.qualcomm.com>
Cc: linux-sound@vger.kernel.org
Subject: Re: [PATCH 1/2] ASoC: SDCA: add jack ops hooks
Date: Sat, 05 Dec 2026 16:18:35 +0000 [thread overview]
Message-ID: <sashiko-outbox-251740@kernel.org> (raw)
In-Reply-To: <20261205-b4-sdca-wcd9378-jack-v1-1-60ec9bff39ea@oss.qualcomm.com>
Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [High] ASoC: SDCA: set_jack() hardware enable is not restored after
system resume
- [Medium] ASoC: SDCA: class_function_set_jack() enables jack HW even
when jack is NULL
- [Medium] ASoC: SDCA: race between set_jack() and
post_jack_irq_process() hooks
- [Low] ASoC: SDCA: core jack layer couples to sdca_class_drv and omits
lock docs
- [Low] ASoC: SDCA: inaccurate set_jack() doc claim on initial hardware
state read
--
commit 44baabaeaf479d2ea44b8b468dfe123bdbd091ca
Author: Gopi Chandra Sekhar Reddy Kanala <gopi.kanala@oss.qualcomm.com>
ASoC: SDCA: add jack ops hooks
This commit adds optional set_jack and post_jack_irq_process callbacks to
struct sdca_class_ops and wires a back-pointer from sdca_interrupt_info to
sdca_class_drv so sdca_jack_process() can invoke the post-IRQ hook.
> diff --git a/include/sound/sdca_class.h b/include/sound/sdca_class.h
> index 794a756472cd6..073f122633e24 100644
> --- a/include/sound/sdca_class.h
> +++ b/include/sound/sdca_class.h
> @@ -26,10 +26,23 @@ struct sdca_function_data;
> * DT/non-DisCo platforms. Called once per SDCA function with
> * @dev pointing at that function's device. Pure data source;
> * performs no bus I/O. Return 0 on success or a negative errno.
> + * @set_jack: called from the class function driver's ASoC .set_jack, just
> + * before the jack is registered with sdca_jack_set_jack(). Use
> + * to enable detection hardware that must not be active any
> + * earlier. Enabling here means the initial state reported by
> + * sdca_jack_set_jack() already reflects the hardware. May be
> + * NULL.
[Severity: Low]
Is this comment (and the commit message) accurate about the initial state
reported by sdca_jack_set_jack()?
sdca_jack_set_jack() calls sdca_jack_report(), which reads the cached
SDCA_CTL_GE_SELECTED_MODE register rather than volatile
SDCA_CTL_GE_DETECTED_MODE. During snd_soc_card_bind(), machine drivers call
snd_soc_component_set_jack() from dai_link->init or card->late_probe before
snd_soc_component_fixup_controls() invokes sdca_irq_populate() to request
detected_mode_handler(). Because sdca_jack_process() has not run yet,
sdca_jack_set_jack() only reports the cached default value rather than live
hardware state.
[ ... ]
> diff --git a/include/sound/sdca_interrupts.h b/include/sound/sdca_interrupts.h
> index 3b30146e21db5..fa53ccf27b798 100644
> --- a/include/sound/sdca_interrupts.h
> +++ b/include/sound/sdca_interrupts.h
> @@ -60,6 +63,9 @@ struct sdca_interrupt {
> * struct sdca_interrupt_info - contains top-level SDCA interrupt information
> * @irq_chip: regmap irq chip structure.
> * @irq_data: regmap irq chip data structure.
> + * @core: Optional pointer to the device-level SDCA class driver owning
> + * this interrupt information, letting Function-level handlers reach the
> + * device's ops. Left NULL by drivers that do not use sdca_class_drv.
> * @irqs: Array of data for each individual IRQ.
> * @irq_lock: Protects access to the list of sdca_interrupt structures.
> */
> @@ -67,6 +73,8 @@ struct sdca_interrupt_info {
> struct regmap_irq_chip irq_chip;
> struct regmap_irq_chip_data *irq_data;
>
> + struct sdca_class_drv *core;
> +
> struct sdca_interrupt irqs[SDCA_MAX_INTERRUPTS];
[Severity: Low]
Should struct sdca_interrupt_info carry a direct pointer to
struct sdca_class_drv? This couples the reusable core snd-soc-sdca library
(sdca_interrupts.h and sdca_jack.c) to the upper-layer class driver instead
of using a generic jack or interrupt callback or wrapping the IRQ handler
via sdca_irq_request().
Separately, sdca_jack_process() calls post_jack_irq_process() while holding
card->snd_card->controls_rwsem for writing, and runs it before updating
SELECTED_MODE via snd_soc_dapm_put_enum_double() and calling
sdca_jack_report(). The struct sdca_class_ops kernel-doc does not mention
the held controls_rwsem lock or the sleepable and runtime PM expectations
for these callbacks.
[ ... ]
> diff --git a/sound/soc/sdca/sdca_class_function.c b/sound/soc/sdca/sdca_class_function.c
> index 1f0b5954a948c..7f05336712639 100644
> --- a/sound/soc/sdca/sdca_class_function.c
> +++ b/sound/soc/sdca/sdca_class_function.c
> @@ -214,6 +214,14 @@ static int class_function_set_jack(struct snd_soc_component *component,
> {
> struct class_function_drv *drv = snd_soc_component_get_drvdata(component);
> struct sdca_class_drv *core = drv->core;
> + int ret;
> +
> + if (core->ops && core->ops->set_jack) {
> + ret = core->ops->set_jack(core->sdw, core->dev_regmap);
> + if (ret)
> + dev_warn(component->dev,
> + "failed to enable hardware jack detection: %d\n", ret);
> + }
>
> return sdca_jack_set_jack(core->irq_info, jack);
> }
[Severity: Medium]
Should core->ops->set_jack() be called when jack is NULL?
ASoC machine drivers call snd_soc_component_set_jack(component, NULL, NULL)
to detach the jack on card teardown or probe-deferral rollback, for example
in qcom_snd_headset_jack_cleanup(). Because set_jack() takes neither jack
nor an enable flag and is called unconditionally here, teardown re-enables
hardware jack detection with no attached jack and gives codec drivers no way
to disable it. Passing jack (or an enable boolean) to the callback would
let drivers distinguish attach from detach.
[Severity: High]
How is hardware jack detection restored after system suspend and resume?
Machine drivers invoke snd_soc_component_set_jack() once during
dai_link->init, not on system resume. During system resume,
class_function_runtime_resume() resets the function and replays init_table
(which no longer enables jack detection), while class_dev_regmap_volatile()
marks every register in core->dev_regmap except SDW_SCP_SDCA_INTMASK1..4 as
volatile so regcache_sync(drv->dev_regmap) does not restore vendor
jack-detection registers written by core->ops->set_jack(). Without
tracking whether a jack is attached and re-invoking set_jack() on resume
after class_function_init_device(), hardware jack detection stays disabled
after the first system suspend/resume cycle.
[ ... ]
> diff --git a/sound/soc/sdca/sdca_jack.c b/sound/soc/sdca/sdca_jack.c
> index 73f8067906a90..8c9ca3b51d272 100644
> --- a/sound/soc/sdca/sdca_jack.c
> +++ b/sound/soc/sdca/sdca_jack.c
> @@ -82,6 +84,14 @@ int sdca_jack_process(struct sdca_interrupt *interrupt)
>
> dev_dbg(dev, "%s: %#x\n", interrupt->name, val);
>
> + /* core is unset on devices that are not sdca_class_drv users */
> + if (core && core->ops && core->ops->post_jack_irq_process) {
> + ret = core->ops->post_jack_irq_process(core->sdw,
> + core->dev_regmap);
> + if (ret)
> + dev_warn(dev, "jack post-process failed: %d\n", ret);
> + }
> +
> ucontrol = kzalloc_obj(*ucontrol);
> if (!ucontrol)
> return -ENOMEM;
[Severity: Medium]
Can core->ops->post_jack_irq_process() race with core->ops->set_jack()?
During card teardown, snd_soc_card_cleanup_resources() runs
snd_soc_link_exit() before snd_soc_card_link_components_remove() frees the
jack IRQ via sdca_irq_cleanup():
CPU0 CPU1 (threaded IRQ)
snd_soc_card_cleanup_resources()
snd_soc_link_exit()
class_function_set_jack()
ops->set_jack(...)
detected_mode_handler()
sdca_jack_process()
guard(rwsem_write)(rwsem)
ops->post_jack_irq_process(...)
<-- concurrent regmap writes
snd_soc_card_link_components_remove()
sdca_irq_cleanup()
class_function_set_jack() holds neither controls_rwsem nor irq_lock, so
multi-register sequences and read-modify-write updates in set_jack() and
post_jack_irq_process() can interleave on core->dev_regmap and corrupt the
hardware jack-detection state. Serializing both hooks under a common lock
(or disabling the jack IRQ around set_jack()) would prevent the race.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261205-b4-sdca-wcd9378-jack-v1-0-60ec9bff39ea@oss.qualcomm.com?part=1
next prev parent reply other threads:[~2026-12-05 16:18 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-05 15:59 [PATCH 0/2] ASoC: SDCA: support hardware jack detection on WCD9378 Gopi Chandra Sekhar Reddy Kanala
2026-12-05 15:59 ` [PATCH 1/2] ASoC: SDCA: add jack ops hooks Gopi Chandra Sekhar Reddy Kanala
2026-12-05 16:18 ` sashiko-bot [this message]
2026-12-05 15:59 ` [PATCH 2/2] ASoC: codecs: wcd9378-sdca: enable MBHC jack-detect (GE 35) interrupt Gopi Chandra Sekhar Reddy Kanala
2026-12-05 16:24 ` sashiko-bot
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=sashiko-outbox-251740@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=gopi.kanala@oss.qualcomm.com \
--cc=linux-sound@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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