Re: [PATCH v3 4/6] tpm: Support TPM2 sized buffers (TPM2B)

From
Jarkko Sakkinen <jarkko@kernel.org>
Date
2023-11-06 03:25:26
Also in
keyrings, linux-integrity, lkml
On Fri, 2023-10-27 at 08:32 -0400, James Bottomley wrote:
On Tue, 2023-10-24 at 04:15 +0300, Jarkko Sakkinen wrote:
quoted
+++ b/drivers/char/tpm/tpm-buf.c
@@ -7,22 +7,32 @@
 #include <linux/tpm.h>
 
 /**
- * tpm_buf_init() - Initialize from the heap
+ * tpm_buf_init() - Initialize a TPM buffer
  * @buf:       A @tpm_buf
+ * @sized:     Represent a sized buffer (TPM2B)
+ * @alloc:     Allocate from the heap
  *
  * Initialize all structure fields to zero, allocate a page from the
heap, and
  * zero the bytes that the buffer headers will consume.
  *
  * Return: 0 or -ENOMEM
  */
-int tpm_buf_init(struct tpm_buf *buf)
+int tpm_buf_init(struct tpm_buf *buf, bool alloc, bool sized)
I think it creates a phenomenally confusing interface to use multiple
booleans because, unlike flags, it's not self describing at point of
use.  The confusion is enormously heightened here by having the doc
book arguments be the reverse of the actual function prototype (I just
tripped over this).

The alloc flag is particularly counter intuitive: if you pass in an
allocated buffer, you expect to be responsible for freeing it again,
but that's not how you use it; you really use it like a reset not an
alloc, which looks odd because you already created a separate
tpm_buf_reset function which can't be used in this case.

Why not replace the alloc flags with two reset functions: one for TPM2B
buffers and one for command buffers?

James
Or you can make that as internal (__tpm_buf_init()) and add two
wrappers.

BR, Jarkko
Thread (1 message) 1 message, 1 author, last reply 2023-11-06
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help