b.a.t.m.a.n.lists.open-mesh.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] batman-adv: Replace FIELD_SIZEOF with sizeof_field
@ 2019-12-11  8:52 Sven Eckelmann
  0 siblings, 0 replies; only message in thread
From: Sven Eckelmann @ 2019-12-11  8:52 UTC (permalink / raw)
  To: b.a.t.m.a.n

The prefered way of getting the size of a member of a struct is the common
macro sizeof_field from stddef.h and not the FIELD_SIZEOF (with multiple
definitions).

Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
 compat-include/linux/stddef.h | 24 ++++++++++++++++++++++++
 net/batman-adv/main.c         |  2 +-
 2 files changed, 25 insertions(+), 1 deletion(-)
 create mode 100644 compat-include/linux/stddef.h

diff --git a/compat-include/linux/stddef.h b/compat-include/linux/stddef.h
new file mode 100644
index 00000000..dd18840e
--- /dev/null
+++ b/compat-include/linux/stddef.h
@@ -0,0 +1,24 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright (C) 2007-2019  B.A.T.M.A.N. contributors:
+ *
+ * Marek Lindner, Simon Wunderlich
+ *
+ * This file contains macros for maintaining compatibility with older versions
+ * of the Linux kernel.
+ */
+
+#ifndef _NET_BATMAN_ADV_COMPAT_LINUX_STDDEF_H_
+#define _NET_BATMAN_ADV_COMPAT_LINUX_STDDEF_H_
+
+#include <linux/version.h>
+#include_next <linux/stddef.h>
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 16, 0)
+
+#ifndef sizeof_field
+#define sizeof_field(TYPE, MEMBER) sizeof((((TYPE *)0)->MEMBER))
+#endif
+
+#endif /* < KERNEL_VERSION(4, 16, 0) */
+
+#endif	/* _NET_BATMAN_ADV_COMPAT_LINUX_STDDEF_H_ */
diff --git a/net/batman-adv/main.c b/net/batman-adv/main.c
index 4a89177d..4811ec65 100644
--- a/net/batman-adv/main.c
+++ b/net/batman-adv/main.c
@@ -548,7 +548,7 @@ static void batadv_recv_handler_init(void)
 	BUILD_BUG_ON(sizeof(struct batadv_tvlv_tt_change) != 12);
 	BUILD_BUG_ON(sizeof(struct batadv_tvlv_roam_adv) != 8);
 
-	i = FIELD_SIZEOF(struct sk_buff, cb);
+	i = sizeof_field(struct sk_buff, cb);
 	BUILD_BUG_ON(sizeof(struct batadv_skb_cb) > i);
 
 	/* broadcast packet */
-- 
2.20.1


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2019-12-11  8:52 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-11  8:52 [PATCH] batman-adv: Replace FIELD_SIZEOF with sizeof_field Sven Eckelmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).