Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: 1b6d7f9eb150 ("tpm: add session encryption protection to tpm2_get_random()")
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>

+9 -29
-26
drivers/char/tpm/tpm-buf.c
··· 223 223 } 224 224 EXPORT_SYMBOL_GPL(tpm_buf_read_u32); 225 225 226 - static u16 tpm_buf_tag(struct tpm_buf *buf) 227 - { 228 - struct tpm_header *head = (struct tpm_header *)buf->data; 229 226 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; 250 - 251 - return &buf->data[offset]; 252 - }
+9 -1
drivers/char/tpm/tpm2-cmd.c
··· 281 281 int tpm2_get_random(struct tpm_chip *chip, u8 *dest, size_t max) 282 282 { 283 283 struct tpm2_get_random_out *out; 284 + struct tpm_header *head; 284 285 struct tpm_buf buf; 285 286 u32 recd; 286 287 u32 num_bytes = max; ··· 289 288 int total = 0; 290 289 int retries = 5; 291 290 u8 *dest_ptr = dest; 291 + off_t offset; 292 292 293 293 if (!num_bytes || max > TPM_MAX_RNG_DATA) 294 294 return -EINVAL; ··· 322 320 goto out; 323 321 } 324 322 325 - out = (struct tpm2_get_random_out *)tpm_buf_parameters(&buf); 323 + head = (struct tpm_header *)buf.data; 324 + offset = TPM_HEADER_SIZE; 325 + /* Skip the parameter size field: */ 326 + if (be16_to_cpu(head->tag) == TPM2_ST_SESSIONS) 327 + offset += 4; 328 + 329 + out = (struct tpm2_get_random_out *)&buf.data[offset]; 326 330 recd = min_t(u32, be16_to_cpu(out->size), num_bytes); 327 331 if (tpm_buf_length(&buf) < 328 332 TPM_HEADER_SIZE +
-2
include/linux/tpm.h
··· 437 437 u16 tpm_buf_read_u16(struct tpm_buf *buf, off_t *offset); 438 438 u32 tpm_buf_read_u32(struct tpm_buf *buf, off_t *offset); 439 439 440 - u8 *tpm_buf_parameters(struct tpm_buf *buf); 441 - 442 440 /* 443 441 * Check if TPM device is in the firmware upgrade mode. 444 442 */