Skip to contentSkip to conversation

gprs: fix allocation of context id

PATCH In review Martin Hundebøll 2 participants 2 messages Jan 4, 2019

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 gprs: fix allocation of context id

After the convertion to l_uintset, the creation of new contexts fails due to a range error being returned from l_uintset_find_unused().

The error happens because the uinset is created with a min-value of 1, but the start-value passed to l_uintset_find_unused() is initialized as 0.

Fix this by using the minimum id when last used id is not yet initialized.

---
 src/gprs.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
src/gprs.c +5 -1
index 58a998ca..92820e60 100644
@@ -2334,7 +2334,11 @@ static void provision_context(const struct ofono_gprs_provision_data *ap,
 			strlen(ap->message_center) > MAX_MESSAGE_CENTER_LENGTH)
 		return;
 
-	id = l_uintset_find_unused(gprs->used_pids, gprs->last_context_id);
+	if (!gprs->last_context_id)
+		id = l_uintset_get_min(gprs->used_pids);
+	else
+		id = l_uintset_find_unused(gprs->used_pids,
+						gprs->last_context_id);
 	if (id > l_uintset_get_max(gprs->used_pids))
 		return;
 
Signature · 1 line
2.20.1
#1 lore raw

Hi Martin,

Quoted 18 lines · Martin Hundebøll

After the convertion to l_uintset, the creation of new contexts fails due to a range error being returned from l_uintset_find_unused().

The error happens because the uinset is created with a min-value of 1, but the start-value passed to l_uintset_find_unused() is initialized as 0.

Fix this by using the minimum id when last used id is not yet initialized.

---
  src/gprs.c | 6 +++++-
  1 file changed, 5 insertions(+), 1 deletion(-)
src/gprs.c +0 -0
index 58a998ca..92820e60 100644

src/gprs.c static void provision_context(const struct ofono_gprs_provision_data *ap, · line 2338

Quoted 6 lines
src/gprs.c +2 -1
@@ -2334,7 +2334,11 @@ static void provision_context(const struct ofono_gprs_provision_data *ap,
  			strlen(ap->message_center) > MAX_MESSAGE_CENTER_LENGTH)
  		return;
 
-	id = l_uintset_find_unused(gprs->used_pids, gprs->last_context_id);
+	if (!gprs->last_context_id)
+		id = l_uintset_get_min(gprs->used_pids);

You actually want find_unused_min here.

src/gprs.c static void provision_context(const struct ofono_gprs_provision_data *ap, · line 2344

Quoted 7 lines
src/gprs.c +3 -0
+	else
+		id = l_uintset_find_unused(gprs->used_pids,
+						gprs->last_context_id);
  	if (id > l_uintset_get_max(gprs->used_pids))
  		return;
 

Anyway, I pushed my own version of this patch earlier as commit:
c3fdf6a7c567a7507c3558a27006b6f9559493d6

I did steal the commit description from you :)

Regards,
-Denis