From: Takashi Iwai <tiwai@suse.de>
To: Rosen Penev <rosenp@gmail.com>
Cc: linux-sound@vger.kernel.org, Jaroslav Kysela <perex@perex.cz>,
Takashi Iwai <tiwai@suse.com>,
linux-kernel@vger.kernel.org (open list)
Subject: Re: [PATCH] ALSA: usb-audio: use kzalloc_flex
Date: Thu, 12 Mar 2026 07:34:30 +0100 [thread overview]
Message-ID: <87tsuld095.wl-tiwai@suse.de> (raw)
In-Reply-To: <20260311232748.18697-1-rosenp@gmail.com>
On Thu, 12 Mar 2026 00:27:48 +0100,
Rosen Penev wrote:
>
> Saves one allocation by using a flexible array member.
As it's a fixed size array, it doesn't have to be a flex array at all,
so it can be even simpler.
thanks,
Takashi
>
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
> ---
> sound/usb/mixer.c | 22 +++++++---------------
> sound/usb/mixer.h | 5 +++--
> 2 files changed, 10 insertions(+), 17 deletions(-)
>
> diff --git a/sound/usb/mixer.c b/sound/usb/mixer.c
> index 7007e0c9489b..337815b9e72c 100644
> --- a/sound/usb/mixer.c
> +++ b/sound/usb/mixer.c
> @@ -1393,7 +1393,7 @@ static int mixer_ctl_feature_info(struct snd_kcontrol *kcontrol,
> if (!cval->initialized) {
> get_min_max_with_quirks(cval, 0, kcontrol);
> if (cval->initialized && cval->dBmin >= cval->dBmax) {
> - kcontrol->vd[0].access &=
> + kcontrol->vd[0].access &=
> ~(SNDRV_CTL_ELEM_ACCESS_TLV_READ |
> SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK);
> snd_ctl_notify(cval->head.mixer->chip->card,
> @@ -3006,15 +3006,12 @@ static void snd_usb_mixer_free(struct usb_mixer_interface *mixer)
> snd_usb_mixer_disconnect(mixer);
>
> /* Unregister controls first, snd_ctl_remove() frees the element */
> - if (mixer->id_elems) {
> - for (id = 0; id < MAX_ID_ELEMS; id++) {
> - for (list = mixer->id_elems[id]; list; list = next) {
> - next = list->next_id_elem;
> - if (list->kctl)
> - snd_ctl_remove(mixer->chip->card, list->kctl);
> - }
> + for (id = 0; id < MAX_ID_ELEMS; id++) {
> + for (list = mixer->id_elems[id]; list; list = next) {
> + next = list->next_id_elem;
> + if (list->kctl)
> + snd_ctl_remove(mixer->chip->card, list->kctl);
> }
> - kfree(mixer->id_elems);
> }
> if (mixer->urb) {
> kfree(mixer->urb->transfer_buffer);
> @@ -3652,16 +3649,11 @@ int snd_usb_create_mixer(struct snd_usb_audio *chip, int ctrlif)
>
> strscpy(chip->card->mixername, "USB Mixer");
>
> - mixer = kzalloc_obj(*mixer);
> + mixer = kzalloc_flex(*mixer, id_elems, MAX_ID_ELEMS);
> if (!mixer)
> return -ENOMEM;
> mixer->chip = chip;
> mixer->ignore_ctl_error = !!(chip->quirk_flags & QUIRK_FLAG_IGNORE_CTL_ERROR);
> - mixer->id_elems = kzalloc_objs(*mixer->id_elems, MAX_ID_ELEMS);
> - if (!mixer->id_elems) {
> - kfree(mixer);
> - return -ENOMEM;
> - }
>
> mixer->hostif = &usb_ifnum_to_if(chip->dev, ctrlif)->altsetting[0];
> switch (get_iface_desc(mixer->hostif)->bInterfaceProtocol) {
> diff --git a/sound/usb/mixer.h b/sound/usb/mixer.h
> index 167fbfcf01ac..30dd30b925fc 100644
> --- a/sound/usb/mixer.h
> +++ b/sound/usb/mixer.h
> @@ -19,8 +19,6 @@ struct usb_mixer_interface {
> struct list_head list;
> unsigned int ignore_ctl_error;
> struct urb *urb;
> - /* array[MAX_ID_ELEMS], indexed by unit id */
> - struct usb_mixer_elem_list **id_elems;
>
> /* the usb audio specification version this interface complies to */
> int protocol;
> @@ -42,6 +40,9 @@ struct usb_mixer_interface {
> void *private_data;
> void (*private_free)(struct usb_mixer_interface *mixer);
> void (*private_suspend)(struct usb_mixer_interface *mixer);
> +
> + /* array[MAX_ID_ELEMS], indexed by unit id */
> + struct usb_mixer_elem_list *id_elems[];
> };
>
> #define MAX_CHANNELS 16 /* max logical channels */
> --
> 2.53.0
>
next prev parent reply other threads:[~2026-03-12 6:34 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-11 23:27 [PATCH] ALSA: usb-audio: use kzalloc_flex Rosen Penev
2026-03-12 6:34 ` Takashi Iwai [this message]
2026-03-12 6:45 ` Rosen Penev
2026-03-13 22:02 ` Rosen Penev
2026-03-14 13:29 ` Takashi Iwai
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=87tsuld095.wl-tiwai@suse.de \
--to=tiwai@suse.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=perex@perex.cz \
--cc=rosenp@gmail.com \
--cc=tiwai@suse.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.