ALSA: mixart: Replace one-element arrays with simple object declarations
PATCH v2 1/1 ALSA: mixart: Replace one-element arrays with simple object declarations
One-element arrays are deprecated, and we are replacing them with flexible array members instead. However, in this case it seems those one-element arrays have never actually been used as fake flexible arrays.
See this code that dates from Linux-2.6.12-rc2 initial git repository build (commit 1da177e4c3f4 ("Linux-2.6.12-rc2")):
sound/pci/mixart/mixart_core.h:
215 struct mixart_stream_state_req
216 {
217 u32 delayed; 218 u64 scheduler; 219 u32 reserved4np[3]; 220 u32 stream_count; /* set to 1 for instance */ 221 struct mixart_flow_info stream_info; /* could be an array[stream_count] */
222 } __attribute__((packed));
sound/pci/mixart/mixart.c:
388
389 memset(&stream_state_req, 0, sizeof(stream_state_req)); 390 stream_state_req.stream_count = 1; 391 stream_state_req.stream_info.stream_desc.uid_pipe = stream->pipe->group_uid; 392 stream_state_req.stream_info.stream_desc.stream_idx = stream->substream->number;
393
So, taking the code above as example, replace multiple one-element arrays with simple object declarations, and refactor the rest of the code, accordingly.
This helps with the ongoing efforts to tighten the FORTIFY_SOURCE routines on memcpy() and help us make progress towards globally enabling -fstrict-flex-arrays=3 [1].
This results in no differences in binary output.
---
Changes in v2:
- Keep the code comments (by Takashi Iwai) and explicitly mention that the objects could be arrays, in theory.
v1:
- Link: https://lore.kernel.org/linux-hardening/ZGVlcpuvx1rSOMP8@work/
sound/pci/mixart/mixart.c | 8 ++++---- sound/pci/mixart/mixart_core.h | 7 +++---- 2 files changed, 7 insertions(+), 8 deletions(-)
sound/pci/mixart/mixart.c +4 -4
@@ -98,7 +98,7 @@ static int mixart_set_pipe_state(struct mixart_mgr *mgr,memset (&group_state,0 ,sizeof (group_state)); group_state.pipe_count =1 ; - group_state.pipe_uid[0 ] = pipe->group_uid; + group_state.pipe_uid = pipe->group_uid;if (start) request.message_id =MSG_STREAM_START_STREAM_GRP_PACKET ;
@@ -185,7 +185,7 @@ static int mixart_set_clock(struct mixart_mgr *mgr, clock_properties.clock_mode =CM_STANDALONE ; clock_properties.frequency = rate; clock_properties.nb_callers =1 ;/* only one entry in uid_caller ! */ - clock_properties.uid_caller[0 ] = pipe->group_uid; + clock_properties.uid_caller = pipe->group_uid;dev_dbg (&mgr->pci->dev,"mixart_set_clock to %d kHz\n" , rate);
@@ -565,8 +565,8 @@ static int mixart_set_format(struct mixart_stream *stream, snd_pcm_format_t form stream_param.pipe_count =1 ;/* set to 1 */ stream_param.stream_count =1 ;/* set to 1 */ - stream_param.stream_desc[0 ].uid_pipe = stream->pipe->group_uid; - stream_param.stream_desc[0 ].stream_idx = stream->substream->number; + stream_param.stream_desc.uid_pipe = stream->pipe->group_uid; + stream_param.stream_desc.stream_idx = stream->substream->number; request.message_id =MSG_STREAM_SET_INPUT_STAGE_PARAM ; request.uid = (struct mixart_uid ){0 ,0 };
sound/pci/mixart/mixart_core.h +3 -4
@@ -231,7 +231,7 @@ struct mixart_group_state_requ64 scheduler;u32 reserved4np[2 ];u32 pipe_count;/* set to 1 for instance */ -struct mixart_uid pipe_uid[1 ];/* could be an array[pipe_count] */ +struct mixart_uid pipe_uid;/* could be an array[pipe_count], in theory */ } __attribute__((packed));struct mixart_group_state_resp
@@ -314,7 +314,7 @@ struct mixart_clock_propertiesu32 format;u32 board_mask;u32 nb_callers;/* set to 1 (see below) */ -struct mixart_uid uid_caller[1 ]; +struct mixart_uid uid_caller; } __attribute__((packed));struct mixart_clock_properties_resp
@@ -401,8 +401,7 @@ struct mixart_stream_param_descu32 reserved4np[3 ];u32 pipe_count;/* set to 1 (array size !) */ u32 stream_count;/* set to 1 (array size !) */ -struct mixart_txx_stream_desc stream_desc[1 ];/* only one stream per command, but this could be an array */ - +struct mixart_txx_stream_desc stream_desc;/* only one stream per command, but this could be an array, in theory */ } __attribute__((packed));
Signature · 1 line
2.34.1
Takashi Iwai
AppliedQuoted 34 lines · Gustavo A. R. Silva
One-element arrays are deprecated, and we are replacing them with flexible array members instead. However, in this case it seems those one-element arrays have never actually been used as fake flexible arrays.
See this code that dates from Linux-2.6.12-rc2 initial git repository build (commit
1da177e4c3f4("Linux-2.6.12-rc2")):
sound/pci/mixart/mixart_core.h:
215 structmixart_stream_state_req
216 {217 u32 delayed; 218 u64 scheduler; 219 u32 reserved4np[3]; 220 u32 stream_count; /* set to 1 for instance */ 221 struct mixart_flow_info stream_info; /* could be an array[stream_count] */222 } __attribute__((packed));
sound/pci/mixart/mixart.c:
388389 memset(&stream_state_req, 0, sizeof(stream_state_req)); 390 stream_state_req.stream_count = 1; 391 stream_state_req.stream_info.stream_desc.uid_pipe = stream->pipe->group_uid; 392 stream_state_req.stream_info.stream_desc.stream_idx = stream->substream->number;393
So, taking the code above as example, replace multiple one-element arrays with simple object declarations, and refactor the rest of the code, accordingly.
This helps with the ongoing efforts to tighten the
FORTIFY_SOURCEroutines onmemcpy()and help us make progress towards globally enabling -fstrict-flex-arrays=3 [1].
Quoted 6 lines
This results in no differences in binary output.
Thanks, applied.
Takashi