From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.216.54 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793423679; b=nglOWdB/gBklCYY92QBIUoveF12yyQM4+CvuNx9NDVvVNKdtHjEOAZoZbj0mlkao1uAV i4awUZw0JRw1YnwoZliXAi+s5mSOjeB/MiUQTtpuG4Voqh9APm1/jD9zK6rBksQVHUW47 YcHiJi+RqowTdP2IkqO27eI+xZu5MEx5Ajf2YSdrq1dTrmt81Y6fhyp2z9s8KDW7gvFDM w07pqZycHawV1YVKqWmEpkr5hAyJwDhTY27wdkljHBP1FWu0dZqG3pLD2VCJpCN5803YJ CsMpuuCRt81LD4TWbT38ZVwQUHteLsDNxdSIE5XZOF/nOmvfi3UmuB6j+bXC1RgnAjg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793423679; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-Id:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=JV84msgXUJaDxvG1g2Xeu1J3+jfzXhZ4gyQkFLKAo20=; b=e2US9wBPxnQg7zGHSlOqlsmwsvtSPfbYMJNJIxR1+2qYHRg0wy2R8N+gFWOnumD2iYzO zcJpV+isoAfiI2RANUCu65msNl+f//RnUTVWvsrr0fZtxhh9udvynZ4ukzXTD3XjSc2rX HuoUN6R1J/LQ8C+xjYPZZ+mZwcny8ss7XuAA3Yq9Ctvr9956otxTnRQ4kit7pxIXRNeI3 Pg0mki8NHXUMk8fmNUxciKFLr65ZS+ByHGAaCeziMnSqz/NTLGgY8rJ7bPFEf9GCDhF/d TglS3h1wb6Wzbq7g8QzMQ4byjTMH2y8DibDH6fitnzFz580yKFwz7o0v6TR1QzrDKYA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=ILf6iwf8; arc=none smtp.remote-ip=209.85.216.54 Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C4E20606A31C for ; Sat, 31 Oct 2026 05:14:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C4E20606A31C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=ILf6iwf8 Received: by mail-pj1-f54.google.com with SMTP id 98e67ed59e1d1-3a4b3ac8fb7so903188a91.0 for ; Fri, 30 Oct 2026 22:14:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793423678; x=1794028478; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=JV84msgXUJaDxvG1g2Xeu1J3+jfzXhZ4gyQkFLKAo20=; b=ILf6iwf8V/VJobhvhGdua6Qwd6lsSYAvzoTQnCNUwG2/1ESqujzI7L/t6oZx7WAe7M BtH6QUWd/bR35qMsw0KgMTvkoV7nMRhc9fB9R2LVDJtyjGx0lqjTTgLLbNvkKd6OiUQm aElcg+8ZaG2jgg6L6H4UU+g+8OORO8zgb1p/9IdSBvVlOwJRCpAsb6hqvgyPJdvZ8OXm QqNno2uRF1rNA7sS0H6DgeSpmrNzoASIFWyMl2D91UTC/1YDaIVPY2+dq4qqQHdt8PYW SfS6mHmboeSodbvO91acJ8lgGEoMEsDOJBhkDTI7kwRwsj4zR0Pgrq9t3J+0RlrIAnJR PFUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793423678; x=1794028478; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=JV84msgXUJaDxvG1g2Xeu1J3+jfzXhZ4gyQkFLKAo20=; b=SqWMbBbN163fTdGI2xOsAzWGuwVYOeDUVnVhNAMXupDWyR57zfiNwOEHW2IgSVP4qO cdqjpJbxLK3SnmyBnxbDGz/jgGSeRrYS43+q4bFoUx5yBvINhTxoiQ15VLlMEFdYvL+8 RWiV9/Q/6QYKBRdinpTMGOtHifiImyGo6Jxe0kJpcuIwN5uP1TjVsi4yZIjMwHsJtdDW V0Y5CA6CI2bpeIGtjx0I1nGsWmhtRnW1CO7t0bfjnLmAHnXg7vop/GVMBrMvYcyeeLc0 n0635FbO5Ll15CSUaqsodyCxslcD/p2KX2IU8QW+6Ho1PsiCffC6MPZGT7qOFHY222yx ZTrA== X-Forwarded-Encrypted: i=1; AKwUvBwJtAoAB2BnW/YCTxxARZKfhxuXFsps9uxRptZxBUrO0jfEQxRSFrWkKUI42lcHgYh+x8he/X+8sbfAbws=@vger.kernel.org X-Gm-Message-State: AFq9FYI9W7b02WQHvv6i2FQ8HBiEqw/g6pJYzEtqhfJFrhLx8FFn2hOO ocbHgN4+LLW7XJuhg5R84+70JsSB1RMKDa4Au4FYvM/6kZfsGOno80/s X-Gm-Gg: AYBFou3P4f4dtyAIp8VI/LIJgK3zR1Yls9p3+RYGeX3rWpz8pYwu1i3Y5CMou5pjH3J sN8o8NWatDC8cvSOWfcO3vg6M6y0+xks4zDf5f4jdeuBnxIp/2Mp85IXDp3s08cWlhEJ3gHWrcb P8amjMu/HCnW0aA99zjV91/eNFRvqjzueft/6ukhm52jWqxA52kapUczDPcjF7L+6f2qTgGCcfm +xzh7Ths4+kiBx8nXFgeG77jImPBH4nykJBaKrduUdYMtkUfZM99UCH7xhi95cV8DU60P4nIJ7T C6IzORp/DY6ykxNiBRgU7fe6bXQQFu4loB0Q4MurKHt7IClnOBooNgwmnb4fyoPMWzPFU4aQjq9 A5rwuvZ83EOVWQABlixXMJX5jcH8tjne+Wb0s4kaTVq2EW35ndj4d43T6WN36ZcxgRKxqJjKdpI DMufr0XRlDNzjdqVQ9xdu3GD1GTJ4oIw6cXBlXYSmY2baPG3MgJQGl/Bf5yuJKlaZaxthYJtXZF PDa4310cp3Nfz4S8RHg1GAnFuIcokgBc+05Rl4DoYC96ZfI53RGZ1vn9cLbM2Y77brvQgMRUGpB WmU2QCh3iVXsmczYfXdISGyl X-Received: by 2002:a17:90b:4a83:b0:3ad:b86d:dbad with SMTP id 98e67ed59e1d1-3ae89747e27mr3500938a91.30.1793423678081; Fri, 30 Oct 2026 22:14:38 -0700 (PDT) Received: from localhost ([111.228.63.84]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3ae845df666sm6216305a91.14.2026.10.30.22.14.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2026 22:14:37 -0700 (PDT) From: Cen Zhang To: perex@perex.cz, tiwai@suse.com, thierry.reding@kernel.org, jonathanh@nvidia.com Cc: linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org, linux-tegra@vger.kernel.org, tiwai@suse.de, baijiaju1990@gmail.com, jjzuming@gmail.com, zzzccc427@gmail.com Subject: [PATCH v4 0/5] ALSA: hda: Wait for PCM files on codec teardown Date: Sat, 31 Oct 2026 13:14:25 +0800 Message-Id: X-Mailer: git-send-email 2.34.1 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit When an HD-audio codec is unbound while the card stays registered, the codec remove frees its PCMs while files can still use them, and the probe and remove of codecs on one bus can run at the same time. Following Takashi's suggestion on v2, this version fixes both in the HD-audio layer: patch 1 serializes the codec probe and remove and the card registration on a bus, and patch 5 makes the codec teardown wait until the files opened on its PCMs are closed. Patches 2 and 3 add the file to the card while the PCM minor is looked up, so that the wait does not miss an open between the lookup and snd_card_file_add(), and record the device a file was opened for. The teardown waits only for the files of its own PCMs, because the card files also include the control device, which a sound server keeps open for as long as it runs. Patch 4 makes an open fail once its PCM is disconnected, so that a late open does not get a working stream and hold off the teardown. Cen Zhang (5): ALSA: hda: Serialize codec probe and remove on the same bus ALSA: core: Add the card file while looking up a minor ALSA: pcm: Add the file to the card while looking up the minor ALSA: pcm: Refuse to open a disconnected PCM ALSA: hda: Wait for the files of the codec PCMs before freeing them include/sound/core.h | 7 ++++ include/sound/hda_codec.h | 1 + include/sound/hdaudio.h | 1 + include/sound/pcm.h | 1 + sound/core/init.c | 61 +++++++++++++++++++++++++++--- sound/core/oss/pcm_oss.c | 19 +++------- sound/core/pcm.c | 3 ++ sound/core/pcm_native.c | 37 ++++++++---------- sound/core/sound.c | 34 +++++++++++++++++ sound/core/sound_oss.c | 21 ++++++++++ sound/hda/common/bind.c | 43 +++++++++++++++++++++ sound/hda/common/sysfs.c | 2 +- sound/hda/controllers/acpi.c | 2 +- sound/hda/controllers/cix-ipbloq.c | 2 +- sound/hda/controllers/intel.c | 2 +- sound/hda/controllers/tegra.c | 2 +- sound/hda/core/bus.c | 1 + 17 files changed, 193 insertions(+), 46 deletions(-) base-commit: a4311e9447bbb219044db38897f95be112f46a8a --- Changes in v4: - Address the unlocked snd_card_register() callers raised by Sashiko: https://sashiko.dev/#/patchset/98644 - Patch 1: add snd_hda_card_register() and use it in the controller probes and in the reconfig sysfs knob, so that the card registration is serialized with codec probe and remove as well. - Patch 1: use mutex_lock() and mutex_unlock() in hda_codec_driver_probe() instead of mixing guard() with goto. Link to v1: https://lore.kernel.org/r/pm-pmb-a4703edca61d34aa679b-v6-680f350d78e44f9de7a7@gmail.com Link to v2: https://lore.kernel.org/r/pm-pmb-a4703edca61d34aa679b-v9-c4f3df026f28aea10fd1-0@gmail.com Link to v3: https://lore.kernel.org/r/pm-pmb-a4703edca61d34aa679b-v11-d9186d19e8afb48972af-0@gmail.com