Re: [PATCH v2] tpm: Cleanup class for tpm_buf

From: James Bottomley
Date: Thu Jun 26 2025 - 11:02:51 EST


On Thu, 2025-06-26 at 13:19 +0300, Jarkko Sakkinen wrote:
> From: Jarkko Sakkinen <jarkko.sakkinen@xxxxxxxxxxx>
>
> Create a cleanup class for struct tpm_buf using DEFINE_CLASS(), which
> will guarantee that the heap allocated memory will be freed
> automatically for the transient instances of this structure, when
> they go out of scope.
>
> Wrap this all into help macro CLASS_TPM_BUF().
>
> A TPM buffer can now be declared trivially:
>
>     CLASS_TPM_BUF(buf, buf_size);

Well, that's not all ... you're also adding a size to the API that we
didn't have before, which should at least be documented in the commit
message and probably be a separate patch.

What is the reason for this, though? The reason we currently use a
page is that it's easy for the OS to manage (no slab fragmentation
issues). The TCG reference platform defines this to be just under 4k
(actually 4096-0x80) precisely because TPM implementations don't do
scatter gather, so they don't want it going over an ARM page, so
there's no danger of us ever needing more than a page.

Regards,

James