]> git.baikalelectronics.ru Git - kernel.git/commit
treewide: uapi: Replace zero-length arrays with flexible-array members
authorGustavo A. R. Silva <gustavoars@kernel.org>
Thu, 7 Apr 2022 00:36:51 +0000 (19:36 -0500)
committerGustavo A. R. Silva <gustavoars@kernel.org>
Tue, 28 Jun 2022 19:26:05 +0000 (21:26 +0200)
commita561a5a8bb708c63fff2210113d375e5905d5f68
treef561e2f6e3688a968357f0f9c98551321a44b982
parent71374b58ebc7666369d670c06d1176f81c437c59
treewide: uapi: Replace zero-length arrays with flexible-array members

There is a regular need in the kernel to provide a way to declare
having a dynamically sized set of trailing elements in a structure.
Kernel code should always use “flexible array members”[1] for these
cases. The older style of one-element or zero-length arrays should
no longer be used[2].

This code was transformed with the help of Coccinelle:
(linux-5.19-rc2$ spatch --jobs $(getconf _NPROCESSORS_ONLN) --sp-file script.cocci --include-headers --dir . > output.patch)

@@
identifier S, member, array;
type T1, T2;
@@

struct S {
  ...
  T1 member;
  T2 array[
- 0
  ];
};

-fstrict-flex-arrays=3 is coming and we need to land these changes
to prevent issues like these in the short future:

../fs/minix/dir.c:337:3: warning: 'strcpy' will always overflow; destination buffer has size 0,
but the source string has length 2 (including NUL byte) [-Wfortify-source]
strcpy(de3->name, ".");
^

Since these are all [0] to [] changes, the risk to UAPI is nearly zero. If
this breaks anything, we can use a union with a new member name.

[1] https://en.wikipedia.org/wiki/Flexible_array_member
[2] https://www.kernel.org/doc/html/v5.16/process/deprecated.html#zero-length-and-one-element-arrays

Link: https://github.com/KSPP/linux/issues/78
Build-tested-by: kernel test robot <lkp@intel.com>
Link: https://lore.kernel.org/lkml/62b675ec.wKX6AOZ6cbE71vtF%25lkp@intel.com/
Acked-by: Dan Williams <dan.j.williams@intel.com> # For ndctl.h
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
82 files changed:
arch/m68k/include/uapi/asm/bootinfo.h
arch/mips/include/uapi/asm/ucontext.h
arch/s390/include/uapi/asm/hwctrset.h
arch/x86/include/uapi/asm/bootparam.h
arch/x86/include/uapi/asm/kvm.h
include/uapi/drm/i915_drm.h
include/uapi/linux/blkzoned.h
include/uapi/linux/bpf.h
include/uapi/linux/btrfs.h
include/uapi/linux/btrfs_tree.h
include/uapi/linux/can/bcm.h
include/uapi/linux/connector.h
include/uapi/linux/cycx_cfm.h
include/uapi/linux/dm-ioctl.h
include/uapi/linux/dm-log-userspace.h
include/uapi/linux/ethtool.h
include/uapi/linux/fanotify.h
include/uapi/linux/fiemap.h
include/uapi/linux/firewire-cdev.h
include/uapi/linux/fs.h
include/uapi/linux/if_alg.h
include/uapi/linux/if_arcnet.h
include/uapi/linux/if_pppox.h
include/uapi/linux/if_tun.h
include/uapi/linux/igmp.h
include/uapi/linux/inet_diag.h
include/uapi/linux/inotify.h
include/uapi/linux/ip.h
include/uapi/linux/ip_vs.h
include/uapi/linux/iso_fs.h
include/uapi/linux/jffs2.h
include/uapi/linux/kcov.h
include/uapi/linux/kvm.h
include/uapi/linux/minix_fs.h
include/uapi/linux/mmc/ioctl.h
include/uapi/linux/ndctl.h
include/uapi/linux/net_dropmon.h
include/uapi/linux/netfilter/x_tables.h
include/uapi/linux/netfilter_arp/arp_tables.h
include/uapi/linux/netfilter_bridge/ebt_among.h
include/uapi/linux/netfilter_ipv4/ip_tables.h
include/uapi/linux/netfilter_ipv6/ip6_tables.h
include/uapi/linux/perf_event.h
include/uapi/linux/pkt_cls.h
include/uapi/linux/raid/md_p.h
include/uapi/linux/random.h
include/uapi/linux/romfs_fs.h
include/uapi/linux/rtnetlink.h
include/uapi/linux/sctp.h
include/uapi/linux/seg6.h
include/uapi/linux/seg6_iptunnel.h
include/uapi/linux/stm.h
include/uapi/linux/target_core_user.h
include/uapi/linux/usb/audio.h
include/uapi/linux/usb/cdc.h
include/uapi/linux/usb/ch9.h
include/uapi/linux/usb/raw_gadget.h
include/uapi/linux/usbdevice_fs.h
include/uapi/linux/vhost_types.h
include/uapi/linux/virtio_9p.h
include/uapi/linux/xfrm.h
include/uapi/rdma/hfi/hfi1_user.h
include/uapi/rdma/ib_user_verbs.h
include/uapi/rdma/rdma_user_cm.h
include/uapi/rdma/rdma_user_ioctl_cmds.h
include/uapi/scsi/fc/fc_els.h
include/uapi/scsi/scsi_bsg_fc.h
include/uapi/sound/asound.h
include/uapi/sound/firewire.h
include/uapi/sound/skl-tplg-interface.h
include/uapi/sound/sof/header.h
include/uapi/sound/usb_stream.h
tools/arch/x86/include/uapi/asm/kvm.h
tools/include/uapi/drm/i915_drm.h
tools/include/uapi/linux/fs.h
tools/include/uapi/linux/if_tun.h
tools/include/uapi/linux/kvm.h
tools/include/uapi/linux/perf_event.h
tools/include/uapi/linux/pkt_cls.h
tools/include/uapi/linux/seg6.h
tools/include/uapi/linux/usbdevice_fs.h
tools/include/uapi/sound/asound.h