public inbox for linux-sound@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ALSA: ctxfi: simplify mixer allocation
@ 2026-04-25  1:30 Rosen Penev
  2026-04-27 11:52 ` Takashi Iwai
  0 siblings, 1 reply; 2+ messages in thread
From: Rosen Penev @ 2026-04-25  1:30 UTC (permalink / raw)
  To: linux-sound; +Cc: Jaroslav Kysela, Takashi Iwai, open list

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>
---
 sound/pci/ctxfi/ctmixer.c | 27 +++++----------------------
 sound/pci/ctxfi/ctmixer.h |  4 ++--
 2 files changed, 7 insertions(+), 24 deletions(-)

diff --git a/sound/pci/ctxfi/ctmixer.c b/sound/pci/ctxfi/ctmixer.c
index e3ee76bd8482..50ab69aca2fa 100644
--- a/sound/pci/ctxfi/ctmixer.c
+++ b/sound/pci/ctxfi/ctmixer.c
@@ -965,35 +965,20 @@ static int ct_mixer_get_resources(struct ct_mixer *mixer)
 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;
diff --git a/sound/pci/ctxfi/ctmixer.h b/sound/pci/ctxfi/ctmixer.h
index e812f6c93b41..dd23d227aeb5 100644
--- a/sound/pci/ctxfi/ctmixer.h
+++ b/sound/pci/ctxfi/ctmixer.h
@@ -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,
-- 
2.54.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] ALSA: ctxfi: simplify mixer allocation
  2026-04-25  1:30 [PATCH] ALSA: ctxfi: simplify mixer allocation Rosen Penev
@ 2026-04-27 11:52 ` Takashi Iwai
  0 siblings, 0 replies; 2+ messages in thread
From: Takashi Iwai @ 2026-04-27 11:52 UTC (permalink / raw)
  To: Rosen Penev; +Cc: linux-sound, Jaroslav Kysela, Takashi Iwai, open list

On Sat, 25 Apr 2026 03:30:20 +0200,
Rosen Penev wrote:
> 
> 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>

Applied to for-next branch now.  Thanks.


Takashi

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-04-27 11:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-25  1:30 [PATCH] ALSA: ctxfi: simplify mixer allocation Rosen Penev
2026-04-27 11:52 ` Takashi Iwai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox