From: Takashi Iwai <tiwai@suse.de>
To: cryolitia@uniontech.com,
Cryolitia PukNgae via B4 Relay
<devnull+cryolitia.uniontech.com@kernel.org>
Cc: 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>,
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,
Takashi Iwai <tiwai@suse.de>
Subject: Re: [PATCH v3 3/4] ALSA: usb-audio: add module param device_quirk_flags
Date: Wed, 17 Sep 2025 15:45:40 +0200 [thread overview]
Message-ID: <87ms6tchvf.wl-tiwai@suse.de> (raw)
In-Reply-To: <20250917-sound-v3-3-92ebe9472a0a@uniontech.com>
On Wed, 17 Sep 2025 14:46:42 +0200,
Cryolitia PukNgae via B4 Relay wrote:
>
> From: Cryolitia PukNgae <cryolitia@uniontech.com>
>
> For apply and unapply quirk flags more flexibly though param and sysfs
>
> Co-developed-by: Takashi Iwai <tiwai@suse.de>
> Signed-off-by: Cryolitia PukNgae <cryolitia@uniontech.com>
I think an easier approach would be to rather parse the string value
at each time when probing a device and seeking for options.
That is, let's code without a mutex at first (for the permission
0444):
void snd_usb_init_dynamic_quirks(int idx, struct snd_usb_audio *chip)
{
....
/* old style option found: the position-based integer value */
if (quirk_flags[idx] &&
!kstrtou32(quirk_flags[idx], 0, &chip->quirk_flags)) {
usb_audio_dbg(....);
return;
}
/* take the default quirk from the quirk table */
snd_usb_init_quirk_flags(chip);
for (i = 0; i < ARRAY_SIZE(quirk_flags); i++) {
if (quirk_flags[i] && *quirk_flags[i]) {
err = parse_quirk_option(chip, quirk_flags[i]);
if (err < 0)
return;
}
}
}
and the parser would be something like:
static int parse_quirk_option(struct snd_usb_audio *chip, const char *str)
{
char *val __free(kfree) = NULL;
char *field;
int pid, vid;
if (!strchr(str, ':'))
return 0;
val = kstrdup(str, GFP_KERNEL);
if (!val)
return -ENOMEM;
/* Each entry consists of VID:PID:flags */
field = strsep(&p, ":");
if (!field)
return 0;
if (strcmp(field, "*") == 0)
vid = 0;
else if (kstrtou16(field, 16, &vid))
return 0; // can spew warning message, too
field = strsep(&p, ":");
if (!field)
return 0;
if (strcmp(field, "*") == 0)
pid = 0;
else if (kstrtou16(field, 16, &pid))
return 0; // can spew warning message, too
.... // evaluate the tokens, set or clear chip->quirk_flags accordingly
return 0;
}
So you can just use the normal charp type for the parameters.
Once after this working, we may want to allow the dynamic module
parameter change. Then make the parameter a special type just to take
the device_quirk_mutex at set callback, while the set callback simply
calls parm_set_charp() for the rest. For get and free callbacks, we
can use param_get_charp() and param_free_charp() as is.
Finally, snd_usb_init_dynamic_quirks() takes the device_quirk_mutex,
and that's all. No need for heavy cleanups or linked list handling.
Of course, it's a bit inefficient from the performance POV, but the
device probing is rather a very rare event, so the speed doesn't
matter at all.
thanks,
Takashi
next prev parent reply other threads:[~2025-09-17 13:45 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-17 12:46 [PATCH v3 0/4] ALSA: usb-audio: add module param device_quirk_flags Cryolitia PukNgae via B4 Relay
2025-09-17 12:46 ` [PATCH v3 1/4] ALSA: usb-audio: add two-way convert between name and bit for QUIRK_FLAG_* Cryolitia PukNgae via B4 Relay
2025-09-17 12:46 ` [PATCH v3 2/4] param: export param_array related functions Cryolitia PukNgae via B4 Relay
2025-09-17 12:46 ` [PATCH v3 3/4] ALSA: usb-audio: add module param device_quirk_flags Cryolitia PukNgae via B4 Relay
2025-09-17 13:45 ` Takashi Iwai [this message]
2025-09-17 12:46 ` [PATCH v3 4/4] ALSA: doc: add docs about device_device_quirk_flags in snd-usb-audio Cryolitia PukNgae via B4 Relay
2025-09-17 13:27 ` Dragan Simic
2025-09-17 14:09 ` Cryolitia
2025-09-17 17:58 ` Randy Dunlap
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=87ms6tchvf.wl-tiwai@suse.de \
--to=tiwai@suse.de \
--cc=anguoli@uniontech.com \
--cc=corbet@lwn.net \
--cc=cryolitia@uniontech.com \
--cc=da.gomez@kernel.org \
--cc=devnull+cryolitia.uniontech.com@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=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).