connman.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [PATCH] wisrp: Handle wispr_portal_detect failures
@ 2022-08-28 13:53 Daniel Wagner
  2022-08-28 18:31 ` Daniel Wagner
  0 siblings, 1 reply; 2+ messages in thread
From: Daniel Wagner @ 2022-08-28 13:53 UTC (permalink / raw)
  To: connman; +Cc: Daniel Wagner

__connman_wispr_start() should handle any errors reported by
wispr_portal_detect.

While at it also return early if the service type is not supported.
---
 src/wispr.c | 56 ++++++++++++++++++++++++++++++-----------------------
 1 file changed, 32 insertions(+), 24 deletions(-)

diff --git a/src/wispr.c b/src/wispr.c
index 84bed33f217d..9b27af5fff55 100644
--- a/src/wispr.c
+++ b/src/wispr.c
@@ -916,7 +916,6 @@ static gboolean no_proxy_callback(gpointer user_data)
 static int wispr_portal_detect(struct connman_wispr_portal_context *wp_context)
 {
 	enum connman_service_proxy_method proxy_method;
-	enum connman_service_type service_type;
 	char *interface = NULL;
 	char **nameservers = NULL;
 	int if_index;
@@ -926,23 +925,6 @@ static int wispr_portal_detect(struct connman_wispr_portal_context *wp_context)
 	DBG("wispr/portal context %p service %p", wp_context,
 		wp_context->service);
 
-	service_type = connman_service_get_type(wp_context->service);
-
-	switch (service_type) {
-	case CONNMAN_SERVICE_TYPE_ETHERNET:
-	case CONNMAN_SERVICE_TYPE_WIFI:
-	case CONNMAN_SERVICE_TYPE_BLUETOOTH:
-	case CONNMAN_SERVICE_TYPE_CELLULAR:
-	case CONNMAN_SERVICE_TYPE_GADGET:
-		break;
-	case CONNMAN_SERVICE_TYPE_UNKNOWN:
-	case CONNMAN_SERVICE_TYPE_SYSTEM:
-	case CONNMAN_SERVICE_TYPE_GPS:
-	case CONNMAN_SERVICE_TYPE_VPN:
-	case CONNMAN_SERVICE_TYPE_P2P:
-		return -EOPNOTSUPP;
-	}
-
 	interface = connman_service_get_interface(wp_context->service);
 	if (!interface)
 		return -EINVAL;
@@ -1012,13 +994,28 @@ int __connman_wispr_start(struct connman_service *service,
 {
 	struct connman_wispr_portal_context *wp_context = NULL;
 	struct connman_wispr_portal *wispr_portal = NULL;
-	int index;
+	int index, err;
 
 	DBG("service %p", service);
 
 	if (!wispr_portal_hash)
 		return -EINVAL;
 
+	switch (connman_service_get_type(service)) {
+	case CONNMAN_SERVICE_TYPE_ETHERNET:
+	case CONNMAN_SERVICE_TYPE_WIFI:
+	case CONNMAN_SERVICE_TYPE_BLUETOOTH:
+	case CONNMAN_SERVICE_TYPE_CELLULAR:
+	case CONNMAN_SERVICE_TYPE_GADGET:
+		break;
+	case CONNMAN_SERVICE_TYPE_UNKNOWN:
+	case CONNMAN_SERVICE_TYPE_SYSTEM:
+	case CONNMAN_SERVICE_TYPE_GPS:
+	case CONNMAN_SERVICE_TYPE_VPN:
+	case CONNMAN_SERVICE_TYPE_P2P:
+		return -EOPNOTSUPP;
+	}
+
 	index = __connman_service_get_index(service);
 	if (index < 0)
 		return -EINVAL;
@@ -1038,16 +1035,20 @@ int __connman_wispr_start(struct connman_service *service,
 		wp_context = wispr_portal->ipv4_context;
 	else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
 		wp_context = wispr_portal->ipv6_context;
-	else
-		return -EINVAL;
+	else {
+		err = -EINVAL;
+		goto free_wp;
+	}
 
 	/* If there is already an existing context, we wipe it */
 	if (wp_context)
 		wispr_portal_context_unref(wp_context);
 
 	wp_context = create_wispr_portal_context();
-	if (!wp_context)
-		return -ENOMEM;
+	if (!wp_context) {
+		err = -ENOMEM;
+		goto free_wp;
+	}
 
 	wp_context->service = service;
 	wp_context->type = type;
@@ -1058,7 +1059,14 @@ int __connman_wispr_start(struct connman_service *service,
 	else
 		wispr_portal->ipv6_context = wp_context;
 
-	return wispr_portal_detect(wp_context);
+	err = wispr_portal_detect(wp_context);
+	if (err)
+		goto free_wp;
+	return 0;
+
+free_wp:
+	g_hash_table_remove(wispr_portal_hash, GINT_TO_POINTER(index));
+	return err;
 }
 
 void __connman_wispr_stop(struct connman_service *service)
-- 
2.37.2


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

* Re: [PATCH] wisrp: Handle wispr_portal_detect failures
  2022-08-28 13:53 [PATCH] wisrp: Handle wispr_portal_detect failures Daniel Wagner
@ 2022-08-28 18:31 ` Daniel Wagner
  0 siblings, 0 replies; 2+ messages in thread
From: Daniel Wagner @ 2022-08-28 18:31 UTC (permalink / raw)
  To: connman

On Sun, Aug 28, 2022 at 03:53:22PM +0200, Daniel Wagner wrote:
> __connman_wispr_start() should handle any errors reported by
> wispr_portal_detect.
> 
> While at it also return early if the service type is not supported.

applied

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

end of thread, other threads:[~2022-08-28 18:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-28 13:53 [PATCH] wisrp: Handle wispr_portal_detect failures Daniel Wagner
2022-08-28 18:31 ` Daniel Wagner

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