[3/3] batman-adv: genetlink: mark families as __ro_after_init

Message ID 20161029080328.26584-3-sven@narfation.org (mailing list archive)
State Accepted, archived
Commit c776b4a071d82f8ad0e35d1b9472758ecf69a75e
Delegated to: Sven Eckelmann
Headers

Commit Message

Sven Eckelmann Oct. 29, 2016, 8:03 a.m. UTC
  From: Johannes Berg <johannes.berg@intel.com>

Now genl_register_family() is the only thing (other than the
users themselves, perhaps, but I didn't find any doing that)
writing to the family struct.

In all families that I found, genl_register_family() is only
called from __init functions (some indirectly, in which case
I've add __init annotations to clarifly things), so all can
actually be marked __ro_after_init.

This protects the data structure from accidental corruption.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
[sven@narfation.org: Add compat code]
Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
Patch already in net-next

 compat-include/linux/cache.h | 35 +++++++++++++++++++++++++++++++++++
 net/batman-adv/netlink.c     |  2 +-
 2 files changed, 36 insertions(+), 1 deletion(-)
 create mode 100644 compat-include/linux/cache.h
  

Comments

Sven Eckelmann Nov. 1, 2016, 7:30 a.m. UTC | #1
On Samstag, 29. Oktober 2016 10:03:28 CET Sven Eckelmann wrote:
> From: Johannes Berg <johannes.berg@intel.com>
> 
> Now genl_register_family() is the only thing (other than the
> users themselves, perhaps, but I didn't find any doing that)
> writing to the family struct.
> 
> In all families that I found, genl_register_family() is only
> called from __init functions (some indirectly, in which case
> I've add __init annotations to clarifly things), so all can
> actually be marked __ro_after_init.
> 
> This protects the data structure from accidental corruption.
> 
> Signed-off-by: Johannes Berg <johannes.berg@intel.com>
> Signed-off-by: David S. Miller <davem@davemloft.net>
> [sven@narfation.org: Add compat code]
> Signed-off-by: Sven Eckelmann <sven@narfation.org>
> ---
> Patch already in net-next
> 
>  compat-include/linux/cache.h | 35 +++++++++++++++++++++++++++++++++++
>  net/batman-adv/netlink.c     |  2 +-
>  2 files changed, 36 insertions(+), 1 deletion(-)
>  create mode 100644 compat-include/linux/cache.h

Applied in c776b4a071d82f8ad0e35d1b9472758ecf69a75e [1].

Kind regards,
        Sven

[1] https://git.open-mesh.org/batman-adv.git/commit/c776b4a071d82f8ad0e35d1b9472758ecf69a75e
  

Patch

diff --git a/compat-include/linux/cache.h b/compat-include/linux/cache.h
new file mode 100644
index 0000000..93dff58
--- /dev/null
+++ b/compat-include/linux/cache.h
@@ -0,0 +1,35 @@ 
+/* Copyright (C) 2007-2016 B.A.T.M.A.N. contributors:
+ *
+ * Marek Lindner, Simon Wunderlich
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * This file contains macros for maintaining compatibility with older versions
+ * of the Linux kernel.
+ */
+
+#ifndef _NET_BATMAN_ADV_COMPAT_LINUX_CACHE_H
+#define _NET_BATMAN_ADV_COMPAT_LINUX_CACHE_H
+
+#include <linux/version.h>
+#include_next <linux/cache.h>
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 6, 0)
+
+#ifndef __ro_after_init
+#define __ro_after_init
+#endif
+
+#endif /* < KERNEL_VERSION(4, 6, 0) */
+
+#endif /* _NET_BATMAN_ADV_COMPAT_LINUX_CACHE_H */
diff --git a/net/batman-adv/netlink.c b/net/batman-adv/netlink.c
index 5dfc5c4..5d38c77 100644
--- a/net/batman-adv/netlink.c
+++ b/net/batman-adv/netlink.c
@@ -603,7 +603,7 @@  static const struct genl_ops batadv_netlink_ops[] = {
 
 };
 
-struct genl_family batadv_netlink_family = {
+struct genl_family batadv_netlink_family __ro_after_init = {
 	.hdrsize = 0,
 	.name = BATADV_NL_NAME,
 	.version = 1,