media: venus: hfi_cmds: Replace fake flex-array with flexible-array member
authorGustavo A. R. Silva <gustavoars@kernel.org>
Wed, 17 May 2023 01:03:39 +0000 (02:03 +0100)
committerMauro Carvalho Chehab <mchehab@kernel.org>
Fri, 9 Jun 2023 12:43:18 +0000 (13:43 +0100)
commita0eadbe92610cfaa0f5d519778c0297564e6a3a2
treee7ea90b5920dbb9474a036c39747ae3c156103cd
parent927e78ac8bc58155316cf6f46026e1912bbbbcfc
media: venus: hfi_cmds: Replace fake flex-array with flexible-array member

One-element arrays are deprecated, and we are replacing them with flexible
array members instead. So, replace one-element arrays with flexible-array
members in struct hfi_sys_set_resource_pkt, 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].

The only binary differences seen before/after changes are the
following:

     17ba:      mov    %rbx,%rdi
     17bd:      call   17c2 <pkt_sys_set_resource+0x42>
                        17be: R_X86_64_PLT32    __tsan_write4-0x4
-    17c2:      movl   $0x14,(%rbx)
+    17c2:      movl   $0x10,(%rbx)
     17c8:      lea    0x4(%rbx),%rdi
     17cc:      call   17d1 <pkt_sys_set_resource+0x51>
                        17cd: R_X86_64_PLT32    __tsan_write4-0x4

which is expected once this accounts for the following line of code
at  drivers/media/platform/qcom/venus/hfi_cmds.c:73

73         pkt->hdr.size = sizeof(*pkt);

and as *pkt is of type struct hfi_sys_set_resource_pkt, sizeof(*pkt) is
reduced by 4 bytes, due to the flex-array transformation.

Link: https://github.com/KSPP/linux/issues/79
Link: https://github.com/KSPP/linux/issues/293
Link: https://gcc.gnu.org/pipermail/gcc-patches/2022-October/602902.html
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Signed-off-by: Stanimir Varbanov <stanimir.k.varbanov@gmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
drivers/media/platform/qcom/venus/hfi_cmds.c
drivers/media/platform/qcom/venus/hfi_cmds.h