* [PATCH] tools/power/acpi: close file only if it is open
@ 2016-03-18 14:28 Colin King
0 siblings, 0 replies; 3+ messages in thread
From: Colin King @ 2016-03-18 14:28 UTC (permalink / raw)
To: Rafael J . Wysocki, Len Brown, Robert Moore, Lv Zheng, linux-acpi,
devel
Cc: linux-kernel
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 --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;
--
2.7.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH] tools/power/acpi: close file only if it is open
@ 2016-03-24 5:01 Lv Zheng
2016-04-21 0:19 ` Rafael J. Wysocki
0 siblings, 1 reply; 3+ messages in thread
From: Lv Zheng @ 2016-03-24 5:01 UTC (permalink / raw)
To: Rafael J. Wysocki, Rafael J. Wysocki, Len Brown
Cc: Lv Zheng, Lv Zheng, linux-acpi
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>
---
tools/power/acpi/tools/acpidbg/acpidbg.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/power/acpi/tools/acpidbg/acpidbg.c b/tools/power/acpi/tools/acpidbg/acpidbg.c
index d070fcc..a88ac45 100644
--- a/tools/power/acpi/tools/acpidbg/acpidbg.c
+++ b/tools/power/acpi/tools/acpidbg/acpidbg.c
@@ -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);
--
1.7.10
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-04-21 0:17 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-18 14:28 [PATCH] tools/power/acpi: close file only if it is open Colin King
-- strict thread matches above, loose matches on Subject: below --
2016-03-24 5:01 Lv Zheng
2016-04-21 0:19 ` Rafael J. Wysocki
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).