Re: [PATCH] tpm: Create cleanup class for tpm_buf
From: Jason Gunthorpe <jgg@ziepe.ca>
Date: 2025-06-26 14:49:18
Also in:
keyrings, linux-integrity, lkml
From: Jason Gunthorpe <jgg@ziepe.ca>
Date: 2025-06-26 14:49:18
Also in:
keyrings, linux-integrity, lkml
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