All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Svyatoslav Ryhel" <clamor95@gmail.com>
Cc: linux-sound@vger.kernel.org
Subject: Re: [PATCH v2 1/3] ASoC: tegra: Consolidate remaining separate codec machine drivers into tegra_asoc_machine
Date: Fri, 27 Nov 2026 17:02:10 +0000	[thread overview]
Message-ID: <sashiko-outbox-237958@kernel.org> (raw)
In-Reply-To: <20261127164436.292585-2-clamor95@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] ASoC: tegra: unintended mic jack setup in
  tegra_asoc_machine_init()
- [High] ASoC: tegra: NULL pointer dereference in
  tegra_asoc_machine_remove()
--

commit c80741097ea3e7b489563814d70191ee1199c6c6
Author: Svyatoslav Ryhel <clamor95@gmail.com>

ASoC: tegra: Consolidate remaining separate codec machine drivers into tegra_asoc_machine

This commit merges the standalone WM8903, WM8962, and WM8994 machine
drivers into tegra_asoc_machine.c and removes their separate source files.

> diff --git a/sound/soc/tegra/tegra_asoc_machine.c b/sound/soc/tegra/tegra_asoc_machine.c
> index c4e62e2b7fd07..0e0830d2733b9 100644
> --- a/sound/soc/tegra/tegra_asoc_machine.c
> +++ b/sound/soc/tegra/tegra_asoc_machine.c

[ ... ]

> @@ -190,7 +218,7 @@ int tegra_asoc_machine_init(struct snd_soc_pcm_runtime *rtd)
>  			dev_err(rtd->dev, "Headset GPIOs not added: %d\n", err);
>  	}
>  
> -	if (machine->gpiod_mic_det && machine->asoc->add_mic_jack) {
> +	if (machine->asoc->add_mic_jack) {
>  		err = snd_soc_card_jack_new_pins(rtd->card, "Mic Jack",
>  						 SND_JACK_MICROPHONE,
>  						 &tegra_machine_mic_jack,
> @@ -201,24 +229,45 @@ int tegra_asoc_machine_init(struct snd_soc_pcm_runtime *rtd)
>  			return err;
>  		}
>  
> -		tegra_machine_mic_jack_gpio.data = machine;
> -		tegra_machine_mic_jack_gpio.desc = machine->gpiod_mic_det;
> -
> -		if (of_property_read_bool(card->dev->of_node,
> -					  "nvidia,coupled-mic-hp-det")) {
> -			tegra_machine_mic_jack_gpio.desc = machine->gpiod_hp_det;
> -			tegra_machine_mic_jack_gpio.jack_status_check = coupled_mic_hp_check;
> +		if (machine->gpiod_mic_det) {
> +			tegra_machine_mic_jack_gpio.data = machine;
> +			tegra_machine_mic_jack_gpio.desc = machine->gpiod_mic_det;
> +
> +			if (of_property_read_bool(card->dev->of_node,
> +						  "nvidia,coupled-mic-hp-det")) {
> +				tegra_machine_mic_jack_gpio.desc = machine->gpiod_hp_det;
> +				tegra_machine_mic_jack_gpio.jack_status_check = coupled_mic_hp_check;
> +			}
> +
> +			err = snd_soc_jack_add_gpios(&tegra_machine_mic_jack, 1,
> +						     &tegra_machine_mic_jack_gpio);
> +			if (err)
> +				dev_err(rtd->dev, "Mic GPIOs not added: %d\n", err);
> +		} else {
> +			if (of_property_read_bool(card->dev->of_node, "nvidia,headset"))
> +				shrt = SND_JACK_MICROPHONE;
> +
> +			snd_soc_component_set_jack(component, machine->mic_jack,
> +						   shrt ? &shrt : NULL);
>  		}
> -
> -		err = snd_soc_jack_add_gpios(&tegra_machine_mic_jack, 1,
> -					     &tegra_machine_mic_jack_gpio);
> -		if (err)
> -			dev_err(rtd->dev, "Mic GPIOs not added: %d\n", err);
>  	}

[Severity: High]
Does dropping the machine->gpiod_mic_det check here break mic routing and
jack teardown on non-Wolfson boards that set add_mic_jack = true without
an nvidia,mic-det-gpios property?

tegra_max98090_data, tegra_max98088_data, tegra_rt5677_data, and
tegra_rt5631_data all set add_mic_jack = true.  When gpiod_mic_det is NULL
(for example on arch/arm/boot/dts/nvidia/tegra124-venice2.dts),
snd_soc_card_jack_new_pins() now unconditionally creates
tegra_machine_mic_jack and disables the "Mic Jack" and "Headset Mic" DAPM
pins.

On MAX98088, RT5677, and RT5631, the codec does not implement set_jack, so
those DAPM pins stay permanently disabled.  On MAX98090,
max98090_set_jack() stores max98090->jack and enables jack detection work,
but snd_soc_tegra_max98090 has no teardown callback to clear it on card
removal, leaving a dangling pointer in max98090->jack.

Also, passing &shrt (with SND_JACK_MICROPHONE == 2) as the data pointer to
snd_soc_component_set_jack() is specific to WM8903: wm8994_set_jack()
interprets *(int *)data as the 1-based MICBIAS index rather than a jack
report mask.

>  
>  	return 0;
>  }
> -EXPORT_SYMBOL_GPL(tegra_asoc_machine_init);
> +
> +static int tegra_asoc_machine_remove(struct snd_soc_card *card)
> +{
> +	struct snd_soc_dai_link *link = &card->dai_link[0];
> +	struct snd_soc_pcm_runtime *rtd = snd_soc_get_pcm_runtime(card, link);
> +	struct tegra_machine *machine = snd_soc_card_get_drvdata(rtd->card);
> +	struct snd_soc_dai *codec_dai = snd_soc_rtd_to_codec(rtd, 0);
> +	struct snd_soc_component *component = codec_dai->component;
> +
> +	if (!machine->gpiod_mic_det && machine->asoc->add_mic_jack)
> +		snd_soc_component_set_jack(component, NULL, NULL);
> +
> +	return 0;
> +}

[Severity: High]
Will tegra_asoc_machine_remove() always hit a NULL pointer dereference on
rtd?

During card teardown, snd_soc_card_cleanup_resources() removes and frees
every PCM runtime from card->rtd_list before calling card->remove():

sound/soc/soc-card.c:snd_soc_card_cleanup_resources() {
    ...
	for_each_card_rtds_safe(card, rtd, n)
		snd_soc_remove_pcm_runtime(card, rtd);
    ...
	/* remove the card */
	snd_soc_card_remove(card);
}

By the time tegra_asoc_machine_remove() runs, snd_soc_get_pcm_runtime()
returns NULL, so rtd->card and snd_soc_rtd_to_codec(rtd, 0) crash
immediately and the codec jack is never cleared.  Detaching the jack in a
snd_soc_dai_link.exit callback would run while rtd and the codec component
are still active.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261127164436.292585-1-clamor95@gmail.com?part=1

  reply	other threads:[~2026-11-27 17:02 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27 16:44 [PATCH v2 0/3] ASoC: tegra: Consolidate and update tegra_asoc_machine Svyatoslav Ryhel
2026-11-27 16:44 ` [PATCH v2 1/3] ASoC: tegra: Consolidate remaining separate codec machine drivers into tegra_asoc_machine Svyatoslav Ryhel
2026-11-27 17:02   ` sashiko-bot [this message]
2026-11-27 16:44 ` [PATCH v2 2/3] ASoC: tegra: Generalize forced DAPM pin enabling via tegra_asoc_data Svyatoslav Ryhel
2026-11-27 16:44 ` [PATCH v2 3/3] ASoC: tegra: Reorder the codec structures and sort the machine OF match table alphabetically Svyatoslav Ryhel

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-237958@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=clamor95@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.