From: Rosen Penev <rosenp@gmail.com>
To: linux-sound@vger.kernel.org
Cc: Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
linux-kernel@vger.kernel.org (open list)
Subject: [PATCH] ALSA: hda: allocate nodes with tree
Date: Fri, 24 Apr 2026 19:34:21 -0700 [thread overview]
Message-ID: <20260425023421.476334-1-rosenp@gmail.com> (raw)
Use a flexible array member to combine allocations. Simplifies
allocation and freeing.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
sound/hda/core/sysfs.c | 22 ++++------------------
1 file changed, 4 insertions(+), 18 deletions(-)
diff --git a/sound/hda/core/sysfs.c b/sound/hda/core/sysfs.c
index 3e102538e058..f14ce1203a9f 100644
--- a/sound/hda/core/sysfs.c
+++ b/sound/hda/core/sysfs.c
@@ -13,7 +13,7 @@
struct hdac_widget_tree {
struct kobject *root;
struct kobject *afg;
- struct kobject **nodes;
+ struct kobject *nodes[];
};
#define CODEC_ATTR(type) \
@@ -325,11 +325,8 @@ static void widget_tree_free(struct hdac_device *codec)
if (!tree)
return;
free_widget_node(tree->afg, &widget_afg_group);
- if (tree->nodes) {
- for (p = tree->nodes; *p; p++)
- free_widget_node(*p, &widget_node_group);
- kfree(tree->nodes);
- }
+ for (p = tree->nodes; *p; p++)
+ free_widget_node(*p, &widget_node_group);
kobject_put(tree->root);
kfree(tree);
codec->widgets = NULL;
@@ -366,7 +363,7 @@ static int widget_tree_create(struct hdac_device *codec)
int i, err;
hda_nid_t nid;
- tree = codec->widgets = kzalloc_obj(*tree);
+ tree = codec->widgets = kzalloc_flex(*tree, nodes, codec->num_nodes + 1);
if (!tree)
return -ENOMEM;
@@ -374,10 +371,6 @@ static int widget_tree_create(struct hdac_device *codec)
if (!tree->root)
return -ENOMEM;
- tree->nodes = kzalloc_objs(*tree->nodes, codec->num_nodes + 1);
- if (!tree->nodes)
- return -ENOMEM;
-
for (i = 0, nid = codec->start_nid; i < codec->num_nodes; i++, nid++) {
err = add_widget_node(tree->root, nid, &widget_node_group,
&tree->nodes[i]);
@@ -435,12 +428,6 @@ int hda_widget_sysfs_reinit(struct hdac_device *codec,
if (!tree)
return -ENOMEM;
- tree->nodes = kzalloc_objs(*tree->nodes, num_nodes + 1);
- if (!tree->nodes) {
- kfree(tree);
- return -ENOMEM;
- }
-
/* prune non-existing nodes */
for (i = 0, nid = codec->start_nid; i < codec->num_nodes; i++, nid++) {
if (nid < start_nid || nid >= end_nid)
@@ -459,7 +446,6 @@ int hda_widget_sysfs_reinit(struct hdac_device *codec,
}
/* replace with the new tree */
- kfree(codec->widgets->nodes);
kfree(codec->widgets);
codec->widgets = tree;
--
2.54.0
next reply other threads:[~2026-04-25 2:34 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-25 2:34 Rosen Penev [this message]
2026-04-27 11:47 ` [PATCH] ALSA: hda: allocate nodes with tree Takashi Iwai
2026-04-27 11:55 ` 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=20260425023421.476334-1-rosenp@gmail.com \
--to=rosenp@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=perex@perex.cz \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox