dfu: Always do umount for fail path after mount 36/320236/2 accepted/tizen_unified accepted/tizen_unified_x accepted/tizen_unified_x_asan tizen accepted/tizen/unified/20241114.153919 accepted/tizen/unified/x/20241114.135530 accepted/tizen/unified/x/asan/20241224.004555
authorSeung-Woo Kim <sw0312.kim@samsung.com>
Mon, 11 Nov 2024 08:02:22 +0000 (17:02 +0900)
committerSeung-Woo Kim <sw0312.kim@samsung.com>
Mon, 11 Nov 2024 08:25:22 +0000 (17:25 +0900)
In fail path, there is missing umount for mounted point.
Always do umount for fail path after mount.

Change-Id: I4ad0c09a9591ed18a7108cd2cdebe75fc721b5f3
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
src/dfu.c

index fce2f6b6525cef064ddd8558480fa15d61315a63..4cd1e2801d72ab4821666dcf7fafb97875178252 100644 (file)
--- a/src/dfu.c
+++ b/src/dfu.c
@@ -454,6 +454,7 @@ static int find_slot_b(struct dfu_context *ctx, char *name) {
        int fd = -1;
        char *file = NULL;
        int i, ret = 0;
+       int is_file_mode = 0;
 
        for (i = 0; i < DFU_ENTRY_LIST_MAXLEN; i++) {
                char *entry_name = ctx->dfu_entry_list[i][DFU_INFO_NAME];
@@ -485,6 +486,7 @@ static int find_slot_b(struct dfu_context *ctx, char *name) {
                                        strncpy(file, DFU_MOUNT_B_PATH, path_prefix + 1);
                                        strncat(file, entry[DFU_INFO_PATH], path_suffix + 1);
                                        strncat(file, entry[DFU_INFO_NAME], path_name + 1);
+                                       is_file_mode = 1;
                                        break;
                                }
                                default:
@@ -508,6 +510,8 @@ static int find_slot_b(struct dfu_context *ctx, char *name) {
                fprintf(stderr,
                        "cannot open %s for target: %s\n", file, name);
                fd = -EIO;
+               if (is_file_mode)
+                       umount_dev(PATH_B);
        }
 
        free(file);
@@ -520,6 +524,7 @@ static int dfu_start_entry(struct dfu_entry *e, char **entry, uint64_t size)
 {
        char *file;
        int fd, ret = 0;
+       int is_file_mode = 0;
 
        switch (*entry[DFU_INFO_MODE]) {
        case DFU_INFO_MODE_PARTITION:
@@ -546,6 +551,7 @@ static int dfu_start_entry(struct dfu_entry *e, char **entry, uint64_t size)
                strncpy(file, DFU_MOUNT_PATH, path_prefix + 1);
                strncat(file, entry[DFU_INFO_PATH], path_suffix + 1);
                strncat(file, entry[DFU_INFO_NAME], path_name + 1);
+               is_file_mode = 1;
                break;
        }
        default:
@@ -561,6 +567,9 @@ static int dfu_start_entry(struct dfu_entry *e, char **entry, uint64_t size)
                        "cannot open %s for target: %s\n",
                        file, entry[DFU_INFO_NAME]);
                ret = -EIO;
+               if (is_file_mode)
+                       umount_dev(PATH_A);
+
                goto err;
        }