From: Seung-Woo Kim Date: Mon, 11 Nov 2024 08:02:22 +0000 (+0900) Subject: dfu: Always do umount for fail path after mount X-Git-Tag: accepted/tizen/unified/x/20241114.135530^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fheads%2Ftizen;p=platform%2Fcore%2Fsystem%2Finitrd-flash.git dfu: Always do umount for fail path after mount 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 --- diff --git a/src/dfu.c b/src/dfu.c index fce2f6b..4cd1e28 100644 --- 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; }