tools/power/acpi: close file only if it is open
authorLv Zheng <lv.zheng@intel.com>
Thu, 24 Mar 2016 05:01:28 +0000 (13:01 +0800)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Sat, 9 Apr 2016 01:08:40 +0000 (03:08 +0200)
The logic on the test for a valid fd to close is incorrect.
This was just a mistake and was pointed out by Colin Ian King.

Link: https://patchwork.kernel.org/patch/8620201/
Original-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Lv Zheng <lv.zheng@intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
tools/power/acpi/tools/acpidbg/acpidbg.c

index d070fccdba6d53500d15be1afc6bfdfa96b8f9fd..a88ac45b7756aedc77099ca5adbc1de268d5c33c 100644 (file)
@@ -375,7 +375,7 @@ void usage(FILE *file, char *progname)
 
 int main(int argc, char **argv)
 {
-       int fd = 0;
+       int fd = -1;
        int ch;
        int len;
        int ret = EXIT_SUCCESS;
@@ -430,7 +430,7 @@ int main(int argc, char **argv)
        acpi_aml_loop(fd);
 
 exit:
-       if (fd < 0)
+       if (fd >= 0)
                close(fd);
        if (acpi_aml_batch_cmd)
                free(acpi_aml_batch_cmd);