extern struct idr dev_nums_idr;
 
 ssize_t tpm_transmit(struct tpm_chip *chip, u8 *buf, size_t bufsiz);
-ssize_t tpm_transmit_cmd(struct tpm_chip *chip, struct tpm_buf *buf,
-                        size_t min_rsp_body_length, const char *desc);
 int tpm_get_timeouts(struct tpm_chip *);
 int tpm_auto_startup(struct tpm_chip *chip);
 
 int tpm_chip_start(struct tpm_chip *chip);
 void tpm_chip_stop(struct tpm_chip *chip);
 struct tpm_chip *tpm_find_get_ops(struct tpm_chip *chip);
-__must_check int tpm_try_get_ops(struct tpm_chip *chip);
-void tpm_put_ops(struct tpm_chip *chip);
 
 struct tpm_chip *tpm_chip_alloc(struct device *dev,
                                const struct tpm_class_ops *ops);
 
 #if defined(CONFIG_TCG_TPM) || defined(CONFIG_TCG_TPM_MODULE)
 
 extern int tpm_is_tpm2(struct tpm_chip *chip);
+extern __must_check int tpm_try_get_ops(struct tpm_chip *chip);
+extern void tpm_put_ops(struct tpm_chip *chip);
+extern ssize_t tpm_transmit_cmd(struct tpm_chip *chip, struct tpm_buf *buf,
+                               size_t min_rsp_body_length, const char *desc);
 extern int tpm_pcr_read(struct tpm_chip *chip, u32 pcr_idx,
                        struct tpm_digest *digest);
 extern int tpm_pcr_extend(struct tpm_chip *chip, u32 pcr_idx,
 {
        return -ENODEV;
 }
-
 static inline int tpm_pcr_read(struct tpm_chip *chip, int pcr_idx,
                               struct tpm_digest *digest)
 {
 
        if (rc)
                return rc;
 
+       rc = tpm_buf_init(&buf, TPM2_ST_SESSIONS, TPM2_CC_CREATE);
+       if (rc) {
+               tpm_put_ops(chip);
+               return rc;
+       }
+
        tpm_buf_append_u32(&buf, options->keyhandle);
        tpm2_buf_append_auth(&buf, TPM2_RS_PW,
                             NULL /* nonce */, 0,
                goto out;
        }
 
-       rc = tpm_send(chip, buf.data, tpm_buf_length(&buf));
+       rc = tpm_transmit_cmd(chip, &buf, 4, "sealing data");
        if (rc)
                goto out;
 
                        rc = -EPERM;
        }
 
+       tpm_put_ops(chip);
        return rc;
 }
 
                goto out;
        }
 
-       rc = tpm_send(chip, buf.data, tpm_buf_length(&buf));
+       rc = tpm_transmit_cmd(chip, &buf, 4, "loading blob");
        if (!rc)
                *blob_handle = be32_to_cpup(
                        (__be32 *) &buf.data[TPM_HEADER_SIZE]);
                             options->blobauth /* hmac */,
                             TPM_DIGEST_SIZE);
 
-       rc = tpm_send(chip, buf.data, tpm_buf_length(&buf));
+       rc = tpm_transmit_cmd(chip, &buf, 6, "unsealing");
        if (rc > 0)
                rc = -EPERM;
 
        u32 blob_handle;
        int rc;
 
-       rc = tpm2_load_cmd(chip, payload, options, &blob_handle);
+       rc = tpm_try_get_ops(chip);
        if (rc)
                return rc;
 
+       rc = tpm2_load_cmd(chip, payload, options, &blob_handle);
+       if (rc)
+               goto out;
+
        rc = tpm2_unseal_cmd(chip, payload, options, blob_handle);
        tpm2_flush_context(chip, blob_handle);
 
+out:
+       tpm_put_ops(chip);
+
        return rc;
 }