ModemManager/backport-modem-helpers-rework-the-CGEV-indication-parser.patch

87 lines
3.2 KiB
Diff
Raw Normal View History

From 9bbc768666e8ca77abdda325c46588cbf8a4df64 Mon Sep 17 00:00:00 2001
From: Aleksander Morgado <aleksandermj@chromium.org>
Date: Wed, 24 Aug 2022 16:50:34 +0000
Subject: [PATCH] modem-helpers: rework the +CGEV indication parser
We setup all output variables with g_autofree and then use
g_steal_pointer() to return the needed ones.
---
src/mm-modem-helpers.c | 36 +++++++++++++++---------------------
1 file changed, 15 insertions(+), 21 deletions(-)
diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c
index 9c3b0ccdc..d71e1082c 100644
--- a/src/mm-modem-helpers.c
+++ b/src/mm-modem-helpers.c
@@ -3642,8 +3642,8 @@ mm_3gpp_parse_cgev_indication_pdp (const gchar *str,
g_autoptr(GRegex) r = NULL;
g_autoptr(GMatchInfo) match_info = NULL;
GError *inner_error = NULL;
- gchar *pdp_type = NULL;
- gchar *pdp_addr = NULL;
+ g_autofree gchar *pdp_type = NULL;
+ g_autofree gchar *pdp_addr = NULL;
guint cid = 0;
g_assert (type == MM_3GPP_CGEV_REJECT ||
@@ -3660,44 +3660,38 @@ mm_3gpp_parse_cgev_indication_pdp (const gchar *str,
str = mm_strip_tag (str, "+CGEV:");
g_regex_match_full (r, str, strlen (str), 0, 0, &match_info, &inner_error);
- if (inner_error)
- goto out;
+ if (inner_error) {
+ g_propagate_error (error, inner_error);
+ return FALSE;
+ }
if (!g_match_info_matches (match_info)) {
- inner_error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Couldn't match response");
- goto out;
+ g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Couldn't match response");
+ return FALSE;
}
if (out_pdp_type && !(pdp_type = mm_get_string_unquoted_from_match_info (match_info, 1))) {
- inner_error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Error parsing PDP type");
- goto out;
+ g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Error parsing PDP type");
+ return FALSE;
}
if (out_pdp_addr && !(pdp_addr = mm_get_string_unquoted_from_match_info (match_info, 2))) {
- inner_error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Error parsing PDP addr");
- goto out;
+ g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Error parsing PDP addr");
+ return FALSE;
}
/* CID is optional */
if (out_cid &&
(g_match_info_get_match_count (match_info) >= 4) &&
!mm_get_uint_from_match_info (match_info, 3, &cid)) {
- inner_error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Error parsing CID");
- goto out;
- }
-
-out:
- if (inner_error) {
- g_free (pdp_type);
- g_free (pdp_addr);
- g_propagate_error (error, inner_error);
+ g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Error parsing CID");
return FALSE;
}
if (out_pdp_type)
- *out_pdp_type = pdp_type;
+ *out_pdp_type = g_steal_pointer (&pdp_type);
if (out_pdp_addr)
- *out_pdp_addr = pdp_addr;
+ *out_pdp_addr = g_steal_pointer (&pdp_addr);
if (out_cid)
*out_cid = cid;
return TRUE;
--
GitLab