From patchwork Sun Jul 31 15:20:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 12933123 X-Patchwork-Delegate: kieran@bingham.xyz Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AEBAFC00140 for ; Sun, 31 Jul 2022 15:20:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233771AbiGaPUk (ORCPT ); Sun, 31 Jul 2022 11:20:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232548AbiGaPUj (ORCPT ); Sun, 31 Jul 2022 11:20:39 -0400 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A26F7260D for ; Sun, 31 Jul 2022 08:20:38 -0700 (PDT) Received: from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 2B1086D4; Sun, 31 Jul 2022 17:20:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1659280837; bh=GdbhRD+IZtalaTcAijl8rQrM63Eq773gcNvZ0V2Us3c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YCx1xvCejOgxWFV0uFz8n4OaiZH1+5+nOgTXEaMQ05TZOMY1mPGkM9UfHm5NuBYIF WMp9YjrZ5wUyhNjU+lb9EWgAtFPssWnNO8aHcBRSOATH0xels8WBPVPp5o3jpRQw5B ZKR0h33c6OazGrc2P5Rtp4Iwgt2eZi4XJHT0Tfj0= From: Laurent Pinchart To: linux-renesas-soc@vger.kernel.org Cc: Kieran Bingham Subject: [kms-test] [PATCH 4/7] kmstest: Fix exception handling in CRCReader constructor and destructor Date: Sun, 31 Jul 2022 18:20:21 +0300 Message-Id: <20220731152024.24090-5-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220731152024.24090-1-laurent.pinchart@ideasonboard.com> References: <20220731152024.24090-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org If an exception occurs in the CRCReader constructor, the self.dir, self.ctrl and self.data members may not be set. This causes another exception to be thrown by the destructor when it tries to access those members. Fix it by initializing all the members first, and only closing the dir and ctrl file descriptors if they have been successfully opened. Signed-off-by: Laurent Pinchart --- tests/kmstest.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/kmstest.py b/tests/kmstest.py index 177110ebd894..960c27f301ce 100755 --- a/tests/kmstest.py +++ b/tests/kmstest.py @@ -168,17 +168,21 @@ class CRCReader(object): def __init__(self, crtc): self.pipe = crtc.idx + self.ctrl = -1 + self.dir = -1 + self.data = -1 # Hardcode the device minor to 0 as the KMSTest constructor opens the # default card object. self.dir = os.open(f'/sys/kernel/debug/dri/0/crtc-{self.pipe}/crc', 0) self.ctrl = os.open('control', os.O_WRONLY, dir_fd = self.dir) - self.data = -1 def __del__(self): self.stop() - os.close(self.ctrl) - os.close(self.dir) + if self.ctrl != -1: + os.close(self.ctrl) + if self.dir != -1: + os.close(self.dir) def start(self, source): os.write(self.ctrl, source.encode('ascii'))