All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: patches@lists.linux.dev, stable@vger.kernel.org
Cc: Takashi Iwai <tiwai@suse.de>, Sasha Levin <sashal@kernel.org>,
	perex@perex.cz
Subject: [PATCH AUTOSEL 6.6 03/18] ALSA: sb: Don't allow changing the DMA mode during operations
Date: Tue, 24 Jun 2025 00:11:59 -0400	[thread overview]
Message-ID: <20250624041214.84135-3-sashal@kernel.org> (raw)
In-Reply-To: <20250624041214.84135-1-sashal@kernel.org>

From: Takashi Iwai <tiwai@suse.de>

[ Upstream commit ed29e073ba93f2d52832804cabdd831d5d357d33 ]

When a PCM stream is already running, one shouldn't change the DMA
mode via kcontrol, which may screw up the hardware.  Return -EBUSY
instead.

Link: https://bugzilla.kernel.org/show_bug.cgi?id=218185
Link: https://patch.msgid.link/20250610064322.26787-1-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---

**YES**

This commit should be backported to stable kernel trees. Here's my
extensive analysis:

## Key Reasons for Backporting:

1. **Critical Bug Fix for Race Condition**: The commit fixes a race
   condition where changing DMA mode via kcontrol while PCM streams are
   running can corrupt hardware state. Looking at the code:
   - The `chip->mode` field tracks active playback/capture operations
     using `SB_MODE_PLAYBACK` and `SB_MODE_CAPTURE` flags
   - The DMA mode control (`force_mode16`) affects how DMA transfers are
     configured
   - Changing this while streams are active can cause hardware
     inconsistencies

2. **Clear User-Visible Bug**: The commit references Bugzilla #218185,
   indicating this is a real user-reported issue that affects system
   stability and audio functionality.

3. **Minimal and Contained Fix**: The change is extremely small and
   focused:
  ```c
  +       if (chip->mode & (SB_MODE_PLAYBACK | SB_MODE_CAPTURE))
  +               return -EBUSY;
  ```
  It simply adds a check to prevent mode changes during active
  operations, returning -EBUSY to userspace.

4. **No Architectural Changes**: This is a straightforward defensive
   check that doesn't alter any core functionality or introduce new
   features. It only prevents an invalid operation.

5. **Low Risk of Regression**: The fix:
   - Only affects the SB16 sound driver
   - Only changes behavior when someone tries to modify DMA mode during
     active streaming
   - Returns a standard error code (-EBUSY) that applications should
     already handle
   - Doesn't affect normal audio operations

6. **Follows Stable Kernel Rules**: This perfectly matches stable kernel
   criteria:
   - Fixes a real bug that affects users
   - Obviously correct with no subtleties
   - Small change (2 lines of actual code)
   - Already tested in mainline
   - No new features added

## Technical Analysis:

From examining the code flow:
- During `snd_sb16_playback_open()` and `snd_sb16_capture_open()`, the
  driver sets `chip->mode` flags
- These flags remain set until `snd_sb16_playback_close()` and
  `snd_sb16_capture_close()` clear them
- The `force_mode16` setting affects DMA channel selection throughout
  the driver
- Without this fix, userspace can change `force_mode16` while DMA
  operations are active, potentially causing:
  - DMA channel mismatches
  - Audio corruption
  - System instability

This is similar to the first example commit that was backported, which
also prevented operations during inappropriate states (DMA
synchronization during PAUSE state).

 sound/isa/sb/sb16_main.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/sound/isa/sb/sb16_main.c b/sound/isa/sb/sb16_main.c
index a9b87e159b2d1..5efbd0a41312b 100644
--- a/sound/isa/sb/sb16_main.c
+++ b/sound/isa/sb/sb16_main.c
@@ -703,6 +703,9 @@ static int snd_sb16_dma_control_put(struct snd_kcontrol *kcontrol, struct snd_ct
 	unsigned char nval, oval;
 	int change;
 	
+	if (chip->mode & (SB_MODE_PLAYBACK | SB_MODE_CAPTURE))
+		return -EBUSY;
+
 	nval = ucontrol->value.enumerated.item[0];
 	if (nval > 2)
 		return -EINVAL;
-- 
2.39.5


  parent reply	other threads:[~2025-06-24  4:12 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-24  4:11 [PATCH AUTOSEL 6.6 01/18] drm/msm: Fix a fence leak in submit error path Sasha Levin
2025-06-24  4:11 ` [PATCH AUTOSEL 6.6 02/18] drm/msm: Fix another leak in the " Sasha Levin
2025-06-24  4:11 ` Sasha Levin [this message]
2025-06-24  4:12 ` [PATCH AUTOSEL 6.6 04/18] ALSA: sb: Force to disable DMAs once when DMA mode is changed Sasha Levin
2025-06-24  4:12 ` [PATCH AUTOSEL 6.6 05/18] ata: libata-acpi: Do not assume 40 wire cable if no devices are enabled Sasha Levin
2025-06-24  4:12 ` [PATCH AUTOSEL 6.6 06/18] ata: pata_cs5536: fix build on 32-bit UML Sasha Levin
2025-06-24  4:12 ` [PATCH AUTOSEL 6.6 07/18] ASoC: amd: yc: Add quirk for MSI Bravo 17 D7VF internal mic Sasha Levin
2025-06-24  4:12 ` [PATCH AUTOSEL 6.6 08/18] platform/x86/amd/pmc: Add PCSpecialist Lafite Pro V 14M to 8042 quirks list Sasha Levin
2025-06-24  4:12 ` [PATCH AUTOSEL 6.6 09/18] powerpc: Fix struct termio related ioctl macros Sasha Levin
2025-06-24  4:12 ` [PATCH AUTOSEL 6.6 10/18] ASoC: amd: yc: update quirk data for HP Victus Sasha Levin
2025-06-24  4:12 ` [PATCH AUTOSEL 6.6 11/18] regulator: fan53555: add enable_time support and soft-start times Sasha Levin
2025-06-24  4:12 ` [PATCH AUTOSEL 6.6 12/18] scsi: target: Fix NULL pointer dereference in core_scsi3_decode_spec_i_port() Sasha Levin
2025-06-24  4:12 ` [PATCH AUTOSEL 6.6 13/18] aoe: defer rexmit timer downdev work to workqueue Sasha Levin
2025-06-24  4:12 ` [PATCH AUTOSEL 6.6 14/18] wifi: mac80211: drop invalid source address OCB frames Sasha Levin
2025-06-24  4:12 ` [PATCH AUTOSEL 6.6 15/18] wifi: ath6kl: remove WARN on bad firmware input Sasha Levin
2025-06-24  4:12 ` [PATCH AUTOSEL 6.6 16/18] ACPICA: Refuse to evaluate a method if arguments are missing Sasha Levin
2025-06-24  4:12 ` [PATCH AUTOSEL 6.6 17/18] mtd: spinand: fix memory leak of ECC engine conf Sasha Levin
2025-06-24  4:12 ` [PATCH AUTOSEL 6.6 18/18] rcu: Return early if callback is not specified 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=20250624041214.84135-3-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=patches@lists.linux.dev \
    --cc=perex@perex.cz \
    --cc=stable@vger.kernel.org \
    --cc=tiwai@suse.de \
    /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.