- if (task->state == BOOT_STATE_INITRD_LOADING) {
- if (task->dtb) {
- update_status(task->status_fn, task->status_arg,
- BOOT_STATUS_INFO,
- "loading device tree");
- task->local_dtb = load_url_async(task, task->dtb,
- &clean_dtb, boot_process);
- if (!task->local_dtb) {
- update_status(task->status_fn, task->status_arg,
- BOOT_STATUS_ERROR,
- "Couldn't load device tree");
- goto no_load;
- } else {
- task->state = BOOT_STATE_FINISH;
- return;
- }
- } else {
- task->state = BOOT_STATE_FINISH;
+static void cleanup_cancellations(struct boot_task *task,
+ struct load_url_result *cur_result)
+{
+ struct load_url_result *result, **results[] = {
+ &task->image, &task->initrd, &task->dtb,
+ };
+ bool pending = false;
+ unsigned int i;
+
+ for (i = 0; i < ARRAY_SIZE(results); i++) {
+ result = *results[i];
+
+ if (!result)
+ continue;
+
+ /* We need to cleanup and free any completed loads */
+ if (result == cur_result || result->status == LOAD_OK
+ || result->status == LOAD_ERROR) {
+ cleanup_load(result);
+ talloc_free(result);
+ *results[i] = NULL;
+
+ /* ... and cancel any pending loads, which we'll free in
+ * the completion callback */
+ } else if (result->status == LOAD_ASYNC) {
+ load_url_async_cancel(result);
+ pending = true;