halcc: Fix errno not to be overwritten before returning 75/313375/1
authorYoungjae Cho <y0.cho@samsung.com>
Tue, 25 Jun 2024 01:38:37 +0000 (10:38 +0900)
committerYoungjae Cho <y0.cho@samsung.com>
Tue, 25 Jun 2024 02:36:12 +0000 (11:36 +0900)
Change-Id: Iddc5f3e1abd43c6a9881fdde55ae354c47850b6a
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
src/hal-api-compatibility-checker.c

index a4d29d4541830ebe34b845b78acc3e2827d0e254..fef9463744d43bc11ed6e94694000b5fec321582 100644 (file)
@@ -350,16 +350,19 @@ static int open_result_file(const char *path, int *fd_out, bool reset)
                        return 0;
                }
 
+               ret = -errno;
                _E("Failed to create %s, %m", path);
-               return -errno;
+
+               return ret;
        }
 
        /* set a new file size */
        ret = ftruncate(fd, sizeof(struct compatibility_info) * HAL_MODULE_END);
        if (ret < 0) {
+               ret = -errno;
                _E("Failed to ftruncate %s, %m", path);
                close(fd);
-               return -errno;
+               return ret;
        }
 
        /* system_fw:system_fw */
@@ -393,9 +396,10 @@ static int write_module_comaptibility_info(enum hal_module module,
        offset = sizeof(struct compatibility_info) * module;
        n_write = pwrite(fd, info, sizeof(*info), offset);
        if (n_write == -1) {
+               ret = -errno;
                _E("Failed to write info, %m");
                close(fd);
-               return -errno;
+               return ret;
        }
 
        close(fd);
@@ -409,6 +413,7 @@ static int load_module_compatibility_info(enum hal_module module,
        int fd = -1;
        size_t n_read = -1;
        off_t offset;
+       int ret;
 
        if (module < HAL_MODULE_UNKNOWN || module >= HAL_MODULE_END)
                return -EINVAL;
@@ -423,8 +428,9 @@ static int load_module_compatibility_info(enum hal_module module,
        offset = sizeof(struct compatibility_info) * module;
        n_read = pread(fd, info, sizeof(*info), offset);
        if (n_read == -1) {
+               ret = -errno;
                close(fd);
-               return -errno;
+               return ret;
        }
 
        close(fd);