Skip to contentSkip to conversation

ASoC: SOF: Replace zero-length array with flexible-array member

PATCH In review Stephen Kitt 4 participants 4 messages Feb 17, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ASoC: SOF: Replace zero-length array with flexible-array member

There is a regular need in the kernel to provide a way to declare having a dynamically sized set of trailing elements in a structure. Kernel code should always use "flexible array members"[1] for these cases. The older style of one-element or zero-length arrays should no longer be used[2].

This helps with the ongoing efforts to globally enable -Warray-bounds and get us closer to being able to tighten the FORTIFY_SOURCE routines on memcpy().

[1] https://en.wikipedia.org/wiki/Flexible_array_member
[2] https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays

---
 include/sound/sof/topology.h | 2 +-
 sound/soc/sof/topology.c     | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
include/sound/sof/topology.h +1 -1
index d12736e14b69..adee6afd1490 100644
@@ -237,7 +237,7 @@ struct sof_ipc_comp_process {
 	/* reserved for future use */
 	uint32_t reserved[7];
 
-	uint8_t data[0];
+	uint8_t data[];
 } __packed;
 
 /* frees components, buffers and pipelines
sound/soc/sof/topology.c +1 -1
index e72dcae5e7ee..1d119d1dd69d 100644
@@ -2164,7 +2164,7 @@ static int sof_process_load(struct snd_soc_component *scomp, int index,
 	 */
 	if (ipc_data_size) {
 		for (i = 0; i < widget->num_kcontrols; i++) {
-			memcpy(&process->data + offset,
+			memcpy(&process->data[offset],
 			       wdata[i].pdata->data,
 			       wdata[i].pdata->size);
 			offset += wdata[i].pdata->size;

base-commit: f71077a4d84bbe8c7b91b7db7c4ef815755ac5e3

Signature · 1 line
2.27.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Stephen Kitt

There is a regular need in the kernel to provide a way to declare having a dynamically sized set of trailing elements in a structure. Kernel code should always use "flexible array members"[1] for these cases. The older style of one-element or zero-length arrays should no longer be used[2].

This helps with the ongoing efforts to globally enable -Warray-bounds and get us closer to being able to tighten the FORTIFY_SOURCE routines on memcpy().

Quoted 7 lines

[1] https://en.wikipedia.org/wiki/Flexible_array_member
[2] https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays

Thanks!
--
Gustavo

Quoted 36 lines
---
 include/sound/sof/topology.h | 2 +-
 sound/soc/sof/topology.c     | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
include/sound/sof/topology.h +1 -1
index d12736e14b69..adee6afd1490 100644
@@ -237,7 +237,7 @@ struct sof_ipc_comp_process {
 	/* reserved for future use */
 	uint32_t reserved[7];
 
-	uint8_t data[0];
+	uint8_t data[];
 } __packed;
 
 /* frees components, buffers and pipelines
sound/soc/sof/topology.c +1 -1
index e72dcae5e7ee..1d119d1dd69d 100644
@@ -2164,7 +2164,7 @@ static int sof_process_load(struct snd_soc_component *scomp, int index,
 	 */
 	if (ipc_data_size) {
 		for (i = 0; i < widget->num_kcontrols; i++) {
-			memcpy(&process->data + offset,
+			memcpy(&process->data[offset],
 			       wdata[i].pdata->data,
 			       wdata[i].pdata->size);
 			offset += wdata[i].pdata->size;

base-commit: f71077a4d84bbe8c7b91b7db7c4ef815755ac5e3

Signature · 1 line
2.27.0
#2 lore raw
Quoted 13 lines · Gustavo A. R. Silva
Quoted 12 lines · Stephen Kitt

There is a regular need in the kernel to provide a way to declare having a dynamically sized set of trailing elements in a structure. Kernel code should always use "flexible array members"[1] for these cases. The older style of one-element or zero-length arrays should no longer be used[2].

This helps with the ongoing efforts to globally enable -Warray-bounds and get us closer to being able to tighten the FORTIFY_SOURCE routines on memcpy().

[1] https://en.wikipedia.org/wiki/Flexible_array_member
[2] https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays

Quoted 6 lines
Quoted 4 lines

Thanks for the patch

I just realized we have additional cases in this directory (interface between kernel and firmware), I'll send a follow-up patch a

channel_map.h:  int32_t ch_coeffs[0];
channel_map.h:  struct sof_ipc_channel_map ch_map[0];
control.h:              struct sof_ipc_ctrl_value_chan chanv[0];
control.h:              struct sof_ipc_ctrl_value_comp compv[0];
control.h:              struct sof_abi_hdr data[0];
control.h:              struct sof_abi_hdr data[0];
Quoted 41 lines

Thanks!
--
Gustavo

Quoted 36 lines
---
 include/sound/sof/topology.h | 2 +-
 sound/soc/sof/topology.c     | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
include/sound/sof/topology.h +1 -1
index d12736e14b69..adee6afd1490 100644
@@ -237,7 +237,7 @@ struct sof_ipc_comp_process {
 	/* reserved for future use */
 	uint32_t reserved[7];
 
-	uint8_t data[0];
+	uint8_t data[];
 } __packed;
 
 /* frees components, buffers and pipelines
sound/soc/sof/topology.c +1 -1
index e72dcae5e7ee..1d119d1dd69d 100644
@@ -2164,7 +2164,7 @@ static int sof_process_load(struct snd_soc_component *scomp, int index,
 	 */
 	if (ipc_data_size) {
 		for (i = 0; i < widget->num_kcontrols; i++) {
-			memcpy(&process->data + offset,
+			memcpy(&process->data[offset],
 			       wdata[i].pdata->data,
 			       wdata[i].pdata->size);
 			offset += wdata[i].pdata->size;

base-commit: f71077a4d84bbe8c7b91b7db7c4ef815755ac5e3

Signature · 1 line
2.27.0
maintainer
#3 lore raw
In reply to Stephen Kitt
Quoted 10 lines · Stephen Kitt

There is a regular need in the kernel to provide a way to declare having a dynamically sized set of trailing elements in a structure. Kernel code should always use "flexible array members"[1] for these cases. The older style of one-element or zero-length arrays should no longer be used[2].

This helps with the ongoing efforts to globally enable -Warray-bounds and get us closer to being able to tighten the FORTIFY_SOURCE routines on memcpy().

[...]

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

Thanks!

[1/1] ASoC: SOF: Replace zero-length array with flexible-array member

      commit: 4fe6a63077a6d3c143d68f6b96e4051f1d0740ac

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark