Skip to content

Commit f3d7ba9

Browse files
committed
tpm: Open code tpm_buf_parameters()
With only single call site, this makes no sense (slipped out of the radar during the review). Open code and document the action directly to the site, to make it more readable. Fixes: 1b6d7f9 ("tpm: add session encryption protection to tpm2_get_random()") Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
1 parent 195aba9 commit f3d7ba9

File tree

3 files changed

+9
-29
lines changed

3 files changed

+9
-29
lines changed

drivers/char/tpm/tpm-buf.c

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -223,30 +223,4 @@ u32 tpm_buf_read_u32(struct tpm_buf *buf, off_t *offset)
223223
}
224224
EXPORT_SYMBOL_GPL(tpm_buf_read_u32);
225225

226-
static u16 tpm_buf_tag(struct tpm_buf *buf)
227-
{
228-
struct tpm_header *head = (struct tpm_header *)buf->data;
229-
230-
return be16_to_cpu(head->tag);
231-
}
232-
233-
/**
234-
* tpm_buf_parameters - return the TPM response parameters area of the tpm_buf
235-
* @buf: tpm_buf to use
236-
*
237-
* Where the parameters are located depends on the tag of a TPM
238-
* command (it's immediately after the header for TPM_ST_NO_SESSIONS
239-
* or 4 bytes after for TPM_ST_SESSIONS). Evaluate this and return a
240-
* pointer to the first byte of the parameters area.
241-
*
242-
* @return: pointer to parameters area
243-
*/
244-
u8 *tpm_buf_parameters(struct tpm_buf *buf)
245-
{
246-
int offset = TPM_HEADER_SIZE;
247-
248-
if (tpm_buf_tag(buf) == TPM2_ST_SESSIONS)
249-
offset += 4;
250226

251-
return &buf->data[offset];
252-
}

drivers/char/tpm/tpm2-cmd.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,13 +281,15 @@ struct tpm2_get_random_out {
281281
int tpm2_get_random(struct tpm_chip *chip, u8 *dest, size_t max)
282282
{
283283
struct tpm2_get_random_out *out;
284+
struct tpm_header *head;
284285
struct tpm_buf buf;
285286
u32 recd;
286287
u32 num_bytes = max;
287288
int err;
288289
int total = 0;
289290
int retries = 5;
290291
u8 *dest_ptr = dest;
292+
off_t offset;
291293

292294
if (!num_bytes || max > TPM_MAX_RNG_DATA)
293295
return -EINVAL;
@@ -320,7 +322,13 @@ int tpm2_get_random(struct tpm_chip *chip, u8 *dest, size_t max)
320322
goto out;
321323
}
322324

323-
out = (struct tpm2_get_random_out *)tpm_buf_parameters(&buf);
325+
head = (struct tpm_header *)buf.data;
326+
offset = TPM_HEADER_SIZE;
327+
/* Skip the parameter size field: */
328+
if (be16_to_cpu(head->tag) == TPM2_ST_SESSIONS)
329+
offset += 4;
330+
331+
out = (struct tpm2_get_random_out *)&buf.data[offset];
324332
recd = min_t(u32, be16_to_cpu(out->size), num_bytes);
325333
if (tpm_buf_length(&buf) <
326334
TPM_HEADER_SIZE +

include/linux/tpm.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,8 +437,6 @@ u8 tpm_buf_read_u8(struct tpm_buf *buf, off_t *offset);
437437
u16 tpm_buf_read_u16(struct tpm_buf *buf, off_t *offset);
438438
u32 tpm_buf_read_u32(struct tpm_buf *buf, off_t *offset);
439439

440-
u8 *tpm_buf_parameters(struct tpm_buf *buf);
441-
442440
/*
443441
* Check if TPM device is in the firmware upgrade mode.
444442
*/

0 commit comments

Comments
 (0)