From patchwork Fri Mar 18 14:28:32 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin King X-Patchwork-Id: 8620201 X-Patchwork-Delegate: rjw@sisk.pl Return-Path: X-Original-To: patchwork-linux-acpi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id EB967C0553 for ; Fri, 18 Mar 2016 14:28:46 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 25BBC20149 for ; Fri, 18 Mar 2016 14:28:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 16850201F5 for ; Fri, 18 Mar 2016 14:28:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932863AbcCRO2j (ORCPT ); Fri, 18 Mar 2016 10:28:39 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:35680 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934048AbcCRO2g (ORCPT ); Fri, 18 Mar 2016 10:28:36 -0400 Received: from cpc86913-craw7-2-0-cust134.16-3.cable.virginm.net ([92.239.46.135] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1agvOD-0005bY-8J; Fri, 18 Mar 2016 14:28:33 +0000 From: Colin King To: "Rafael J . Wysocki" , Len Brown , Robert Moore , Lv Zheng , linux-acpi@vger.kernel.org, devel@acpica.org Cc: linux-kernel@vger.kernel.org Subject: [PATCH] tools/power/acpi: close file only if it is open Date: Fri, 18 Mar 2016 14:28:32 +0000 Message-Id: <1458311312-23330-1-git-send-email-colin.king@canonical.com> X-Mailer: git-send-email 2.7.3 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Colin Ian King 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 --- 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;