/* SPDX-License-Identifier: GPL-2.0-only */ /* * Copyright 2021-2024 Cisco Systems, Inc. and/or its affiliates. All rights reserved. */ #ifndef _CEC_SPLITTER_H_ #define _CEC_SPLITTER_H_ struct cec_splitter; #define STATE_CHANGE_MAX_REPEATS 2 struct cec_splitter_port { struct cec_splitter *splitter; struct cec_adapter *adap; unsigned int port; bool is_active_source; bool found_sink; ktime_t lost_sink_ts; u32 out_request_current_latency_seq; ktime_t out_request_current_latency_ts; u8 video_latency; u32 out_give_device_power_status_seq; ktime_t out_give_device_power_status_ts; u8 power_status; }; struct cec_splitter { struct device *dev; unsigned int num_out_ports; struct cec_splitter_port **ports; /* High-level splitter state */ u8 request_current_latency_dest; u8 give_device_power_status_dest; bool is_standby; }; void cec_splitter_unconfigured_output(struct cec_splitter_port *port); void cec_splitter_configured_output(struct cec_splitter_port *port); int cec_splitter_received_input(struct cec_splitter_port *port, struct cec_msg *msg); int cec_splitter_received_output(struct cec_splitter_port *port, struct cec_msg *msg, struct cec_adapter *input_adap); void cec_splitter_nb_transmit_canceled_output(struct cec_splitter_port *port, const struct cec_msg *msg, struct cec_adapter *input_adap); bool cec_splitter_poll(struct cec_splitter *splitter, struct cec_adapter *input_adap, bool debug); #endif s issue was found with the help of Coccinelle. [1] https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html [2] https://github.com/KSPP/linux/issues/21 [3] commit 76497732932f ("cxgb3/l2t: Fix undefined behaviour") Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com> Signed-off-by: David S. Miller <davem@davemloft.net>
The current codebase makes use of the zero-length array language
extension to the C90 standard, but the preferred mechanism to declare
variable-length types such as these ones is a flexible array member[1][2],
introduced in C99:

struct foo {
        int stuff;
        struct boo array[];
};

By making use of the mechanism above, we will get a compiler warning
in case the flexible array does not occur last in the structure, which
will help us prevent some kind of undefined behavior bugs from being
inadvertently introduced[3] to the codebase from now on.

Also, notice that, dynamic memory allocations won't be affected by
this change:

"Flexible array members have incomplete type, and so the sizeof operator
may not be applied. As a quirk of the original implementation of
zero-length arrays, sizeof evaluates to zero."[1]

This issue was found with the help of Coccinelle.

[1] https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html
[2] https://github.com/KSPP/linux/issues/21
[3] commit 76497732932f ("cxgb3/l2t: Fix undefined behaviour")

Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
Signed-off-by: David S. Miller <davem@davemloft.net>