All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jarkko Sakkinen <jarkko@kernel.org>
To: tpm-protocol@lists.linux.dev
Cc: Jarkko Sakkinen <jarkko@kernel.org>
Subject: [PATCH] refactor!(TpmRc): remove unnecessary Result wrapper
Date: Sun, 31 Aug 2025 12:54:44 +0300	[thread overview]
Message-ID: <20250831095444.54784-1-jarkko@kernel.org> (raw)

`Result` wrapper in the return value of `TpmRc::base()` exists only to
retain API backwards compatibility in 0.10.x branch. Remove the wrapper
in the main branch.

Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
---
 src/data/tpm_rc.rs | 20 +++++++-------------
 tests/runner.rs    |  2 +-
 2 files changed, 8 insertions(+), 14 deletions(-)

diff --git a/src/data/tpm_rc.rs b/src/data/tpm_rc.rs
index c7fa71a..fa8756f 100644
--- a/src/data/tpm_rc.rs
+++ b/src/data/tpm_rc.rs
@@ -165,12 +165,9 @@ pub struct TpmRc {
 impl TpmRc {
     /// Returns the base error code, with handle, parameter, or session index
     /// stripped out.
-    ///
-    /// # Errors
-    ///
-    /// This method returns a `Result` in order to retain API compatibility.
-    pub fn base(self) -> Result<TpmRcBase, TpmErrorKind> {
-        Ok(self.base)
+    #[must_use]
+    pub fn base(self) -> TpmRcBase {
+        self.base
     }
 
     #[must_use]
@@ -250,14 +247,11 @@ impl From<TpmRcBase> for TpmRc {
 
 impl Display for TpmRc {
     fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
-        if let Ok(base) = self.base() {
-            if let Some(index) = self.index() {
-                write!(f, "[{base}, {index}]")
-            } else {
-                write!(f, "{base}")
-            }
+        let base = self.base();
+        if let Some(index) = self.index() {
+            write!(f, "[{base}, {index}]")
         } else {
-            write!(f, "TPM_RC_UNKNOWN(0x{:08X})", self.value())
+            write!(f, "{base}")
         }
     }
 }
diff --git a/tests/runner.rs b/tests/runner.rs
index 83fc209..218d813 100644
--- a/tests/runner.rs
+++ b/tests/runner.rs
@@ -239,7 +239,7 @@ fn test_tpm_rc_base_from_raw() {
 
     for (description, raw_rc, expected_base) in cases {
         let rc = TpmRc::try_from(raw_rc).unwrap();
-        assert_eq!(rc.base(), Ok(expected_base), "{description}");
+        assert_eq!(rc.base(), expected_base, "{description}");
     }
 }
 
-- 
2.39.5


             reply	other threads:[~2025-08-31  9:54 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-31  9:54 Jarkko Sakkinen [this message]
2025-08-31 13:12 ` [PATCH] refactor!(TpmRc): remove unnecessary Result wrapper Jarkko Sakkinen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250831095444.54784-1-jarkko@kernel.org \
    --to=jarkko@kernel.org \
    --cc=tpm-protocol@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.