iwd.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] wiphy: prevent multiple wiphy registrations
@ 2023-01-17 18:03 James Prestwood
  2023-01-17 18:03 ` [PATCH 2/2] manager: handle -ENODEV special in interface callback James Prestwood
  2023-01-17 19:12 ` [PATCH 1/2] wiphy: prevent multiple wiphy registrations Denis Kenzior
  0 siblings, 2 replies; 3+ messages in thread
From: James Prestwood @ 2023-01-17 18:03 UTC (permalink / raw)
  To: iwd; +Cc: James Prestwood

With really badly timed events a wiphy can be registered twice. This
happens when IWD starts and requests a wiphy dump. Immediately after
a NEW_WIPHY event comes in (presumably when the driver loads) which
starts another dump. The NEW_WIPHY event can't simply be ignored
since it could be a hotplug (e.g. USB card) so to fix this we can
instead just prevent it from being registered.

This does mean both dumps will happen but the information will just
be added to the same wiphy object.
---
 src/wiphy.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/src/wiphy.c b/src/wiphy.c
index 9ca651f4..fcdc3ab8 100644
--- a/src/wiphy.c
+++ b/src/wiphy.c
@@ -2324,6 +2324,15 @@ static void wiphy_get_reg_domain(struct wiphy *wiphy)
 
 void wiphy_create_complete(struct wiphy *wiphy)
 {
+	/*
+	 * With really bad timing two wiphy dumps can occur (initial and a
+	 * NEW_WIPHY event) and actually register twice. Ignoring/preventing the
+	 * second dump is problematic since it _could_ be a legitimate event so
+	 * instead just prevent it from registering twice.
+	 */
+	if (wiphy->registered)
+		return;
+
 	wiphy_register(wiphy);
 
 	if (l_memeqzero(wiphy->permanent_addr, 6)) {
-- 
2.34.3


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

* [PATCH 2/2] manager: handle -ENODEV special in interface callback
  2023-01-17 18:03 [PATCH 1/2] wiphy: prevent multiple wiphy registrations James Prestwood
@ 2023-01-17 18:03 ` James Prestwood
  2023-01-17 19:12 ` [PATCH 1/2] wiphy: prevent multiple wiphy registrations Denis Kenzior
  1 sibling, 0 replies; 3+ messages in thread
From: James Prestwood @ 2023-01-17 18:03 UTC (permalink / raw)
  To: iwd; +Cc: James Prestwood

If IWD ends up dumping wiphy's twice (because of NEW_WIPHY event
soon after initial dump) it will also try and dump interfaces
twice leading to multiple DEL_INTERFACE calls. The second attempt
will fail with -ENODEV (since the interface was already deleted).
Just silently fail with this case and let the other DEL_INTERFACE
path handle the re-creation.
---
 src/manager.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/manager.c b/src/manager.c
index fed02777..f1aa59c7 100644
--- a/src/manager.c
+++ b/src/manager.c
@@ -320,13 +320,18 @@ static void manager_setup_cmd_done(void *user_data)
 static void manager_del_interface_cb(struct l_genl_msg *msg, void *user_data)
 {
 	struct wiphy_setup_state *state = user_data;
+	int err;
 
 	l_debug("");
 
 	if (state->aborted)
 		return;
 
-	if (l_genl_msg_get_error(msg) < 0) {
+	err = l_genl_msg_get_error(msg);
+
+	if (err == -ENODEV)
+		return;
+	else if (err < 0) {
 		l_error("DEL_INTERFACE failed: %s",
 			strerror(-l_genl_msg_get_error(msg)));
 		state->use_default = true;
-- 
2.34.3


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

* Re: [PATCH 1/2] wiphy: prevent multiple wiphy registrations
  2023-01-17 18:03 [PATCH 1/2] wiphy: prevent multiple wiphy registrations James Prestwood
  2023-01-17 18:03 ` [PATCH 2/2] manager: handle -ENODEV special in interface callback James Prestwood
@ 2023-01-17 19:12 ` Denis Kenzior
  1 sibling, 0 replies; 3+ messages in thread
From: Denis Kenzior @ 2023-01-17 19:12 UTC (permalink / raw)
  To: James Prestwood, iwd

Hi James,

On 1/17/23 12:03, James Prestwood wrote:
> With really badly timed events a wiphy can be registered twice. This
> happens when IWD starts and requests a wiphy dump. Immediately after
> a NEW_WIPHY event comes in (presumably when the driver loads) which
> starts another dump. The NEW_WIPHY event can't simply be ignored
> since it could be a hotplug (e.g. USB card) so to fix this we can
> instead just prevent it from being registered.
> 
> This does mean both dumps will happen but the information will just
> be added to the same wiphy object.
> ---
>   src/wiphy.c | 9 +++++++++
>   1 file changed, 9 insertions(+)

Both applied, thanks.

Regards,
-Denis


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

end of thread, other threads:[~2023-01-17 19:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-17 18:03 [PATCH 1/2] wiphy: prevent multiple wiphy registrations James Prestwood
2023-01-17 18:03 ` [PATCH 2/2] manager: handle -ENODEV special in interface callback James Prestwood
2023-01-17 19:12 ` [PATCH 1/2] wiphy: prevent multiple wiphy registrations Denis Kenzior

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