diff --git a/dongle.c b/dongle.c
index cabe268a2cd245ca0986a55a86cd3484369bf28e..aca2978abd8b14eb93418ab9a0d5c35b6d414975 100644
--- a/dongle.c
+++ b/dongle.c
@@ -454,61 +454,56 @@ fail:
 	return ipv4_addr;
 }
 
-int list_to_blob(void)
+int list_to_blob(struct blob_buf *bb)
 {
 	struct device *net_dev;
-	struct blob_buf bb;
 	void *arr, *table;
 	int rv;
 
-	memset(&bb, 0, sizeof(bb));
-	rv = blob_buf_init(&bb, 0);
+	memset(bb, 0, sizeof(*bb));
+	rv = blob_buf_init(bb, 0);
 	if (rv != 0)
 		goto fail;
 
-	arr = blobmsg_open_array(&bb, "network_devices");
+	arr = blobmsg_open_array(bb, "network_devices");
 	if (!arr)
 		goto fail_arr;
 
-	list_for_each_entry(net_dev, &devices, list)
-	{
-		table = blobmsg_open_table(&bb, "");
+	list_for_each_entry(net_dev, &devices, list) {
+		table = blobmsg_open_table(bb, "");
 		if (!table)
 			goto fail_table;
 
-		rv = blobmsg_add_string(&bb, "product", net_dev->usb.product);
+		rv = blobmsg_add_string(bb, "product", net_dev->usb.product);
 		if (rv < 0)
 			goto fail_string;
 
-		rv = blobmsg_add_string(&bb, "interface_name", net_dev->usb.if_name);
+		rv = blobmsg_add_string(bb, "interface_name", net_dev->usb.if_name);
 		if (rv < 0)
 			goto fail_string;
 
-		rv = blobmsg_add_string(&bb, "idproduct", net_dev->usb.product_id);
+		rv = blobmsg_add_string(bb, "idproduct", net_dev->usb.product_id);
 		if (rv < 0)
 			goto fail_string;
 
-		rv = blobmsg_add_string(&bb, "idvendor", net_dev->usb.vendor_id);
+		rv = blobmsg_add_string(bb, "idvendor", net_dev->usb.vendor_id);
 		if (rv < 0)
 			goto fail_string;
 
 		if (net_dev->ip)
 		{
-			rv = blobmsg_add_string(&bb, "ip", net_dev->ip);
+			rv = blobmsg_add_string(bb, "ip", net_dev->ip);
 			if (rv < 0)
 				goto fail_string;
 		}
-		blobmsg_close_table(&bb, table);
+		blobmsg_close_table(bb, table);
 	}
-	blobmsg_close_array(&bb, arr);
-	ubus_send_reply(ctx, req, bb.head);
+	blobmsg_close_array(bb, arr);
 
-	blob_buf_free(&bb);
 	return 0;
 fail_string:
 fail_table:
 fail_arr:
-	blob_buf_free(&bb);
 fail:
 	return UBUS_STATUS_UNKNOWN_ERROR;
 }
@@ -517,7 +512,18 @@ int print_list(struct ubus_context *ctx, struct ubus_object *obj,
 			   struct ubus_request_data *req, const char *method,
 			   struct blob_attr *msg)
 {
-	return list_to_blob();
+	struct blob_buf bb;
+	int rv;
+
+	rv = list_to_blob(&bb);
+	if (rv == 0)
+		goto fail;
+
+	ubus_send_reply(ctx, req, bb.head);
+
+fail:
+	blob_buf_free(&bb);
+	return rv;
 }
 
 int clear(struct ubus_context *ctx, struct ubus_object *obj,
diff --git a/dongle.h b/dongle.h
index 88e733d9da58325e341f946cd904aba3d6434cf5..cb6571c7004dfab4893a6ecce8fb81854a6fadbc 100644
--- a/dongle.h
+++ b/dongle.h
@@ -34,7 +34,7 @@ void remove_newline(char *input);
 char *get_usb_stat(char *path, char *dir, char *stat);
 char *get_device_name(char *dir_name);
 char *get_device_ip(char *device_name);
-int list_to_blob(void);
+int list_to_blob(struct blob_buf *bb);
 int print_list(struct ubus_context *ctx, struct ubus_object *obj,
 			   struct ubus_request_data *req, const char *method,
 			   struct blob_attr *msg);