Thread (6 messages) 6 messages, 4 authors, 2019-04-20

Re: [PATCH 1/2] include: linux: Regularise the use of FIELD_SIZEOF macro

From: Shyam Saini <hidden>
Date: 2019-04-20 10:51:16
Also in: bpf, dri-devel, intel-gfx, kvm, linux-arm-kernel, linux-ext4, linux-mips, linux-mm, linux-sctp, lkml

Hi William,

Sorry for the late reply.
quoted
Currently, there are 3 different macros, namely sizeof_field, SIZEOF_FIELD
and FIELD_SIZEOF which are used to calculate the size of a member of
structure, so to bring uniformity in entire kernel source tree lets use
FIELD_SIZEOF and replace all occurrences of other two macros with this.

For this purpose, redefine FIELD_SIZEOF in include/linux/stddef.h and
tools/testing/selftests/bpf/bpf_util.h and remove its defination from
include/linux/kernel.h
quoted
--- a/include/linux/stddef.h
+++ b/include/linux/stddef.h
@@ -20,6 +20,15 @@ enum {
#endif

/**
+ * FIELD_SIZEOF - get the size of a struct's field
+ * @t: the target struct
+ * @f: the target struct's field
+ * Return: the size of @f in the struct definition without having a
+ * declared instance of @t.
+ */
+#define FIELD_SIZEOF(t, f) (sizeof(((t *)0)->f))
+
+/**
 * sizeof_field(TYPE, MEMBER)
 *
 * @TYPE: The structure containing the field of interest
@@ -34,6 +43,6 @@ enum {
 * @MEMBER: The member within the structure to get the end offset of
 */
#define offsetofend(TYPE, MEMBER) \
-     (offsetof(TYPE, MEMBER) + sizeof_field(TYPE, MEMBER))
+     (offsetof(TYPE, MEMBER) + FIELD_SIZEOF(TYPE, MEMBER))
If you're doing this, why are you leaving the definition of sizeof_field() in
stddef.h untouched?
I have removed definition of sizeof_field in [1/2] patch.
Given the way this has worked historically, if you are leaving it in place for
source compatibility reasons, shouldn't it be redefined in terms of
FIELD_SIZEOF(), e.g.:

#define sizeof_field(TYPE, MEMBER) FIELD_SIZEOF(TYPE, MEMBER)
Actually, never thought this way. So,Thanks a lot for this valuable feedback.

I'll re-spin and post again.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help