linux-stable/include/uapi/linux/stm.h
Gustavo A. R. Silva 94dfc73e7c 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>
2022-06-28 21:26:05 +02:00

46 lines
1.3 KiB
C

/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
/*
* System Trace Module (STM) userspace interfaces
* Copyright (c) 2014, Intel Corporation.
*
* STM class implements generic infrastructure for System Trace Module devices
* as defined in MIPI STPv2 specification.
*/
#ifndef _UAPI_LINUX_STM_H
#define _UAPI_LINUX_STM_H
#include <linux/types.h>
/* Maximum allowed master and channel values */
#define STP_MASTER_MAX 0xffff
#define STP_CHANNEL_MAX 0xffff
/**
* struct stp_policy_id - identification for the STP policy
* @size: size of the structure including real id[] length
* @master: assigned master
* @channel: first assigned channel
* @width: number of requested channels
* @id: identification string
*
* User must calculate the total size of the structure and put it into
* @size field, fill out the @id and desired @width. In return, kernel
* fills out @master, @channel and @width.
*/
struct stp_policy_id {
__u32 size;
__u16 master;
__u16 channel;
__u16 width;
/* padding */
__u16 __reserved_0;
__u32 __reserved_1;
char id[];
};
#define STP_POLICY_ID_SET _IOWR('%', 0, struct stp_policy_id)
#define STP_POLICY_ID_GET _IOR('%', 1, struct stp_policy_id)
#define STP_SET_OPTIONS _IOW('%', 2, __u64)
#endif /* _UAPI_LINUX_STM_H */