aboutsummaryrefslogtreecommitdiff
path: root/src/mm-modem-helpers-qmi.c
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@aleksander.es>2020-11-22 17:01:19 +0100
committerAleksander Morgado <aleksander@aleksander.es>2021-02-23 11:35:11 +0000
commit657cabcfce6794d2a2f629d63dbd56fc149dab2e (patch)
tree402bd1b6787ee65b93aad0d1b94ef9e9162e2178 /src/mm-modem-helpers-qmi.c
parentdbdf67e9f7c55d7f70ed94449160a7ff254359a2 (diff)
libmm-glib,common-helpers: make hexstr2bin() return a GError
This util method checks whether the input string is a valid hex string, so make sure we return a GError on failure.
Diffstat (limited to 'src/mm-modem-helpers-qmi.c')
-rw-r--r--src/mm-modem-helpers-qmi.c20
1 files changed, 7 insertions, 13 deletions
diff --git a/src/mm-modem-helpers-qmi.c b/src/mm-modem-helpers-qmi.c
index 8d0e4b88..4180a268 100644
--- a/src/mm-modem-helpers-qmi.c
+++ b/src/mm-modem-helpers-qmi.c
@@ -1811,25 +1811,19 @@ mm_firmware_unique_id_to_qmi_unique_id (const gchar *unique_id,
/* The length will be exactly EXPECTED_QMI_UNIQUE_ID_LENGTH*2 if given in HEX */
if (len == (2 * EXPECTED_QMI_UNIQUE_ID_LENGTH)) {
- guint8 *tmp;
- gsize tmp_len;
- guint i;
-
- for (i = 0; i < len; i++) {
- if (!g_ascii_isxdigit (unique_id[i])) {
- g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
- "Unexpected character found in unique id (not HEX): %c", unique_id[i]);
- return NULL;
- }
- }
+ g_autofree guint8 *tmp = NULL;
+ gsize tmp_len;
tmp_len = 0;
- tmp = (guint8 *) mm_utils_hexstr2bin (unique_id, &tmp_len);
+ tmp = (guint8 *) mm_utils_hexstr2bin (unique_id, &tmp_len, error);
+ if (!tmp) {
+ g_prefix_error (error, "Unexpected character found in unique id: ");
+ return NULL;
+ }
g_assert (tmp_len == EXPECTED_QMI_UNIQUE_ID_LENGTH);
qmi_unique_id = g_array_sized_new (FALSE, FALSE, sizeof (guint8), tmp_len);
g_array_insert_vals (qmi_unique_id, 0, tmp, tmp_len);
- g_free (tmp);
return qmi_unique_id;
}