From: Richard Fitzgerald <rf@opensource.cirrus.com>
To: broonie@kernel.org
Cc: linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org,
patches@opensource.cirrus.com
Subject: [PATCH 1/2] firmware: cs_dsp: Resize members of cs_dsp_coeff_ctl to save bytes
Date: Fri, 27 Nov 2026 11:40:36 +0000 [thread overview]
Message-ID: <20261127114037.2010271-2-rf@opensource.cirrus.com> (raw)
In-Reply-To: <20261127114037.2010271-1-rf@opensource.cirrus.com>
Reduce the size of some members in struct cs_dsp_coeff_ctl to the size of
the data they are storing. On an x86_64 build this saves 8 bytes per
control.
- The subname_len string can never be more than 16-bits. In V0 and V1
firmwares it is a 256-character array, and in later firmwares it is an
8-bit field. (In any case it is impractical to have a control name
>65535 characters long.)
- Control type and flags are 16-bit values in the firmware.
- Type is relocated adjacent to subname_len to avoid introducing
alignment padding bytes after subname_len
The ctl_type and flags fields in struct cs_dsp_coeff_parsed_coeff have
been changed to match these widths.
The arguments to cs_dsp_create_control() have been changed to the same
types so that consistent widths are used.
Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
---
drivers/firmware/cirrus/cs_dsp.c | 15 +++++++++------
include/linux/firmware/cirrus/cs_dsp.h | 8 ++++----
2 files changed, 13 insertions(+), 10 deletions(-)
diff --git a/drivers/firmware/cirrus/cs_dsp.c b/drivers/firmware/cirrus/cs_dsp.c
index abf9196db883..b9e4b9283df1 100644
--- a/drivers/firmware/cirrus/cs_dsp.c
+++ b/drivers/firmware/cirrus/cs_dsp.c
@@ -1044,8 +1044,8 @@ static void cs_dsp_free_ctl_blk(struct cs_dsp_coeff_ctl *ctl)
static int cs_dsp_create_control(struct cs_dsp *dsp,
const struct cs_dsp_alg_region *alg_region,
unsigned int offset, unsigned int len,
- const char *subname, unsigned int subname_len,
- unsigned int flags, unsigned int type)
+ const char *subname, u16 subname_len,
+ u16 flags, u16 type)
{
struct cs_dsp_coeff_ctl *ctl;
int ret;
@@ -1162,9 +1162,9 @@ struct cs_dsp_coeff_parsed_coeff {
int offset;
int mem_type;
const u8 *name;
- int name_len;
- unsigned int ctl_type;
- int flags;
+ u16 name_len;
+ u16 ctl_type;
+ u16 flags;
int len;
};
@@ -1312,6 +1312,9 @@ static int cs_dsp_coeff_parse_coeff(struct cs_dsp *dsp,
blk->offset = le16_to_cpu(raw->hdr.offset);
blk->mem_type = le16_to_cpu(raw->hdr.type);
+ static_assert(sizeof(blk->ctl_type) >= sizeof(raw->ctl_type));
+ static_assert(sizeof(blk->flags) >= sizeof(raw->flags));
+
switch (dsp->wmfw_ver) {
case 0:
case 1:
@@ -1319,7 +1322,7 @@ static int cs_dsp_coeff_parse_coeff(struct cs_dsp *dsp,
return -EOVERFLOW;
blk->name = raw->name;
- blk->name_len = strnlen(raw->name, ARRAY_SIZE(raw->name));
+ blk->name_len = (u16)strnlen(raw->name, ARRAY_SIZE(raw->name));
blk->ctl_type = le16_to_cpu(raw->ctl_type);
blk->flags = le16_to_cpu(raw->flags);
blk->len = le32_to_cpu(raw->len);
diff --git a/include/linux/firmware/cirrus/cs_dsp.h b/include/linux/firmware/cirrus/cs_dsp.h
index 6aa1e1b2b4a5..16542bdce5c4 100644
--- a/include/linux/firmware/cirrus/cs_dsp.h
+++ b/include/linux/firmware/cirrus/cs_dsp.h
@@ -84,9 +84,9 @@ struct cs_dsp_alg_region {
* @fw_name: Name of the firmware
* @subname: Name of the control parsed from the WMFW
* @subname_len: Length of subname
+ * @type: One of the WMFW_CTL_TYPE_ control types defined in wmfw.h
* @offset: Offset of control within alg_region in words
* @len: Length of the cached value in bytes
- * @type: One of the WMFW_CTL_TYPE_ control types defined in wmfw.h
* @flags: Bitfield of WMFW_CTL_FLAG_ control flags defined in wmfw.h
* @set: Flag indicating the value has been written by the user
* @enabled: Flag indicating whether control is enabled
@@ -100,11 +100,11 @@ struct cs_dsp_coeff_ctl {
const char *fw_name;
/* Subname is needed to match with firmware */
const char *subname;
- unsigned int subname_len;
+ u16 subname_len;
+ u16 type;
unsigned int offset;
unsigned int len;
- unsigned int type;
- unsigned int flags;
+ u16 flags;
unsigned int set:1;
unsigned int enabled:1;
struct cs_dsp_alg_region alg_region;
--
2.47.3
next prev parent reply other threads:[~2026-11-27 11:41 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 11:40 [PATCH 0/2] firmware: cs_dsp: Remove some more wasted bytes per control Richard Fitzgerald
2026-11-27 11:40 ` Richard Fitzgerald [this message]
2026-11-27 11:40 ` [PATCH 2/2] firmware: cs_dsp: Store control cache data in struct cs_dsp_coeff_ctl Richard Fitzgerald
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=20261127114037.2010271-2-rf@opensource.cirrus.com \
--to=rf@opensource.cirrus.com \
--cc=broonie@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=patches@opensource.cirrus.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