summaryrefslogtreecommitdiff
path: root/drivers/mbimmodem
diff options
context:
space:
mode:
authorDenis Kenzior <denkenz@gmail.com>2017-10-04 10:59:30 -0500
committerDenis Kenzior <denkenz@gmail.com>2017-10-05 11:08:38 -0500
commitdb42e75a9cbada6f3249bb473c99b9059a178fee (patch)
tree61f6cbcc12744363d0e0b96efbf96119685be9b3 /drivers/mbimmodem
parent09eed8855345e390daa150ea3005781efc34c079 (diff)
downloadofono-db42e75a9cbada6f3249bb473c99b9059a178fee.tar.gz
mbim: Add mbim_device_cancel
Diffstat (limited to 'drivers/mbimmodem')
-rw-r--r--drivers/mbimmodem/mbim.c54
-rw-r--r--drivers/mbimmodem/mbim.h1
2 files changed, 47 insertions, 8 deletions
diff --git a/drivers/mbimmodem/mbim.c b/drivers/mbimmodem/mbim.c
index 59a7f2e1..db0528c0 100644
--- a/drivers/mbimmodem/mbim.c
+++ b/drivers/mbimmodem/mbim.c
@@ -240,15 +240,30 @@ static bool pending_command_match_tid(const void *a, const void *b)
return pending->tid == tid;
}
-static void pending_command_free(void *data)
+/*
+ * Since we have to track how many outstanding requests we have issues, we
+ * have to keep a pending_command structure around until it is replied to
+ * by the function. However, all resources associated with the command
+ * can be freed
+ */
+static void pending_command_cancel(void *data)
{
struct pending_command *pending = data;
mbim_message_unref(pending->message);
+ pending->message = NULL;
if (pending->destroy)
pending->destroy(pending->user_data);
+ pending->callback = NULL;
+ pending->user_data = NULL;
+ pending->destroy = NULL;
+}
+
+static void pending_command_free(void *pending)
+{
+ pending_command_cancel(pending);
l_free(pending);
}
@@ -357,13 +372,8 @@ static bool command_write_handler(struct l_io *io, void *user_data)
"fragment me");
}
- if (pending->callback == NULL) {
- pending_command_free(pending);
- goto done;
- }
-
l_queue_push_tail(device->sent_commands, pending);
-done:
+
if (l_queue_isempty(device->pending_commands))
return false;
@@ -387,7 +397,9 @@ static void dispatch_message(struct mbim_device *device, uint32_t type,
if (!pending)
goto done;
- pending->callback(message, pending->user_data);
+ if (pending->callback)
+ pending->callback(message, pending->user_data);
+
pending_command_free(pending);
if (l_queue_isempty(device->pending_commands))
@@ -877,3 +889,29 @@ uint32_t mbim_device_send(struct mbim_device *device, uint32_t gid,
done:
return pending->tid;
}
+
+bool mbim_device_cancel(struct mbim_device *device, uint32_t tid)
+{
+ struct pending_command *pending;
+
+ if (unlikely(!device))
+ return false;
+
+ pending = l_queue_remove_if(device->pending_commands,
+ pending_command_match_tid,
+ L_UINT_TO_PTR(tid));
+ if (pending) {
+ pending_command_free(pending);
+ return true;
+ }
+
+ pending = l_queue_find(device->sent_commands,
+ pending_command_match_tid,
+ L_UINT_TO_PTR(tid));
+
+ if (!pending)
+ return false;
+
+ pending_command_cancel(pending);
+ return true;
+}
diff --git a/drivers/mbimmodem/mbim.h b/drivers/mbimmodem/mbim.h
index 377aea7a..7c7758d8 100644
--- a/drivers/mbimmodem/mbim.h
+++ b/drivers/mbimmodem/mbim.h
@@ -62,3 +62,4 @@ uint32_t mbim_device_send(struct mbim_device *device, uint32_t gid,
mbim_device_reply_func_t function,
void *user_data,
mbim_device_destroy_func_t destroy);
+bool mbim_device_cancel(struct mbim_device *device, uint32_t tid);