Re: [PATCH v5 2/4] ALSA: usb-audio: improve module param quirk_flags

From: Takashi Iwai

Date: Sat Sep 27 2025 - 05:30:11 EST


On Thu, 25 Sep 2025 11:25:17 +0200,
Cryolitia PukNgae via B4 Relay wrote:
> +static void snd_usb_init_quirk_flags(int idx, struct snd_usb_audio *chip)
> +{
> + /* add or correct quirk bits from options */
> + for (i = 0; i < ARRAY_SIZE(quirk_flags); i++) {
> + if (!quirk_flags[i] || !*quirk_flags[i])
> + break;
> +
> + val = kstrdup(quirk_flags[i], GFP_KERNEL);
> +
> + if (!val)
> + return;
> +
> + snd_usb_init_quirk_flags_parse_string(chip, val);
> +
> + kfree(val);

For a temporary string allocation, nowadays it's better to use
__free(kfree):

for (i = 0; i < ARRAY_SIZE(quirk_flags); i++) {
if (!quirk_flags[i] || !*quirk_flags[i])
break;

char *val __free(kfree) =
kstrdup(quirk_flags[i], GFP_KERNEL);
if (!val)
return;

snd_usb_init_quirk_flags_parse_string(chip, val);
}

Or maybe it's even safer to pass the original string (with const) and
do kstrdup() in the callee side. You can use __free(kfree) in the
same way in snd_usb_init_quirk_flags_parse_string().


thanks,

Takashi