mux: Convert mux_control_ops to a flex array member in mux_chip
authorThorsten Blum <thorsten.blum@linux.dev>
Tue, 10 Jun 2025 10:40:59 +0000 (12:40 +0200)
committerKees Cook <kees@kernel.org>
Wed, 18 Jun 2025 21:20:32 +0000 (14:20 -0700)
commit4bfbc2691de8c869339090e851703209b17ba378
treeef06a674df6c4fb642331c2f137315e1de5460e8
parente04c78d86a9699d136910cfc0bdcf01087e3267e
mux: Convert mux_control_ops to a flex array member in mux_chip

Convert mux_control_ops to a flexible array member at the end of the
mux_chip struct and add the __counted_by() compiler attribute to
improve access bounds-checking via CONFIG_UBSAN_BOUNDS and
CONFIG_FORTIFY_SOURCE.

Use struct_size() to calculate the number of bytes to allocate for a new
mux chip and to remove the following Coccinelle/coccicheck warning:

  WARNING: Use struct_size

Use size_add() to safely add any extra bytes.

No functional changes intended.

Link: https://github.com/KSPP/linux/issues/83
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
Link: https://lore.kernel.org/r/20250610104106.1948-2-thorsten.blum@linux.dev
Signed-off-by: Kees Cook <kees@kernel.org>
drivers/mux/core.c
include/linux/mux/driver.h