Skip to contentSkip to conversation

Mesh: Fix reclaiming addresses when deleting a node

PATCH New Inga Stotland 1 participant 1 message Mar 19, 2018 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Mesh: Fix reclaiming addresses when deleting a node

The calculations for address pool edges were off by 1.
Also, handle a case when newly adjacent address pools need to be merged.

---
 mesh/net.c | 24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)
mesh/net.c +19 -5
index 20dfcb8a8..b64847fe1 100644
@@ -785,11 +785,25 @@ void net_release_address(uint16_t addr, uint8_t num_elements)
 		max = range >> 16;
 		min = range & 0xffff;
 
-		if (min == (addr + num_elements + 1))
-			min  = addr;
-		else if (addr && max == (addr - 1))
-			max = addr + num_elements + 1;
-		else
+		if (min == (addr + num_elements))
+			min = addr;
+		else if (addr && max == (addr - 1)) {
+			max = max + num_elements;
+
+			/* Check if needs to merge with the next pool */
+			if (l->next) {
+				GList *l1 = l->next;
+				uint32_t range1 = GPOINTER_TO_UINT(l1->data);
+				uint16_t min1 = range1 & 0xffff;
+
+				if (min1 == (max + 1)) {
+					max = range1 >> 16;
+					net.address_pool = g_list_delete_link(
+							net.address_pool, l);
+					l = l1;
+				}
+			}
+		} else
 			continue;
 
 		range = min + (max << 16);
Signature · 1 line
2.13.6