linux/drivers/rpmsg
Gustavo A. R. Silva c1ddb29709 rpmsg: glink: Avoid -Wflex-array-member-not-at-end warnings
-Wflex-array-member-not-at-end was introduced in GCC-14, and we are
getting ready to enable it, globally.

So, in order to avoid ending up with a flexible-array member in the
middle of multiple other structs, we use the `__struct_group()`
helper to create a new tagged `struct glink_msg_hdr`. This structure
groups together all the members of the flexible `struct glink_msg`
except the flexible array.

As a result, the array is effectively separated from the rest of the
members without modifying the memory layout of the flexible structure.
We then change the type of the middle struct members currently causing
trouble from `struct glink_msg` to `struct glink_msg_hdr`.

We also want to ensure that when new members need to be added to the
flexible structure, they are always included within the newly created
tagged struct. For this, we use `static_assert()`. This ensures that the
memory layout for both the flexible structure and the new tagged struct
is the same after any changes.

This approach avoids having to implement `struct glink_msg_hdr` as a
completely separate structure, thus preventing having to maintain two
independent but basically identical structures, closing the door to
potential bugs in the future.

We also use `container_of()` whenever we need to retrieve a pointer to
the flexible structure, through which we can access the flexible-array
member, if necessary.

Additionally, we use the `DEFINE_RAW_FLEX()` helper for an on-stack
definition of a flexible structure where the size for the flexible-array
member is known at compile-time.

So, with these changes, fix the following warnings:
drivers/rpmsg/qcom_glink_native.c:51:26: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
drivers/rpmsg/qcom_glink_native.c:459:34: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
drivers/rpmsg/qcom_glink_native.c:846:34: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
drivers/rpmsg/qcom_glink_native.c:968:34: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
drivers/rpmsg/qcom_glink_native.c:1380:34: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]

Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Reviewed-by: Kees Cook <kees@kernel.org>
Link: https://lore.kernel.org/r/ZrOQa2gew5yadyt3@cute
Signed-off-by: Bjorn Andersson <andersson@kernel.org>
2024-09-13 14:09:47 -07:00
..
Kconfig rpmsg: Move the rpmsg control device from rpmsg_char to rpmsg_ctrl 2022-03-13 11:49:53 -05:00
Makefile rpmsg: glink: Introduce packet tracepoints 2024-08-12 15:26:28 -07:00
mtk_rpmsg.c rpmsg: mtk_rpmsg: Fix circular locking dependency 2022-06-14 16:41:10 -06:00
qcom_glink_native.c rpmsg: glink: Avoid -Wflex-array-member-not-at-end warnings 2024-09-13 14:09:47 -07:00
qcom_glink_native.h rpmsg: glink: Fix spelling of peek 2023-02-14 20:28:48 -08:00
qcom_glink_rpm.c rpmsg: qcom_glink_rpm: Convert to platform remove callback returning void 2023-04-05 20:58:32 -07:00
qcom_glink_smem.c rpmsg: glink: Fix spelling of peek 2023-02-14 20:28:48 -08:00
qcom_glink_ssr.c rpmsg: qcom_glink_ssr: fix module autoloading 2024-05-06 19:26:28 -07:00
qcom_glink_trace.h rpmsg: glink: Introduce packet tracepoints 2024-08-12 15:26:28 -07:00
qcom_smd.c rpmsg: qcom_smd: Use qcom_smem_is_available() 2023-07-13 22:18:56 -07:00
rpmsg_char.c rpmsg: char: add missing MODULE_DESCRIPTION() macro 2024-06-10 11:11:59 -06:00
rpmsg_char.h rpmsg: char: Export eptdev create and destroy functions 2022-03-13 11:49:53 -05:00
rpmsg_core.c driver core: have match() callback in struct bus_type take a const * 2024-07-03 15:16:54 +02:00
rpmsg_ctrl.c rpmsg: core: Make rpmsg_class constant 2024-03-26 11:25:13 -06:00
rpmsg_internal.h driver core: have match() callback in struct bus_type take a const * 2024-07-03 15:16:54 +02:00
rpmsg_ns.c rpmsg: Replace deprecated strncpy with strscpy_pad 2023-10-23 11:57:57 -06:00
virtio_rpmsg_bus.c virtio: rename virtio_find_vqs_info() to virtio_find_vqs() 2024-07-17 05:20:58 -04:00