diff mbox

tools/power/acpi: close file only if it is open

Message ID 1458311312-23330-1-git-send-email-colin.king@canonical.com (mailing list archive)
State Superseded, archived
Delegated to: Rafael Wysocki
Headers show

Commit Message

Colin King March 18, 2016, 2:28 p.m. UTC
From: Colin Ian King <colin.king@canonical.com>

the logic on the test for a valid fd to close is incorrect and
the current code will close -ve fd's which is not was intended.
Since the only path to the exit label is on a failed open, we
may as well just close fd if it has been opened successfully
before the exit label and also remove the valid fd check.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 tools/power/acpi/tools/acpidbg/acpidbg.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
diff mbox

Patch

diff --git a/tools/power/acpi/tools/acpidbg/acpidbg.c b/tools/power/acpi/tools/acpidbg/acpidbg.c
index d070fcc..38ccac9 100644
--- a/tools/power/acpi/tools/acpidbg/acpidbg.c
+++ b/tools/power/acpi/tools/acpidbg/acpidbg.c
@@ -429,9 +429,8 @@  int main(int argc, char **argv)
 		acpi_aml_flush(fd);
 	acpi_aml_loop(fd);
 
+	close(fd);
 exit:
-	if (fd < 0)
-		close(fd);
 	if (acpi_aml_batch_cmd)
 		free(acpi_aml_batch_cmd);
 	return ret;