mirror of
https://github.com/torvalds/linux.git
synced 2026-09-24 06:24:02 +02:00
The same macros are redefined in three places, so move them to a common file to reduce duplication and make it easier to reuse them. Signed-off-by: Alexandru Dadu <alexandru.dadu@imgtec.com> Co-developed-by: Alessio Belle <alessio.belle@imgtec.com> Reviewed-by: Brajesh Gupta <brajesh.gupta@imgtec.com> Link: https://patch.msgid.link/20260729-fwif-checks-updates-v1-1-af65e9606a7e@imgtec.com Signed-off-by: Alessio Belle <alessio.belle@imgtec.com>
37 lines
1.3 KiB
C
37 lines
1.3 KiB
C
/* SPDX-License-Identifier: GPL-2.0-only OR MIT */
|
|
/* Copyright (c) 2026 Imagination Technologies Ltd. */
|
|
|
|
#ifndef PVR_CHECK_H
|
|
#define PVR_CHECK_H
|
|
|
|
#include <linux/build_bug.h>
|
|
#include <linux/overflow.h>
|
|
#include <linux/stddef.h>
|
|
|
|
#define OFFSET_CHECK(type, member, offset) \
|
|
static_assert(offsetof(type, member) == (offset), \
|
|
"offsetof(" #type ", " #member ") incorrect")
|
|
|
|
#define SIZE_CHECK(type, size) \
|
|
static_assert(sizeof(type) == (size), #type " is incorrect size")
|
|
|
|
#define ALIGN_CHECK(type, align) \
|
|
static_assert(__alignof__(type) <= (align), #type " has incorrect alignment")
|
|
|
|
/*
|
|
* Where the last member of a struct is a flexible array member, using
|
|
* SIZE_CHECK() is pointless. If the structure is not already padded to
|
|
* alignment without the flexible array member, sizeof() will not match the
|
|
* offset of the flexible array member and the "correct" sizeof() value is
|
|
* completely meaningless.
|
|
*
|
|
* In those instances, use FLEX_ARRAY_CHECK() instead to assert that the final
|
|
* field is a flexible array member and that it behaves as expected.
|
|
*/
|
|
#define FLEX_ARRAY_CHECK(type, member) \
|
|
static_assert(flex_array_size((type *)NULL, member, 1) == \
|
|
sizeof_field(type, member[0]), \
|
|
#type "->" #member " is incorrect size")
|
|
|
|
#endif /* PVR_CHECK_H */
|