[PATCH 47/47] headers: Check for NULL in dev_put() and dev_hold()

Hauke Mehrtens <[email protected]>
Newsgroups org.kernel.vger.backports
Message-ID <[email protected]>
Since kernel 5.15 the dev_put() and dev_hold() functions check if the
given dev is not NULL before accessing the pointer. Previously the code
to check for NULL was in the calling function. Add this check for NULL
because some checks were already removed from the driver code.

Signed-off-by: Hauke Mehrtens <[email protected]>
---
 backport/backport-include/linux/netdevice.h | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/backport/backport-include/linux/netdevice.h b/backport/backport-include/linux/netdevice.h
index 5c30426d..22942398 100644
--- a/backport/backport-include/linux/netdevice.h
+++ b/backport/backport-include/linux/netdevice.h
@@ -151,4 +151,20 @@ struct rtnl_link_stats64 *
 bp_dev_get_tstats64(struct net_device *dev, struct rtnl_link_stats64 *s);
 #endif /* < 4.11 */
 
+#if LINUX_VERSION_IS_LESS(5,15,0)
+static inline void backport_dev_put(struct net_device *dev)
+{
+	if (dev)
+		dev_put(dev);
+}
+#define dev_put LINUX_BACKPORT(dev_put)
+
+static inline void backport_dev_hold(struct net_device *dev)
+{
+	if (dev)
+		dev_hold(dev);
+}
+#define dev_hold LINUX_BACKPORT(dev_hold)
+#endif /* < 5.15 */
+
 #endif /* __BACKPORT_NETDEVICE_H */
-- 
2.30.2

--
To unsubscribe from this list: send the line "unsubscribe backports" in
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.