public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] selftests: tpm2: Implement class desstructor to close file descriptor
@ 2022-09-09 15:20 Stefan Berger
  2022-09-09 15:39 ` R Nageswara Sastry
  2022-09-20  4:31 ` Jarkko Sakkinen
  0 siblings, 2 replies; 4+ messages in thread
From: Stefan Berger @ 2022-09-09 15:20 UTC (permalink / raw)
  To: jarkko, linux-integrity
  Cc: peterhuewe, linux-kernel, linux-kselftest, skhan, Stefan Berger,
	Shuah Khan

From: Stefan Berger <stefanb@linux.ibm.com>

Implement a class destructor to close the open TPM file descriptor
and avoid the following error message:

 test_flush_context (tpm2_tests.SpaceTest) ... \
   /usr/lib64/python3.6/unittest/case.py:605: ResourceWarning: \
   unclosed file <_io.FileIO name='/dev/tpmrm0' mode='rb+' closefd=True>

Fixes: 6ea3dfe1e0732 ("selftests: add TPM 2.0 tests")
Cc: Shuah Khan <shuah@kernel.org>
Cc: linux-kselftest@vger.kernel.org
Cc: Jarkko Sakkinen <jarkko@kernel.org>
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>

---
 tools/testing/selftests/tpm2/tpm2.py | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/tools/testing/selftests/tpm2/tpm2.py b/tools/testing/selftests/tpm2/tpm2.py
index 057a4f49c79d..c7363c6764fc 100644
--- a/tools/testing/selftests/tpm2/tpm2.py
+++ b/tools/testing/selftests/tpm2/tpm2.py
@@ -371,6 +371,10 @@ class Client:
             fcntl.fcntl(self.tpm, fcntl.F_SETFL, flags)
             self.tpm_poll = select.poll()
 
+    def __del__(self):
+        if self.tpm:
+            self.tpm.close()
+
     def close(self):
         self.tpm.close()
 
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-09-20 13:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-09 15:20 [PATCH] selftests: tpm2: Implement class desstructor to close file descriptor Stefan Berger
2022-09-09 15:39 ` R Nageswara Sastry
2022-09-20  4:31 ` Jarkko Sakkinen
2022-09-20 13:14   ` Stefan Berger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox