From: Rosen Penev <rosenp@gmail.com>
To: linux-sound@vger.kernel.org
Cc: Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
Kees Cook <kees@kernel.org>,
"Gustavo A. R. Silva" <gustavoars@kernel.org>,
linux-kernel@vger.kernel.org (open list),
linux-hardening@vger.kernel.org (open list:KERNEL HARDENING (not
covered by other areas):Keyword:\b__counted_by(_le|_be)?\b)
Subject: [PATCH] ALSA: asihpi: Use flexible array for control cache
Date: Mon, 11 May 2026 16:01:21 -0700 [thread overview]
Message-ID: <20260511230121.28606-1-rosenp@gmail.com> (raw)
Store the ASIHPI control-cache lookup table in the control-cache
allocation instead of allocating it separately.
This keeps the lookup table tied to the cache object lifetime and
removes the extra allocation and free path.
Assisted-by: Codex:GPT-5.5
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
sound/pci/asihpi/hpicmn.c | 16 ++++------------
sound/pci/asihpi/hpicmn.h | 4 ++--
2 files changed, 6 insertions(+), 14 deletions(-)
diff --git a/sound/pci/asihpi/hpicmn.c b/sound/pci/asihpi/hpicmn.c
index d846777e7462..0674fd854cc8 100644
--- a/sound/pci/asihpi/hpicmn.c
+++ b/sound/pci/asihpi/hpicmn.c
@@ -641,17 +641,12 @@ void hpi_cmn_control_cache_sync_to_msg(struct hpi_control_cache *p_cache,
struct hpi_control_cache *hpi_alloc_control_cache(const u32 control_count,
const u32 size_in_bytes, u8 *p_dsp_control_buffer)
{
- struct hpi_control_cache *p_cache = kmalloc_obj(*p_cache);
+ struct hpi_control_cache *p_cache;
+
+ p_cache = kzalloc_flex(*p_cache, p_info, control_count);
if (!p_cache)
return NULL;
- p_cache->p_info =
- kzalloc_objs(*p_cache->p_info, control_count);
- if (!p_cache->p_info) {
- kfree(p_cache);
- return NULL;
- }
-
p_cache->cache_size_in_bytes = size_in_bytes;
p_cache->control_count = control_count;
p_cache->p_cache = p_dsp_control_buffer;
@@ -661,10 +656,7 @@ struct hpi_control_cache *hpi_alloc_control_cache(const u32 control_count,
void hpi_free_control_cache(struct hpi_control_cache *p_cache)
{
- if (p_cache) {
- kfree(p_cache->p_info);
- kfree(p_cache);
- }
+ kfree(p_cache);
}
static void subsys_message(struct hpi_message *phm, struct hpi_response *phr)
diff --git a/sound/pci/asihpi/hpicmn.h b/sound/pci/asihpi/hpicmn.h
index 8ec656cf8848..40af7329587a 100644
--- a/sound/pci/asihpi/hpicmn.h
+++ b/sound/pci/asihpi/hpicmn.h
@@ -37,10 +37,10 @@ struct hpi_control_cache {
u16 adap_idx;
u32 control_count;
u32 cache_size_in_bytes;
- /** pointer to allocated memory of lookup pointers. */
- struct hpi_control_cache_info **p_info;
/** pointer to DSP's control cache. */
u8 *p_cache;
+ /** pointer to allocated memory of lookup pointers. */
+ struct hpi_control_cache_info *p_info[] __counted_by(control_count);
};
struct hpi_adapter_obj *hpi_find_adapter(u16 adapter_index);
--
2.54.0
reply other threads:[~2026-05-11 23:01 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20260511230121.28606-1-rosenp@gmail.com \
--to=rosenp@gmail.com \
--cc=gustavoars@kernel.org \
--cc=kees@kernel.org \
--cc=linux-hardening@vger.kernel.org \
--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