From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796487887; b=1u3s55NDkI2NcbhpxS6f+N56h4TiaUsopPHdEIwsfdzdE2XAvJmOmo5CynD+dKi+B/S5 wv6/WR8v5iDSOjhVmRSZY9eQOc4fPF3dox3dgn+LBoOKEUk5IwDPSnfIS2MydbzCM7Ak4 afQnRVSlTSzyMqzwTb9MhokSRfAAip/hSFU/n+FR8AmXvwh1moQd5oUOBccf7f1Pb3yoy sk08k030pfn5qtC3YJNt1D5pyd6zzFO+vQnIGNYHQfk30nwDMbZCzdxdh+RZcsqscOjft Fonmfd3feGOZkDkSr02abBU7y3MKclBWV1B5A0a6P0DbRo7FjYgvyopfMJzT2nMmxMA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796487887; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=/3Rn+78gKovwrndRzuW6C6Luy0qEXKusNqZWNZH2JhU=; b=d0Mieck/o7yHZLyngUS/PyVUOYLIcF/6gpSDK+/DZMHuf7CuTSm/VthXfzQyTZm+E36O xhQnoKqWdEuANsm557iPK3wk0i33l8yG0bJxZkQbW51jmsVTGgrGQXBThE6G04sZX7hoD 4gWywiGk8x3VyLWg+hNonUIDrjAoGrT8BMh4f1pUO87DdJQD+q2OlYqRrXW2hBkG2XEsi yVgIlifTk3cd0sGVCgBGZp2buewf5ZSLHbpPuSElYgEdjCFKyV/tvwfN2rSpepv5w2fYf kE0jqszp5EXekDWOJzxWz1nN41K4Nw2SLI8+4jOgXwOSbQdkJmSs3EGzQKwvW8UXHoA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=KREC2Z1F; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C8995606A685 for ; Sat, 5 Dec 2026 16:24:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=KREC2Z1F Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4977E1F00936; Sat, 5 Dec 2026 16:24:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796487887; bh=/3Rn+78gKovwrndRzuW6C6Luy0qEXKusNqZWNZH2JhU=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=KREC2Z1F+wA85kNau7Rtdn6KHChlQEwFHSB0OSBXsuKLsJrcPXvDXEvumNgG5+5jB ZRaIV2NxzjCyTl0wQptIkkps4/Jphw089eF2GT+XRjQ7A5KurQDjRaLNtB3TWb18Fu OPqdul2vMjshvvaeJtkjMmIbA7r6bkqNBWwVgFKtLl2m0lwexLSZ8MQwAomlBVf2ss SEPfb0+Ja64+3X5mEIMOLBsI8SiAIdsASMTNriwlBwnaYRmMHzwe8ChW7hRvizzhtA /Nqg+VpxGCLzMcoN8HSXc5zaapOw1ZIZrki//s4nHGvctvTFaf9F7BR9Jkhca5oUkc H91b4+45uHNdQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH 2/2] ASoC: codecs: wcd9378-sdca: enable MBHC jack-detect (GE 35) interrupt Reply-To: sashiko-reviews@lists.linux.dev To: "Gopi Chandra Sekhar Reddy Kanala" Cc: linux-sound@vger.kernel.org In-Reply-To: <20261205-b4-sdca-wcd9378-jack-v1-2-60ec9bff39ea@oss.qualcomm.com> References: <20261205-b4-sdca-wcd9378-jack-v1-0-60ec9bff39ea@oss.qualcomm.com> <20261205-b4-sdca-wcd9378-jack-v1-2-60ec9bff39ea@oss.qualcomm.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 05 Dec 2026 16:24:46 +0000 X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 6 potential issues to consider: - [High] ASoC: wcd9378-sdca: MBHC registers lost across system suspend/resume - [Medium] ASoC: wcd9378-sdca: set_jack() re-arms MBHC on jack teardown (NULL) - [Medium] ASoC: wcd9378-sdca: unconditional SDCA_CASCADE clear can drop IRQs - [Medium] ASoC: wcd9378-sdca: wcd9378_sdca_set_jack() clobbers MBHC bitfields - [Medium] ASoC: sdca: unsynchronized jack_state access in sdca_jack_set_jack() - [Low] ASoC: wcd9378-sdca: dropping DP0_INT clear races slave->probed on rebind -- commit 2907479fe1dfbb0d350e7f5726d9243e85e8dab0 Author: Gopi Chandra Sekhar Reddy Kanala ASoC: codecs: wcd9378-sdca: enable MBHC jack-detect (GE 35) interrupt This commit enables WCD9378 mechanical MBHC jack detection by arming the MBHC comparator from a new .set_jack callback, toggling DET_TYP after each GE 35 interrupt, clearing the latched DP0_INT.SDCA_CASCADE bit in the SoundWire interrupt callback, and updating the GE 35 Safe_Mode range and MBHC_CTRL DEVICE_DET init-table entries. > diff --git a/sound/soc/codecs/wcd9378-sdca.c b/sound/soc/codecs/wcd9378-s= dca.c > index efbbeb3dc721a..8bfb2b10b5263 100644 > --- a/sound/soc/codecs/wcd9378-sdca.c > +++ b/sound/soc/codecs/wcd9378-sdca.c [ ... ] > @@ -826,16 +817,11 @@ static struct sdca_init_write wcd9378_sdca_init_tab= le[] =3D { > { .addr =3D 0x40c80008, .val =3D 0x01 }, /* SMP_JACK_CTRL FUNC_ACT (RES= ET_FUNCTION_NOW) */ > { .addr =3D 0x40c00008, .val =3D 0x02 }, /* SMP_JACK_CTRL CMT_GRP_MASK = */ > { .addr =3D 0x40c80000, .val =3D 0xff }, /* SMP_JACK_CTRL FUNC_STAT */ > - { .addr =3D 0x00000000, .val =3D 0x08 }, /* clear DP0 INT status SDCA_C= ASCADE */ > { .addr =3D 0x00000041, .val =3D 0x08 }, /* SCP_INT_STATUS_MASK_1 PORT_= 0_CASCADE_3 */ [Severity: Low] Can dropping this DP0_INT clear leave SDCA_CASCADE stuck during driver rebi= nd? On unbind, sdw_bus_remove() clears slave->probed without resetting slave->prop.paging_support. On rebind, wcd9378_sdca_probe() calls sdca_class_probe(), which queues boot_work before sdw_bus_probe() sets slave->probed =3D true: CPU0 (rebind) CPU1 (boot_work / IRQ) sdca_class_probe() queue_work(&drv->boot_work) class_function_boot() sdca_regmap_write_init() unmask SCP_INT_STATUS_MASK_1 sdw_handle_slave_alerts() if (slave->probed) <-- false, skips cb sdw_bus_probe() slave->probed =3D true If DP0_INT.SDCA_CASCADE is already latched when SCP_INT_STATUS_MASK_1 is unmasked, sdw_handle_slave_alerts() skips wcd9378_sdca_interrupt_callback(), hits MAX_RETRY, and leaves the peripheral in ALERT. Keeping the DP0_INT cl= ear in wcd9378_sdca_init_table[] avoids relying on the interrupt callback during probe-time initialization. [ ... ] > +int wcd9378_sdca_interrupt_callback(struct sdw_slave *slave, > + struct sdw_slave_intr_status *status) > +{ > + int ret; > + > + if (!status->sdca_cascade) > + return 0; > + > + ret =3D sdw_write_no_pm(slave, SDW_DP0_INT, SDW_DP0_SDCA_CASCADE); > + if (ret < 0) > + dev_err(&slave->dev, "SDCA_CASCADE clear failed:%d\n", ret); > + > + return 0; > +} [Severity: Medium] Can clearing SDW_DP0_SDCA_CASCADE unconditionally drop a pending SDCA interrupt? In sdw_handle_slave_alerts(), handle_nested_irq() runs before wcd9378_sdca_interrupt_callback(): IRQ thread Hardware regmap_irq_thread() ack SDW_SCP_SDCA_INT1 sdca_jack_process() wcd9378_sdca_post_jack_irq_process() toggle MECH_DET_TYP snd_soc_dapm_put_enum_double() opposite jack transition fires sets SDW_SCP_SDCA_INT1 bit 4 latches DP0_INT.SDCA_CASCADE wcd9378_sdca_interrupt_callback() write SDW_DP0_INT <-- clears cascade while SDCA_4 is pending Because wcd9378_sdca_post_jack_irq_process() flips DET_TYP before the DAPM = and PDE updates complete, a transition arriving in that window is stranded in SDW_SCP_SDCA_INT1 once DP0_INT is cleared, leaving DET_TYP inverted relative to the physical jack state. The same unconditional clear also drops interrupts arriving while slave->irq is disabled or during snd_soc_card_bin= d() before sdca_irq_populate() unmasks SDCA_4 in regmap_irq. Checking that no unmasked SDW_SCP_SDCA_INT1..4 bits remain set before clear= ing SDW_DP0_SDCA_CASCADE would avoid losing pending events. [ ... ] > +static int wcd9378_sdca_set_jack(struct sdw_slave *slave, struct regmap = *dev_regmap) > +{ > + struct device *dev =3D &slave->dev; > + int ret; > + > + ret =3D pm_runtime_resume_and_get(dev); > + if (ret < 0) { > + dev_err(dev, "failed to resume for jack detect enable: %d\n", ret); > + return ret; > + } > + > + ret =3D regmap_write(dev_regmap, WCD9378_MBHC_NEW_INT_MECH_DET_CURRENT_= ADDR, > + WCD9378_MBHC_HSDET_PULLUP_CTL_2P0_UA); > + if (ret) { > + dev_err(dev, "MBHC_NEW_INT_MECH_DET_CURRENT: %d\n", ret); > + goto out; > + } > + > + ret =3D regmap_write(dev_regmap, WCD9378_ANA_MBHC_MECH_ADDR, > + WCD9378_ANA_MBHC_MECH_ENABLE); > + if (ret) { > + dev_err(dev, "ANA_MBHC_MECH: %d\n", ret); > + goto out; > + } [Severity: Medium] Does wcd9378_sdca_set_jack() re-arm MBHC when a machine driver detaches the jack with jack =3D=3D NULL? class_function_set_jack() calls core->ops->set_jack() unconditionally witho= ut passing jack or an enable flag, and machine drivers such as x1e80100 call snd_soc_component_set_jack(component, NULL, NULL) in qcom_snd_headset_jack_cleanup() on teardown or probe rollback. Writing WCD9378_ANA_MBHC_MECH_ENABLE leaves the comparator, bias, pull-up current, = and RCO powered on after unbind and resets DET_TYP to insertion polarity, which can trigger spurious SDCA_4 interrupts during teardown or re-introduce the SDCA_4 interrupt storm on deferred re-probe. Passing whether a jack is bei= ng attached or detached and disabling MBHC on NULL would avoid this. [Severity: Medium] Does arming GE 35 interrupts here expose an unsynchronized data race on jack_state during sound-card teardown? On teardown in snd_soc_card_cleanup_resources(), dai_link->exit() calls qcom_snd_headset_jack_cleanup() -> sdca_jack_set_jack(info, NULL) before snd_soc_card_link_components_remove() runs sdca_irq_cleanup() -> free_irq(): CPU0 (card teardown) CPU1 (GE 35 IRQ thread) sdca_jack_set_jack(info, NULL) detected_mode_handler() lock(&info->irq_lock) sdca_jack_process() jack_state->mask |=3D ... lock(&card->controls_rwsem) jack_state->jack =3D NULL sdca_jack_report() snd_soc_jack_report(jack_state->jac= k, ..., jack_state->mas= k) <-- data race on jack_state sdca_jack_set_jack() updates jack_state->mask and jack_state->jack under info->irq_lock, while sdca_jack_process() holds only controls_rwsem (and cannot take info->irq_lock because sdca_irq_cleanup() holds it across free_irq()). This leaves a KCSAN-detectable data race and can report events on a detached jack, made more likely when wcd9378_sdca_set_jack() re-writes WCD9378_ANA_MBHC_MECH_ENABLE right before sdca_jack_set_jack() clears the pointer. > + ret =3D regmap_write(dev_regmap, WCD9378_MBHC_NEW_PLUG_DETECT_CTL_ADDR, > + WCD9378_MBHC_INSREM_DBNC_96MS); > + if (ret) { > + dev_err(dev, "MBHC_NEW_PLUG_DETECT_CTL: %d\n", ret); > + goto out; > + } > + > + ret =3D regmap_write(dev_regmap, WCD9378_ANA_MBHC_ELECT_ADDR, > + WCD9378_ANA_MBHC_ELECT_BIAS_EN); > + if (ret) { > + dev_err(dev, "ANA_MBHC_ELECT: %d\n", ret); > + goto out; > + } > + > + ret =3D regmap_write(dev_regmap, WCD9378_MBHC_NEW_CTL_1_ADDR, > + WCD9378_MBHC_NEW_CTL_1_RCO_EN); > + if (ret) > + dev_err(dev, "MBHC_NEW_CTL_1: %d\n", ret); [Severity: Medium] Do these full-byte regmap_write() calls clobber unrelated default bitfields= in the MBHC control registers? In the sibling WCD937x/WCD938x/WCD939x codecs sharing this analog block, MBHC_NEW_PLUG_DETECT_CTL defaults to 0xe9 (including MIC_CLAMP_CTL in bits [5:4]), ANA_MBHC_ELECT defaults to 0x08 (ELECT_DET_TYPE), and MBHC_NEW_CTL_1 defaults to 0x02 (BTN_DBNC_CTL), and wcd_mbhc_initialise() updates INSREM_DBNC, BIAS_EN, and RCO_EN with masked field writes. Writing 0x06, 0x01, and 0x80 directly zeroes those defaults, disabling automatic mic clamping and clearing the other fields; using regmap_update_bits() would preserve them. > +out: > + pm_runtime_mark_last_busy(dev); > + pm_runtime_put_autosuspend(dev); > + > + return ret; > +} [Severity: High] Are these five MBHC registers lost across system suspend and resume? wcd9378_sdca_set_jack() programs them only once during sound-card bind via dev_regmap, where class_dev_regmap_volatile() marks every register outside SDW_SCP_SDCA_INTMASK1..4 volatile so regcache_sync() never restores them. = On system resume, class_function_runtime_resume() resets the function and repl= ays wcd9378_sdca_init_table[] (which intentionally omits MBHC arming), and neit= her wcd9378_sdca_system_resume() nor class_function_runtime_resume() re-arms MB= HC, permanently disabling jack insertion and removal detection after a suspend/resume cycle. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261205-b4-sdca-wc= d9378-jack-v1-0-60ec9bff39ea@oss.qualcomm.com?part=3D2