public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: patches@lists.linux.dev, stable@vger.kernel.org
Cc: Shengjiu Wang <shengjiu.wang@nxp.com>,
	Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>,
	Mark Brown <broonie@kernel.org>, Sasha Levin <sashal@kernel.org>,
	linux-sound@vger.kernel.org
Subject: [PATCH AUTOSEL 6.18-6.12] ASoC: simple-card-utils: Check device node before overwrite direction
Date: Tue, 20 Jan 2026 14:34:51 -0500	[thread overview]
Message-ID: <20260120193456.865383-8-sashal@kernel.org> (raw)
In-Reply-To: <20260120193456.865383-1-sashal@kernel.org>

From: Shengjiu Wang <shengjiu.wang@nxp.com>

[ Upstream commit 22a507d7680f2c3499c133f6384349f62f916176 ]

Even the device node don't exist, the graph_util_parse_link_direction()
will overwrite the playback_only and capture_only to be zero. Which
cause the playback_only and capture_only are not correct, so check device
node exist or not before update the value.

Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com>
Acked-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Link: https://patch.msgid.link/20251229090432.3964848-1-shengjiu.wang@nxp.com
Signed-off-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---

LLM Generated explanations, may be completely bogus:

The commit seems to be describing a new patch to be analyzed. Based on
my full analysis, let me now synthesize my evaluation:

## ANALYSIS SUMMARY

### 1. COMMIT MESSAGE ANALYSIS

The commit message describes a bug where:
- When a device node doesn't exist (is NULL), the
  `graph_util_parse_link_direction()` function still overwrites
  `playback_only` and `capture_only` to zero (false)
- This causes incorrect behavior when these flags should remain as they
  were set by previous calls

The commit has:
- **Acked-by:** from the subsystem maintainer (Kuninori Morimoto)
- **Signed-off-by:** from the maintainer (Mark Brown)

### 2. CODE CHANGE ANALYSIS

**The Bug:**
Looking at the function:
```c
void graph_util_parse_link_direction(struct device_node *np,
                    bool *playback_only, bool *capture_only)
{
    bool is_playback_only = of_property_read_bool(np, "playback-only");
    bool is_capture_only  = of_property_read_bool(np, "capture-only");

    if (playback_only)
        *playback_only = is_playback_only;
    if (capture_only)
        *capture_only = is_capture_only;
}
```

When `np` is NULL:
1. `of_property_read_bool(NULL, ...)` returns `false` (since NULL node
   has no properties)
2. The function unconditionally overwrites `*playback_only = false` and
   `*capture_only = false`

**Call Pattern (from simple-card.c and audio-graph-card.c):**
```c
graph_util_parse_link_direction(top,    &playback_only, &capture_only);
graph_util_parse_link_direction(node,   &playback_only, &capture_only);
graph_util_parse_link_direction(cpu,    &playback_only, &capture_only);
graph_util_parse_link_direction(codec,  &playback_only, &capture_only);
```

The intent is hierarchical: if `top` sets `playback_only = true`, it
should remain true unless a lower-level node explicitly overrides it.
But if `cpu` or `codec` is NULL, the current code wrongly resets
`playback_only` to false.

**The Fix:**
```c
- if (playback_only)
+   if (np && playback_only)
        *playback_only = is_playback_only;
- if (capture_only)
+   if (np && capture_only)
        *capture_only = is_capture_only;
```

Adding `np &&` check prevents the function from overwriting the values
when `np` is NULL.

### 3. CLASSIFICATION

- **Bug fix:** Yes, clearly fixes a logic error
- **Security:** No security implications
- **Feature addition:** No

### 4. SCOPE AND RISK ASSESSMENT

- **Lines changed:** 2 (very minimal)
- **Files touched:** 1
- **Complexity:** Very low - adding a simple NULL check
- **Risk:** Very low - defensive programming that only affects behavior
  when np is NULL, which is already an edge case

### 5. USER IMPACT

- **Who is affected:** Users of ASoC simple-card and audio-graph-card
  drivers
- **Severity:** Audio routing could be incorrect (playback-only or
  capture-only configuration not being honored)
- **Visibility:** Users with device trees that set `playback-only` or
  `capture-only` on higher-level nodes where some lower-level nodes
  don't exist

### 6. STABILITY INDICATORS

- **Acked-by:** Kuninori Morimoto (maintainer of the code)
- **Signed-off-by:** Mark Brown (ASoC subsystem maintainer)

### 7. DEPENDENCY CHECK

- The function exists in stable trees starting from v6.10 (introduced in
  commit d29351e8c20d61)
- The fix applies cleanly and has no dependencies on other commits

### 8. FINAL ASSESSMENT

This is a clear, minimal, and well-reviewed bug fix that:
1. Fixes a real bug that causes incorrect audio configuration
2. Is small and surgical (2-line change with simple NULL check)
3. Has low regression risk (only affects edge case of NULL np)
4. Has been reviewed and acked by the appropriate maintainers
5. Would apply cleanly to stable trees (v6.10+) where this function
   exists

The fix is small, surgical, and meets all stable kernel criteria.

**YES**

 sound/soc/generic/simple-card-utils.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sound/soc/generic/simple-card-utils.c b/sound/soc/generic/simple-card-utils.c
index 355f7ec8943c2..bdc02e85b089f 100644
--- a/sound/soc/generic/simple-card-utils.c
+++ b/sound/soc/generic/simple-card-utils.c
@@ -1179,9 +1179,9 @@ void graph_util_parse_link_direction(struct device_node *np,
 	bool is_playback_only = of_property_read_bool(np, "playback-only");
 	bool is_capture_only  = of_property_read_bool(np, "capture-only");
 
-	if (playback_only)
+	if (np && playback_only)
 		*playback_only = is_playback_only;
-	if (capture_only)
+	if (np && capture_only)
 		*capture_only = is_capture_only;
 }
 EXPORT_SYMBOL_GPL(graph_util_parse_link_direction);
-- 
2.51.0


  parent reply	other threads:[~2026-01-20 19:35 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-20 19:34 [PATCH AUTOSEL 6.18] ALSA: usb-audio: Prevent excessive number of frames Sasha Levin
2026-01-20 19:34 ` [PATCH AUTOSEL 6.18-6.6] ASoC: amd: yc: Fix microphone on ASUS M6500RE Sasha Levin
2026-01-20 19:34 ` [PATCH AUTOSEL 6.18-5.10] ASoC: tlv320adcx140: Propagate error codes during probe Sasha Levin
2026-01-20 19:34 ` [PATCH AUTOSEL 6.18-6.1] nvme-fc: release admin tagset if init fails Sasha Levin
2026-01-20 19:34 ` [PATCH AUTOSEL 6.18] dmaengine: mmp_pdma: Fix race condition in mmp_pdma_residue() Sasha Levin
2026-01-20 19:34 ` [PATCH AUTOSEL 6.18-5.10] ASoC: davinci-evm: Fix reference leak in davinci_evm_probe Sasha Levin
2026-01-20 19:34 ` [PATCH AUTOSEL 6.18-6.6] nvmet-tcp: fixup hang in nvmet_tcp_listen_data_ready() Sasha Levin
2026-01-20 19:34 ` Sasha Levin [this message]
2026-01-20 19:34 ` [PATCH AUTOSEL 6.18] ASoC: Intel: sof_sdw: Add new quirks for PTL on Dell with CS42L43 Sasha Levin
2026-01-20 19:34 ` [PATCH AUTOSEL 6.18] ALSA: hda/tas2781: Add newly-released HP laptop Sasha Levin

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=20260120193456.865383-8-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=broonie@kernel.org \
    --cc=kuninori.morimoto.gx@renesas.com \
    --cc=linux-sound@vger.kernel.org \
    --cc=patches@lists.linux.dev \
    --cc=shengjiu.wang@nxp.com \
    --cc=stable@vger.kernel.org \
    /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