Diff between 07e74279efa0c55d2f9617356e514e15169ebaa1 and 8bdf3c7a2833f5124adfb52893db0821d17e045a

Changed Files

File Additions Deletions Status
src/shared/mgmt.c +24 -6 modified

Full Patch

diff --git a/src/shared/mgmt.c b/src/shared/mgmt.c
index 5dba3d8..b6af1ab 100644
--- a/src/shared/mgmt.c
+++ b/src/shared/mgmt.c
@@ -466,7 +466,7 @@ bool mgmt_set_close_on_unref(struct mgmt *mgmt, bool do_close)
 	return true;
 }
 
-unsigned int mgmt_send(struct mgmt *mgmt, uint16_t opcode, uint16_t index,
+static struct mgmt_request *create_request(uint16_t opcode, uint16_t index,
 				uint16_t length, const void *param,
 				mgmt_request_func_t callback,
 				void *user_data, mgmt_destroy_func_t destroy)
@@ -474,21 +474,21 @@ unsigned int mgmt_send(struct mgmt *mgmt, uint16_t opcode, uint16_t index,
 	struct mgmt_request *request;
 	struct mgmt_hdr *hdr;
 
-	if (!mgmt || !opcode)
-		return 0;
+	if (!opcode)
+		return NULL;
 
 	if (length > 0 && !param)
-		return 0;
+		return NULL;
 
 	request = g_try_new0(struct mgmt_request, 1);
 	if (!request)
-		return 0;
+		return NULL;
 
 	request->len = length + MGMT_HDR_SIZE;
 	request->buf = g_try_malloc(request->len);
 	if (!request->buf) {
 		g_free(request);
-		return 0;
+		return NULL;
 	}
 
 	if (length > 0)
@@ -506,6 +506,24 @@ unsigned int mgmt_send(struct mgmt *mgmt, uint16_t opcode, uint16_t index,
 	request->destroy = destroy;
 	request->user_data = user_data;
 
+	return request;
+}
+
+unsigned int mgmt_send(struct mgmt *mgmt, uint16_t opcode, uint16_t index,
+				uint16_t length, const void *param,
+				mgmt_request_func_t callback,
+				void *user_data, mgmt_destroy_func_t destroy)
+{
+	struct mgmt_request *request;
+
+	if (!mgmt)
+		return 0;
+
+	request = create_request(opcode, index, length, param,
+					callback, user_data, destroy);
+	if (!request)
+		return 0;
+
 	if (mgmt->next_request_id < 1)
 		mgmt->next_request_id = 1;