]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
ALSA: ctxfi: simplify mixer allocation
authorRosen Penev <rosenp@gmail.com>
Sat, 25 Apr 2026 01:30:20 +0000 (18:30 -0700)
committerTakashi Iwai <tiwai@suse.de>
Mon, 27 Apr 2026 11:52:24 +0000 (13:52 +0200)
Combine 3 allocations into one to simplify memory management.

No need for 3 separate frees now.

Replace void pointers with proper types. No need for void here.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Link: https://patch.msgid.link/20260425013020.430496-1-rosenp@gmail.com
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/pci/ctxfi/ctmixer.c
sound/pci/ctxfi/ctmixer.h

index e3ee76bd8482466beddd7b6885d2e503f93d28e9..50ab69aca2fa31c2e3fe10726061590433542131 100644 (file)
@@ -965,35 +965,20 @@ error1:
 static int ct_mixer_get_mem(struct ct_mixer **rmixer)
 {
        struct ct_mixer *mixer;
-       int err;
+       size_t alloc_size;
 
        *rmixer = NULL;
        /* Allocate mem for mixer obj */
-       mixer = kzalloc_obj(*mixer);
+       alloc_size = struct_size(mixer, amixers, NUM_CT_AMIXERS * CHN_NUM);
+       alloc_size += sizeof(*mixer->sums) * NUM_CT_SUMS * CHN_NUM;
+       mixer = kzalloc(alloc_size, GFP_KERNEL);
        if (!mixer)
                return -ENOMEM;
 
-       mixer->amixers = kcalloc(NUM_CT_AMIXERS * CHN_NUM, sizeof(void *),
-                                GFP_KERNEL);
-       if (!mixer->amixers) {
-               err = -ENOMEM;
-               goto error1;
-       }
-       mixer->sums = kcalloc(NUM_CT_SUMS * CHN_NUM, sizeof(void *),
-                             GFP_KERNEL);
-       if (!mixer->sums) {
-               err = -ENOMEM;
-               goto error2;
-       }
+       mixer->sums = (struct sum **)(mixer->amixers + (NUM_CT_AMIXERS * CHN_NUM));
 
        *rmixer = mixer;
        return 0;
-
-error2:
-       kfree(mixer->amixers);
-error1:
-       kfree(mixer);
-       return err;
 }
 
 static int ct_mixer_topology_build(struct ct_mixer *mixer)
@@ -1228,8 +1213,6 @@ int ct_mixer_destroy(struct ct_mixer *mixer)
        }
 
        /* Release mem assigned to mixer object */
-       kfree(mixer->sums);
-       kfree(mixer->amixers);
        kfree(mixer);
 
        return 0;
index e812f6c93b41cad4b9b2ccdadd958c97378e96bf..dd23d227aeb5aa158f86034de82b84a314f973bd 100644 (file)
@@ -41,8 +41,7 @@ enum MIXER_PORT_T {
 struct ct_mixer {
        struct ct_atc *atc;
 
-       void **amixers;         /* amixer resources for volume control */
-       void **sums;            /* sum resources for signal collection */
+       struct sum **sums;              /* sum resources for signal collection */
        unsigned int switch_state; /* A bit-map to indicate state of switches */
 
        int (*get_output_ports)(struct ct_mixer *mixer, enum MIXER_PORT_T type,
@@ -55,6 +54,7 @@ struct ct_mixer {
 #ifdef CONFIG_PM_SLEEP
        int (*resume)(struct ct_mixer *mixer);
 #endif
+       struct amixer *amixers[];               /* amixer resources for volume control */
 };
 
 int ct_alsa_mix_create(struct ct_atc *atc,