[1/2] batman-adv: compat: add the case if dev is NULL

Message ID 20210807051942.38538-1-sven@narfation.org (mailing list archive)
State Accepted, archived
Delegated to: Simon Wunderlich
Headers
Series [1/2] batman-adv: compat: add the case if dev is NULL |

Commit Message

Sven Eckelmann Aug. 7, 2021, 5:19 a.m. UTC
  From: Yajun Deng <yajun.deng@linux.dev>

Add the case if dev is NULL in dev_{put, hold}, so the caller doesn't
need to care whether dev is NULL or not.

Signed-off-by: Yajun Deng <yajun.deng@linux.dev>
Signed-off-by: David S. Miller <davem@davemloft.net>
[sven@narfation.org: Convert to compat code]
Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
 compat-include/linux/netdevice.h | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
  

Patch

diff --git a/compat-include/linux/netdevice.h b/compat-include/linux/netdevice.h
index 8f01b48f..9a62afcc 100644
--- a/compat-include/linux/netdevice.h
+++ b/compat-include/linux/netdevice.h
@@ -67,4 +67,27 @@  static inline int batadv_netif_rx_any_context(struct sk_buff *skb)
 
 #endif /* LINUX_VERSION_IS_LESS(5, 10, 0) */
 
+
+#if LINUX_VERSION_IS_LESS(5, 15, 0)
+
+static inline void batadv_dev_put(struct net_device *dev)
+{
+	if (!dev)
+		return;
+
+	dev_put(dev);
+}
+#define dev_put batadv_dev_put
+
+static inline void batadv_dev_hold(struct net_device *dev)
+{
+	if (!dev)
+		return;
+
+	dev_hold(dev);
+}
+#define dev_hold batadv_dev_hold
+
+#endif /* LINUX_VERSION_IS_LESS(5, 15, 0) */
+
 #endif	/* _NET_BATMAN_ADV_COMPAT_LINUX_NETDEVICE_H_ */