From: Takashi Iwai <tiwai@suse.de>
To: cryolitia@uniontech.com
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
Subject: Re: [PATCH v4 1/5] ALSA: usb-audio: add two-way convert between name and bit for QUIRK_FLAG_*
Date: Fri, 19 Sep 2025 14:32:10 +0200 [thread overview]
Message-ID: <87tt0y8vxx.wl-tiwai@suse.de> (raw)
In-Reply-To: <20250918-sound-v4-1-82cf8123d61c@uniontech.com>
On Thu, 18 Sep 2025 11:24:30 +0200,
Cryolitia PukNgae via B4 Relay wrote:
> --- a/sound/usb/quirks.c
> +++ b/sound/usb/quirks.c
> @@ -2446,6 +2446,62 @@ static const struct usb_audio_quirk_flags_table quirk_flags_table[] = {
> {} /* terminator */
> };
>
> +static const char *const snd_usb_audio_quirk_flag_names[] = {
> + "get_sample_rate",
> + "share_media_device",
I think it's worth to add a comment that this each entry corresponds
to QUIRK_FLAG_XXX. Or another idea would be to define enums like:
enum {
QUIRK_TYPE_GET_SAMPLE_RATE,
QUIRK_TYPE_SHARE_MEDIA_DEVICE,
....
};
then redefine QUIRK_FLAG_* like:
#define QUIRK_FLAG_GET_SAMPLE_RATE BIT_U32(QUIRK_TYPE_GET_SAMPLE_RATE)
#define QUIRK_FLAG_SHARE_MEDIA_DEVICE BIT_U32(QUIRK_TYPE_SHARE_MEDIA_DEVICE)
....
or
#define QUIRK_FLAG(x) BIT_U32(QUIRK_TYPE_ ## x)
and use like QUIRK_FLAG(GET_SAMPLE_RATE).
With those changes, the above can be defined more safely like
static const char *const snd_usb_audio_quirk_flag_names[] = {
[QUIRK_TYPE_GET_SAMPLE_RATE] = "get_sample_rate",
....
or even more drastically by defining some macro for each entry like:
#define QUIRK_STRING_ENTRY(x) \
[QUIRK_TYPE_ ## x] = __stringify(x)
and put like:
static const char *const snd_usb_audio_quirk_flag_names[] = {
QUIRK_STRING_ENTRY(GET_SAMPLE_RATE),
....
};
In this case, it'll become upper letters, so the parse would need to
deal with the case-insensitive comparison, though.
> +u32 snd_usb_quirk_flags_from_name(char *name)
Use const char *.
> +{
> + u32 flag = 0;
> + u32 i;
The iterator can be simple int.
> + if (!name || !*name)
> + return 0;
> +
> + for (i = 0; snd_usb_audio_quirk_flag_names[i]; i++) {
> + if (strcmp(name, snd_usb_audio_quirk_flag_names[i]) == 0) {
> + flag = (1U << i);
Use BIT_U32(i)
> + break;
We can return the value directly, so flag variable can be dropped.
> void snd_usb_init_quirk_flags(struct snd_usb_audio *chip)
> {
> const struct usb_audio_quirk_flags_table *p;
> @@ -2454,10 +2510,28 @@ void snd_usb_init_quirk_flags(struct snd_usb_audio *chip)
> if (chip->usb_id == p->id ||
> (!USB_ID_PRODUCT(p->id) &&
> USB_ID_VENDOR(chip->usb_id) == USB_ID_VENDOR(p->id))) {
> - usb_audio_dbg(chip,
> - "Set quirk_flags 0x%x for device %04x:%04x\n",
> - p->flags, USB_ID_VENDOR(chip->usb_id),
> - USB_ID_PRODUCT(chip->usb_id));
> + unsigned long flags = p->flags;
> + unsigned long bit;
> +
> + for_each_set_bit(bit, &flags,
> + BYTES_TO_BITS(sizeof(p->flags))) {
> + const char *name =
> + snd_usb_audio_quirk_flag_names[bit];
> +
> + if (name)
> + usb_audio_dbg(chip,
> + "Set quirk flag %s for device %04x:%04x\n",
> + name,
> + USB_ID_VENDOR(chip->usb_id),
> + USB_ID_PRODUCT(chip->usb_id));
> + else
> + usb_audio_warn(chip,
> + "Set unknown quirk flag 0x%lx for device %04x:%04x\n",
> + bit,
> + USB_ID_VENDOR(chip->usb_id),
> + USB_ID_PRODUCT(chip->usb_id));
> + }
This could be better factored out as a function.
thanks,
Takashi
next prev parent reply other threads:[~2025-09-19 12:32 UTC|newest]
Thread overview: 17+ 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
2025-09-18 9:24 ` 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
2025-09-18 9:24 ` Cryolitia PukNgae via B4 Relay
2025-09-19 12:32 ` Takashi Iwai [this message]
2025-09-18 9:24 ` [PATCH v4 2/5] param: export param_array related functions Cryolitia PukNgae
2025-09-18 9:24 ` 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
2025-09-18 9:24 ` Cryolitia PukNgae via B4 Relay
2025-09-19 12:47 ` Takashi Iwai
2025-09-18 9:24 ` [PATCH v4 4/5] ALSA: usb-audio: make param quirk_flags change-able in runtime Cryolitia PukNgae
2025-09-18 9:24 ` Cryolitia PukNgae via B4 Relay
2025-09-18 9:24 ` [PATCH v4 5/5] ALSA: doc: add docs about improved quirk_flags in snd-usb-audio Cryolitia PukNgae
2025-09-18 9:24 ` 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=87tt0y8vxx.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=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 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.