]> asedeno.scripts.mit.edu Git - linux.git/blobdiff - drivers/char/tpm/tpm2-space.c
tpm: clean up tpm_try_transmit() error handling flow
[linux.git] / drivers / char / tpm / tpm2-space.c
index 1131a8e7b79ba76493cf4b3a7765e9dcc561708a..5d6487575074147684571681b0e6390bf2285407 100644 (file)
@@ -162,7 +162,7 @@ static int tpm2_save_context(struct tpm_chip *chip, u32 handle, u8 *buf,
        return 0;
 }
 
-static void tpm2_flush_space(struct tpm_chip *chip)
+void tpm2_flush_space(struct tpm_chip *chip)
 {
        struct tpm_space *space = &chip->work_space;
        int i;
@@ -334,7 +334,7 @@ static int tpm2_map_response_header(struct tpm_chip *chip, u32 cc, u8 *rsp,
                                    size_t len)
 {
        struct tpm_space *space = &chip->work_space;
-       struct tpm_output_header *header = (void *)rsp;
+       struct tpm_header *header = (struct tpm_header *)rsp;
        u32 phandle;
        u32 phandle_type;
        u32 vhandle;
@@ -394,7 +394,7 @@ static int tpm2_map_response_body(struct tpm_chip *chip, u32 cc, u8 *rsp,
                                  size_t len)
 {
        struct tpm_space *space = &chip->work_space;
-       struct tpm_output_header *header = (void *)rsp;
+       struct tpm_header *header = (struct tpm_header *)rsp;
        struct tpm2_cap_handles *data;
        u32 phandle;
        u32 phandle_type;
@@ -490,9 +490,9 @@ static int tpm2_save_space(struct tpm_chip *chip)
 }
 
 int tpm2_commit_space(struct tpm_chip *chip, struct tpm_space *space,
-                     u32 cc, u8 *buf, size_t *bufsiz)
+                     u32 cc, void *buf, size_t *bufsiz)
 {
-       struct tpm_output_header *header = (void *)buf;
+       struct tpm_header *header = buf;
        int rc;
 
        if (!space)
@@ -501,19 +501,19 @@ int tpm2_commit_space(struct tpm_chip *chip, struct tpm_space *space,
        rc = tpm2_map_response_header(chip, cc, buf, *bufsiz);
        if (rc) {
                tpm2_flush_space(chip);
-               return rc;
+               goto out;
        }
 
        rc = tpm2_map_response_body(chip, cc, buf, *bufsiz);
        if (rc) {
                tpm2_flush_space(chip);
-               return rc;
+               goto out;
        }
 
        rc = tpm2_save_space(chip);
        if (rc) {
                tpm2_flush_space(chip);
-               return rc;
+               goto out;
        }
 
        *bufsiz = be32_to_cpu(header->length);
@@ -526,4 +526,7 @@ int tpm2_commit_space(struct tpm_chip *chip, struct tpm_space *space,
        memcpy(space->session_buf, chip->work_space.session_buf, PAGE_SIZE);
 
        return 0;
+out:
+       dev_err(&chip->dev, "%s: error %d\n", __func__, rc);
+       return rc;
 }