[PATCH] tpm: Create cleanup class for tpm_buf
Jason Gunthorpe
jgg at ziepe.ca
Thu Jun 26 14:49:15 UTC 2025
On Thu, Jun 26, 2025 at 12:37:56AM +0300, Jarkko Sakkinen wrote:
> @@ -323,7 +323,7 @@ unsigned long tpm1_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal)
> */
> static int tpm1_startup(struct tpm_chip *chip)
> {
> - struct tpm_buf buf;
> + CLASS(tpm_buf, buf)();
> int rc;
>
> dev_info(&chip->dev, "starting up the TPM manually\n");
> @@ -335,7 +335,6 @@ static int tpm1_startup(struct tpm_chip *chip)
> tpm_buf_append_u16(&buf, TPM_ST_CLEAR);
>
> rc = tpm_transmit_cmd(chip, &buf, 0, "attempting to start the TPM");
> - tpm_buf_destroy(&buf);
> return rc;
> }
So, Linus has spoken negatively about just converting existing code to
use cleanup.h, fearful it would introduce more bugs.
I would certainly split this into more patches, and it would be nice
if something mechanical like coccinelle could do the change.
At least I would add the class and drop the tpm_buf_destroy() as one
patch, and another would be to cleanup any empty gotos.
Also, I think the style guide for cleanup.h is to not use the
variable block, so it should be more like:
CLASS(tpm_buf, buf)();
if (!tpm_buf)
return -ENOMEM;
AFAICT, but that seems to be some kind of tribal knowledge.
Jason
More information about the Linux-security-module-archive
mailing list