linux-modules.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Cryolitia PukNgae via B4 Relay <devnull+cryolitia.uniontech.com@kernel.org>
To: Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
	 Jonathan Corbet <corbet@lwn.net>,
	Luis Chamberlain <mcgrof@kernel.org>,
	 Petr Pavlu <petr.pavlu@suse.com>,
	Daniel Gomez <da.gomez@kernel.org>,
	 Sami Tolvanen <samitolvanen@google.com>
Cc: linux-sound@vger.kernel.org, linux-usb@vger.kernel.org,
	 linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org,
	 Mingcong Bai <jeffbai@aosc.io>,
	Kexy Biscuit <kexybiscuit@aosc.io>,
	 Nie Cheng <niecheng1@uniontech.com>,
	Zhan Jun <zhanjun@uniontech.com>,
	 Feng Yuan <fengyuan@uniontech.com>,
	qaqland <anguoli@uniontech.com>,
	 kernel@uniontech.com, linux-modules@vger.kernel.org,
	 Cryolitia PukNgae <cryolitia@uniontech.com>,
	Takashi Iwai <tiwai@suse.de>
Subject: [PATCH v4 4/5] ALSA: usb-audio: make param quirk_flags change-able in runtime
Date: Thu, 18 Sep 2025 17:24:33 +0800	[thread overview]
Message-ID: <20250918-sound-v4-4-82cf8123d61c@uniontech.com> (raw)
In-Reply-To: <20250918-sound-v4-0-82cf8123d61c@uniontech.com>

From: Cryolitia PukNgae <cryolitia@uniontech.com>

Developers now can change it during sysfs, without rebooting, for
debugging new buggy devices.

Co-developed-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Cryolitia PukNgae <cryolitia@uniontech.com>
---
 sound/usb/card.c     | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++--
 sound/usb/quirks.c   |  9 +++++++--
 sound/usb/usbaudio.h |  2 ++
 3 files changed, 63 insertions(+), 4 deletions(-)

diff --git a/sound/usb/card.c b/sound/usb/card.c
index 5837677effa1787ef9d7d02714c3ae43b1a8bc79..fd99df5949df826d97b3d2bc6d3137923ab4295d 100644
--- a/sound/usb/card.c
+++ b/sound/usb/card.c
@@ -103,13 +103,65 @@ module_param_array(delayed_register, charp, NULL, 0444);
 MODULE_PARM_DESC(delayed_register, "Quirk for delayed registration, given by id:iface, e.g. 0123abcd:4.");
 module_param_array(implicit_fb, bool, NULL, 0444);
 MODULE_PARM_DESC(implicit_fb, "Apply generic implicit feedback sync mode.");
-module_param_array(quirk_flags, charp, NULL, 0444);
-MODULE_PARM_DESC(quirk_flags, "Driver quirk bit flags.");
 module_param_named(use_vmalloc, snd_usb_use_vmalloc, bool, 0444);
 MODULE_PARM_DESC(use_vmalloc, "Use vmalloc for PCM intermediate buffers (default: yes).");
 module_param_named(skip_validation, snd_usb_skip_validation, bool, 0444);
 MODULE_PARM_DESC(skip_validation, "Skip unit descriptor validation (default: no).");
 
+/* protects quirk_flags */
+DEFINE_MUTEX(quirk_flags_mutex);
+
+static int quirk_flags_param_set(const char *value,
+				 const struct kernel_param *kp)
+{
+	int err;
+
+	mutex_lock(&quirk_flags_mutex);
+
+	memset(quirk_flags, 0, sizeof(quirk_flags));
+	err = param_array_set(value, kp);
+
+	mutex_unlock(&quirk_flags_mutex);
+
+	return err;
+}
+
+static int quirk_flags_param_get(char *buffer, const struct kernel_param *kp)
+{
+	int err;
+
+	mutex_lock(&quirk_flags_mutex);
+	err = param_array_get(buffer, kp);
+	mutex_unlock(&quirk_flags_mutex);
+
+	return err;
+}
+
+static void quirk_flags_param_free(void *arg)
+{
+	mutex_lock(&quirk_flags_mutex);
+	param_array_free(arg);
+	mutex_unlock(&quirk_flags_mutex);
+}
+
+static const struct kernel_param_ops quirk_flags_param_ops = {
+	.set = quirk_flags_param_set,
+	.get = quirk_flags_param_get,
+	.free = quirk_flags_param_free,
+};
+
+static struct kparam_array quirk_flags_param_array = {
+	.max = SNDRV_CARDS,
+	.elemsize = sizeof(char *),
+	.num = NULL,
+	.ops = &param_ops_charp,
+	.elem = &quirk_flags,
+};
+
+device_param_cb(quirk_flags, &quirk_flags_param_ops, &quirk_flags_param_array,
+		0644);
+MODULE_PARM_DESC(quirk_flags, "Add/modify USB audio quirks");
+
 /*
  * we keep the snd_usb_audio_t instances by ourselves for merging
  * the all interfaces on the same card as one sound device.
diff --git a/sound/usb/quirks.c b/sound/usb/quirks.c
index 4dc2464133e934e48b1fa613884a8a0ebdaff91d..ba9ea94399e5a6e7e1711b2a9148c90f991f05cd 100644
--- a/sound/usb/quirks.c
+++ b/sound/usb/quirks.c
@@ -2548,6 +2548,8 @@ void snd_usb_init_quirk_flags(int idx, struct snd_usb_audio *chip)
 	u16 vid, pid;
 	size_t i;
 
+	mutex_lock(&quirk_flags_mutex);
+
 	/* old style option found: the position-based integer value */
 	if (quirk_flags[idx] &&
 	    !kstrtou32(quirk_flags[idx], 0, &chip->quirk_flags)) {
@@ -2556,7 +2558,7 @@ void snd_usb_init_quirk_flags(int idx, struct snd_usb_audio *chip)
 			      chip->quirk_flags, idx,
 			      USB_ID_VENDOR(chip->usb_id),
 			      USB_ID_PRODUCT(chip->usb_id));
-		return;
+		goto unlock;
 	}
 
 	/* take the default quirk from the quirk table */
@@ -2571,7 +2573,7 @@ void snd_usb_init_quirk_flags(int idx, struct snd_usb_audio *chip)
 
 		if (!val) {
 			pr_err("snd_usb_audio: Error allocating memory while parsing quirk_flags\n");
-			return;
+			goto unlock;
 		}
 
 		for (p = val; p && *p;) {
@@ -2653,4 +2655,7 @@ void snd_usb_init_quirk_flags(int idx, struct snd_usb_audio *chip)
 
 		kfree(val);
 	}
+
+unlock:
+	mutex_unlock(&quirk_flags_mutex);
 }
diff --git a/sound/usb/usbaudio.h b/sound/usb/usbaudio.h
index 73564cd68ebf101291440d0171eb81c220c6f5e2..40551946c20df8c17d306fddd8295ca3a2bfa702 100644
--- a/sound/usb/usbaudio.h
+++ b/sound/usb/usbaudio.h
@@ -168,6 +168,8 @@ extern char *quirk_flags[SNDRV_CARDS];
 extern bool snd_usb_use_vmalloc;
 extern bool snd_usb_skip_validation;
 
+extern struct mutex quirk_flags_mutex;
+
 /*
  * Driver behavior quirk flags, stored in chip->quirk_flags
  *

-- 
2.51.0



  parent reply	other threads:[~2025-09-18  9:24 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-18  9:24 [PATCH v4 0/5] ALSA: usb-audio: add module param device_quirk_flags Cryolitia PukNgae via B4 Relay
2025-09-18  9:24 ` [PATCH v4 1/5] ALSA: usb-audio: add two-way convert between name and bit for QUIRK_FLAG_* Cryolitia PukNgae via B4 Relay
2025-09-19 12:32   ` Takashi Iwai
2025-09-18  9:24 ` [PATCH v4 2/5] param: export param_array related functions Cryolitia PukNgae via B4 Relay
2025-09-19 12:37   ` Takashi Iwai
2025-09-18  9:24 ` [PATCH v4 3/5] ALSA: usb-audio: improve module param quirk_flags Cryolitia PukNgae via B4 Relay
2025-09-19 12:47   ` Takashi Iwai
2025-09-18  9:24 ` Cryolitia PukNgae via B4 Relay [this message]
2025-09-18  9:24 ` [PATCH v4 5/5] ALSA: doc: add docs about improved quirk_flags in snd-usb-audio Cryolitia PukNgae via B4 Relay
2025-09-18 20:21   ` Randy Dunlap
2025-09-19  1:43     ` Cryolitia PukNgae

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=20250918-sound-v4-4-82cf8123d61c@uniontech.com \
    --to=devnull+cryolitia.uniontech.com@kernel.org \
    --cc=anguoli@uniontech.com \
    --cc=corbet@lwn.net \
    --cc=cryolitia@uniontech.com \
    --cc=da.gomez@kernel.org \
    --cc=fengyuan@uniontech.com \
    --cc=jeffbai@aosc.io \
    --cc=kernel@uniontech.com \
    --cc=kexybiscuit@aosc.io \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-modules@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mcgrof@kernel.org \
    --cc=niecheng1@uniontech.com \
    --cc=perex@perex.cz \
    --cc=petr.pavlu@suse.com \
    --cc=samitolvanen@google.com \
    --cc=tiwai@suse.com \
    --cc=tiwai@suse.de \
    --cc=zhanjun@uniontech.com \
    /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;
as well as URLs for NNTP newsgroup(s).