]> 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 d2e101b32482f83ca85c2ca5c0f5cac85f46efe5..5d6487575074147684571681b0e6390bf2285407 100644 (file)
@@ -83,7 +83,7 @@ static int tpm2_load_context(struct tpm_chip *chip, u8 *buf,
        body_size = sizeof(*ctx) + be16_to_cpu(ctx->blob_size);
        tpm_buf_append(&tbuf, &buf[*offset], body_size);
 
-       rc = tpm_transmit_cmd(chip, NULL, tbuf.data, PAGE_SIZE, 4,
+       rc = tpm_transmit_cmd(chip, NULL, &tbuf, 4,
                              TPM_TRANSMIT_NESTED, NULL);
        if (rc < 0) {
                dev_warn(&chip->dev, "%s: failed with a system error %d\n",
@@ -132,7 +132,7 @@ static int tpm2_save_context(struct tpm_chip *chip, u32 handle, u8 *buf,
 
        tpm_buf_append_u32(&tbuf, handle);
 
-       rc = tpm_transmit_cmd(chip, NULL, tbuf.data, PAGE_SIZE, 0,
+       rc = tpm_transmit_cmd(chip, NULL, &tbuf, 0,
                              TPM_TRANSMIT_NESTED, NULL);
        if (rc < 0) {
                dev_warn(&chip->dev, "%s: failed with a system error %d\n",
@@ -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;
@@ -373,7 +373,7 @@ static int tpm2_map_response_header(struct tpm_chip *chip, u32 cc, u8 *rsp,
                dev_err(&chip->dev, "%s: unknown handle 0x%08X\n",
                        __func__, phandle);
                break;
-       };
+       }
 
        return 0;
 out_no_slots:
@@ -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;
 }