[PATCH 1/2] firmware: cs_dsp: Resize members of cs_dsp_coeff_ctl to save bytes
From: Richard Fitzgerald
Date: Fri Nov 27 2026 - 06:41:15 EST
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@xxxxxxxxxxxxxxxxxxxxx>
---
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