Skip to content

Commit b34b77a

Browse files
author
Jarkko Sakkinen
committed
tpm: declare struct tpm_header
Declare struct tpm_header that replaces struct tpm_input_header and struct tpm_output_header. Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> Reviewed-by: Stefan Berger <stefanb@linux.ibm.com> Tested-by: Stefan Berger <stefanb@linux.ibm.com> Reviewed-by: Jerry Snitselaar <jsnitsel@redhat.com> Reviewed-by: James Bottomley <James.Bottomley@HansenPartnership.com> Tested-by: Alexander Steffen <Alexander.Steffen@infineon.com>
1 parent aff0c20 commit b34b77a

File tree

7 files changed

+34
-43
lines changed

7 files changed

+34
-43
lines changed

drivers/char/tpm/tpm-interface.c

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,10 @@ unsigned long tpm_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal)
6262
}
6363
EXPORT_SYMBOL_GPL(tpm_calc_ordinal_duration);
6464

65-
static int tpm_validate_command(struct tpm_chip *chip,
66-
struct tpm_space *space,
67-
const u8 *cmd,
68-
size_t len)
65+
static int tpm_validate_command(struct tpm_chip *chip, struct tpm_space *space,
66+
const void *cmd, size_t len)
6967
{
70-
const struct tpm_input_header *header = (const void *)cmd;
68+
const struct tpm_header *header = cmd;
7169
int i;
7270
u32 cc;
7371
u32 attrs;
@@ -161,12 +159,10 @@ static int tpm_go_idle(struct tpm_chip *chip, unsigned int flags)
161159
return chip->ops->go_idle(chip);
162160
}
163161

164-
static ssize_t tpm_try_transmit(struct tpm_chip *chip,
165-
struct tpm_space *space,
166-
u8 *buf, size_t bufsiz,
167-
unsigned int flags)
162+
static ssize_t tpm_try_transmit(struct tpm_chip *chip, struct tpm_space *space,
163+
void *buf, size_t bufsiz, unsigned int flags)
168164
{
169-
struct tpm_output_header *header = (void *)buf;
165+
struct tpm_header *header = buf;
170166
int rc;
171167
ssize_t len = 0;
172168
u32 count, ordinal;
@@ -325,7 +321,7 @@ static ssize_t tpm_try_transmit(struct tpm_chip *chip,
325321
ssize_t tpm_transmit(struct tpm_chip *chip, struct tpm_space *space,
326322
u8 *buf, size_t bufsiz, unsigned int flags)
327323
{
328-
struct tpm_output_header *header = (struct tpm_output_header *)buf;
324+
struct tpm_header *header = (struct tpm_header *)buf;
329325
/* space for header and handles */
330326
u8 save[TPM_HEADER_SIZE + 3*sizeof(u32)];
331327
unsigned int delay_msec = TPM2_DURATION_SHORT;
@@ -390,8 +386,7 @@ ssize_t tpm_transmit_cmd(struct tpm_chip *chip, struct tpm_space *space,
390386
struct tpm_buf *buf, size_t min_rsp_body_length,
391387
unsigned int flags, const char *desc)
392388
{
393-
const struct tpm_output_header *header =
394-
(struct tpm_output_header *)buf->data;
389+
const struct tpm_header *header = (struct tpm_header *)buf->data;
395390
int err;
396391
ssize_t len;
397392

drivers/char/tpm/tpm.h

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -273,16 +273,13 @@ struct tpm_chip {
273273

274274
#define to_tpm_chip(d) container_of(d, struct tpm_chip, dev)
275275

276-
struct tpm_input_header {
277-
__be16 tag;
278-
__be32 length;
279-
__be32 ordinal;
280-
} __packed;
281-
282-
struct tpm_output_header {
283-
__be16 tag;
284-
__be32 length;
285-
__be32 return_code;
276+
struct tpm_header {
277+
__be16 tag;
278+
__be32 length;
279+
union {
280+
__be32 ordinal;
281+
__be32 return_code;
282+
};
286283
} __packed;
287284

288285
#define TPM_TAG_RQU_COMMAND 193
@@ -401,8 +398,8 @@ struct tpm_buf {
401398

402399
static inline void tpm_buf_reset(struct tpm_buf *buf, u16 tag, u32 ordinal)
403400
{
404-
struct tpm_input_header *head;
405-
head = (struct tpm_input_header *)buf->data;
401+
struct tpm_header *head = (struct tpm_header *)buf->data;
402+
406403
head->tag = cpu_to_be16(tag);
407404
head->length = cpu_to_be32(sizeof(*head));
408405
head->ordinal = cpu_to_be32(ordinal);
@@ -428,14 +425,14 @@ static inline void tpm_buf_destroy(struct tpm_buf *buf)
428425

429426
static inline u32 tpm_buf_length(struct tpm_buf *buf)
430427
{
431-
struct tpm_input_header *head = (struct tpm_input_header *) buf->data;
428+
struct tpm_header *head = (struct tpm_header *)buf->data;
432429

433430
return be32_to_cpu(head->length);
434431
}
435432

436433
static inline u16 tpm_buf_tag(struct tpm_buf *buf)
437434
{
438-
struct tpm_input_header *head = (struct tpm_input_header *) buf->data;
435+
struct tpm_header *head = (struct tpm_header *)buf->data;
439436

440437
return be16_to_cpu(head->tag);
441438
}
@@ -444,7 +441,7 @@ static inline void tpm_buf_append(struct tpm_buf *buf,
444441
const unsigned char *new_data,
445442
unsigned int new_len)
446443
{
447-
struct tpm_input_header *head = (struct tpm_input_header *) buf->data;
444+
struct tpm_header *head = (struct tpm_header *)buf->data;
448445
u32 len = tpm_buf_length(buf);
449446

450447
/* Return silently if overflow has already happened. */
@@ -582,7 +579,7 @@ void tpm2_del_space(struct tpm_chip *chip, struct tpm_space *space);
582579
int tpm2_prepare_space(struct tpm_chip *chip, struct tpm_space *space, u32 cc,
583580
u8 *cmd);
584581
int tpm2_commit_space(struct tpm_chip *chip, struct tpm_space *space,
585-
u32 cc, u8 *buf, size_t *bufsiz);
582+
u32 cc, void *buf, size_t *bufsiz);
586583

587584
int tpm_bios_log_setup(struct tpm_chip *chip);
588585
void tpm_bios_log_teardown(struct tpm_chip *chip);

drivers/char/tpm/tpm2-cmd.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ static int tpm2_do_selftest(struct tpm_chip *chip)
784784
*/
785785
int tpm2_probe(struct tpm_chip *chip)
786786
{
787-
struct tpm_output_header *out;
787+
struct tpm_header *out;
788788
struct tpm_buf buf;
789789
int rc;
790790

@@ -797,7 +797,7 @@ int tpm2_probe(struct tpm_chip *chip)
797797
rc = tpm_transmit_cmd(chip, NULL, &buf, 0, 0, NULL);
798798
/* We ignore TPM return codes on purpose. */
799799
if (rc >= 0) {
800-
out = (struct tpm_output_header *)buf.data;
800+
out = (struct tpm_header *)buf.data;
801801
if (be16_to_cpu(out->tag) == TPM2_ST_NO_SESSIONS)
802802
chip->flags |= TPM_CHIP_FLAG_TPM2;
803803
}

drivers/char/tpm/tpm2-space.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ static int tpm2_map_response_header(struct tpm_chip *chip, u32 cc, u8 *rsp,
334334
size_t len)
335335
{
336336
struct tpm_space *space = &chip->work_space;
337-
struct tpm_output_header *header = (void *)rsp;
337+
struct tpm_header *header = (struct tpm_header *)rsp;
338338
u32 phandle;
339339
u32 phandle_type;
340340
u32 vhandle;
@@ -394,7 +394,7 @@ static int tpm2_map_response_body(struct tpm_chip *chip, u32 cc, u8 *rsp,
394394
size_t len)
395395
{
396396
struct tpm_space *space = &chip->work_space;
397-
struct tpm_output_header *header = (void *)rsp;
397+
struct tpm_header *header = (struct tpm_header *)rsp;
398398
struct tpm2_cap_handles *data;
399399
u32 phandle;
400400
u32 phandle_type;
@@ -490,9 +490,9 @@ static int tpm2_save_space(struct tpm_chip *chip)
490490
}
491491

492492
int tpm2_commit_space(struct tpm_chip *chip, struct tpm_space *space,
493-
u32 cc, u8 *buf, size_t *bufsiz)
493+
u32 cc, void *buf, size_t *bufsiz)
494494
{
495-
struct tpm_output_header *header = (void *)buf;
495+
struct tpm_header *header = buf;
496496
int rc;
497497

498498
if (!space)

drivers/char/tpm/tpm_i2c_atmel.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ struct priv_data {
4646
/* This is the amount we read on the first try. 25 was chosen to fit a
4747
* fair number of read responses in the buffer so a 2nd retry can be
4848
* avoided in small message cases. */
49-
u8 buffer[sizeof(struct tpm_output_header) + 25];
49+
u8 buffer[sizeof(struct tpm_header) + 25];
5050
};
5151

5252
static int i2c_atmel_send(struct tpm_chip *chip, u8 *buf, size_t len)
@@ -80,8 +80,7 @@ static int i2c_atmel_recv(struct tpm_chip *chip, u8 *buf, size_t count)
8080
{
8181
struct priv_data *priv = dev_get_drvdata(&chip->dev);
8282
struct i2c_client *client = to_i2c_client(chip->dev.parent);
83-
struct tpm_output_header *hdr =
84-
(struct tpm_output_header *)priv->buffer;
83+
struct tpm_header *hdr = (struct tpm_header *)priv->buffer;
8584
u32 expected_len;
8685
int rc;
8786

drivers/char/tpm/tpm_vtpm_proxy.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,9 @@ static int vtpm_proxy_tpm_op_recv(struct tpm_chip *chip, u8 *buf, size_t count)
303303
static int vtpm_proxy_is_driver_command(struct tpm_chip *chip,
304304
u8 *buf, size_t count)
305305
{
306-
struct tpm_input_header *hdr = (struct tpm_input_header *)buf;
306+
struct tpm_header *hdr = (struct tpm_header *)buf;
307307

308-
if (count < sizeof(struct tpm_input_header))
308+
if (count < sizeof(struct tpm_header))
309309
return 0;
310310

311311
if (chip->flags & TPM_CHIP_FLAG_TPM2) {
@@ -401,7 +401,7 @@ static int vtpm_proxy_request_locality(struct tpm_chip *chip, int locality)
401401
{
402402
struct tpm_buf buf;
403403
int rc;
404-
const struct tpm_output_header *header;
404+
const struct tpm_header *header;
405405
struct proxy_dev *proxy_dev = dev_get_drvdata(&chip->dev);
406406

407407
if (chip->flags & TPM_CHIP_FLAG_TPM2)
@@ -426,7 +426,7 @@ static int vtpm_proxy_request_locality(struct tpm_chip *chip, int locality)
426426
goto out;
427427
}
428428

429-
header = (const struct tpm_output_header *)buf.data;
429+
header = (const struct tpm_header *)buf.data;
430430
rc = be32_to_cpu(header->return_code);
431431
if (rc)
432432
locality = -1;

drivers/char/tpm/xen-tpmfront.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ static int vtpm_send(struct tpm_chip *chip, u8 *buf, size_t count)
163163
wmb();
164164
notify_remote_via_evtchn(priv->evtchn);
165165

166-
ordinal = be32_to_cpu(((struct tpm_input_header*)buf)->ordinal);
166+
ordinal = be32_to_cpu(((struct tpm_header *)buf)->ordinal);
167167
duration = tpm_calc_ordinal_duration(chip, ordinal);
168168

169169
if (wait_for_tpm_stat(chip, VTPM_STATUS_IDLE, duration,

0 commit comments

Comments
 (0)