linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: dev: Add API to check net_dev readiness
@ 2020-07-26 19:37 Ilia Lin
  2020-07-26 19:45 ` Andrew Lunn
  0 siblings, 1 reply; 8+ messages in thread
From: Ilia Lin @ 2020-07-26 19:37 UTC (permalink / raw)
  To: davem, kuba, jiri, edumazet, ap420073, xiyou.wangcong, maximmi, ilia.lin
  Cc: netdev, linux-kernel

From: Ilia Lin <ilia.lin@kernel.org>

Add an API that returns true, if the net_dev_init was already called,
and the driver was initialized.

Some early drivers, that are initialized during the subsys_initcall
may try accessing the net_dev or NAPI APIs before the net_dev_init,
and will encounter a kernel bug. This API provides a way to handle
this and manage by deferring or by other way.

Signed-off-by: Ilia Lin <ilia.lin@kernel.org>
---
 include/linux/netdevice.h |  2 ++
 net/core/dev.c            | 17 +++++++++++++++++
 2 files changed, 19 insertions(+)

diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 98d290c..d17d364 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -2600,6 +2600,8 @@ enum netdev_cmd {
 };
 const char *netdev_cmd_to_name(enum netdev_cmd cmd);
 
+bool is_net_dev_initialized(void);
+
 int register_netdevice_notifier(struct notifier_block *nb);
 int unregister_netdevice_notifier(struct notifier_block *nb);
 int register_netdevice_notifier_net(struct net *net, struct notifier_block *nb);
diff --git a/net/core/dev.c b/net/core/dev.c
index 316349f..1b50488 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -1793,6 +1793,23 @@ static void call_netdevice_unregister_net_notifiers(struct notifier_block *nb,
 static int dev_boot_phase = 1;
 
 /**
+ * is_net_dev_initialized - check, whether the net_dev was
+ * initialized
+ *
+ * Returns true, if the net_dev_init was already called, and
+ * the driver is initialized.
+ *
+ * This is useful for early drivers trying to call net_dev and
+ * NAPI APIs
+ */
+
+bool is_net_dev_initialized(void)
+{
+       return !(bool)dev_boot_phase;
+}
+EXPORT_SYMBOL(is_net_dev_initialized);
+
+/**
  * register_netdevice_notifier - register a network notifier block
  * @nb: notifier
  *


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2020-08-05 20:12 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-26 19:37 [PATCH] net: dev: Add API to check net_dev readiness Ilia Lin
2020-07-26 19:45 ` Andrew Lunn
2020-07-27 17:32   ` David Miller
2020-08-04 17:47     ` Ilia Lin
2020-08-04 19:24       ` Andrew Lunn
2020-08-05 10:31         ` Ilia Lin
2020-08-05 13:14           ` Andrew Lunn
2020-08-04 18:42     ` Ilia Lin

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).