ASoC: codecs: Use sizeof(struct) for aw_container allocation
PATCH 1/1 ASoC: codecs: Use sizeof(struct) for aw_container allocation
From: wangdicheng <[email protected]>
The aw88395 driver and its variants (aw88081, aw88261) use sizeof(int) when allocating memory for struct aw_container. This should use sizeof(struct aw_container) instead for proper type safety and portability.
While sizeof(int) and sizeof(struct aw_container) may have the same size on most platforms (both are typically 4 bytes), using the proper struct size is the correct approach according to kernel coding style for structures with flexible array members.
The standard pattern for allocating such structures is:
sizeof(struct) + flexible_array_size
--- sound/soc/codecs/aw88081.c | 4 +++- sound/soc/codecs/aw88261.c | 4 +++- sound/soc/codecs/aw88395/aw88395.c | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-)
sound/soc/codecs/aw88081.c +3 -1
@@ -1148,7 +1148,9 @@ static int aw88081_request_firmware_file(struct aw88081 *aw88081)dev_dbg (aw88081->aw_pa->dev,"loaded %s - size: %zu\n" ,AW88081_ACF_FILE , cont ? cont->size :0 ); - aw88081->aw_cfg =devm_kzalloc (aw88081->aw_pa->dev, cont->size +sizeof (int ),GFP_KERNEL ); + aw88081->aw_cfg =devm_kzalloc (aw88081->aw_pa->dev, +sizeof (struct aw_container ) + cont->size, +GFP_KERNEL );if (!aw88081->aw_cfg) {release_firmware (cont);return -ENOMEM ;
sound/soc/codecs/aw88261.c +3 -1
@@ -1111,7 +1111,9 @@ static int aw88261_request_firmware_file(struct aw88261 *aw88261)dev_info (aw88261->aw_pa->dev,"loaded %s - size: %zu\n" , fw_name, cont ? cont->size :0 ); - aw88261->aw_cfg =devm_kzalloc (aw88261->aw_pa->dev, cont->size +sizeof (int ),GFP_KERNEL ); + aw88261->aw_cfg =devm_kzalloc (aw88261->aw_pa->dev, +sizeof (struct aw_container ) + cont->size, +GFP_KERNEL );if (!aw88261->aw_cfg) {release_firmware (cont);return -ENOMEM ;
sound/soc/codecs/aw88395/aw88395.c +3 -1
@@ -475,7 +475,9 @@ static int aw88395_request_firmware_file(struct aw88395 *aw88395)dev_info (aw88395->aw_pa->dev,"loaded %s - size: %zu\n" ,AW88395_ACF_FILE , cont ? cont->size :0 ); - aw88395->aw_cfg =devm_kzalloc (aw88395->aw_pa->dev, cont->size +sizeof (int ),GFP_KERNEL ); + aw88395->aw_cfg =devm_kzalloc (aw88395->aw_pa->dev, +sizeof (struct aw_container ) + cont->size, +GFP_KERNEL );if (!aw88395->aw_cfg) {release_firmware (cont);return -ENOMEM ;
Signature · 1 line
2.25.1
Mark Brown
maintainersound/soc/codecs/aw88081.c static int aw88081_request_firmware_file(struct aw88081 *aw88081) · line 1153
Quoted 4 lines · On Mon, Jun 01, 2026 at 03:25:53PM +0800, [email protected] wrote:
sound/soc/codecs/aw88081.c +3
-1- aw88081->aw_cfg =devm_kzalloc (aw88081->aw_pa->dev, cont->size +sizeof (int ),GFP_KERNEL ); + aw88081->aw_cfg =devm_kzalloc (aw88081->aw_pa->dev, +sizeof (struct aw_container ) + cont->size, +GFP_KERNEL );
We have a bunch of helper macros like struct_size() for this stuff.