All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jarkko Sakkinen <jarkko@kernel.org>
To: Jason Gunthorpe <jgg@ziepe.ca>
Cc: linux-kernel@vger.kernel.org, keyrings@vger.kernel.org,
	Jarkko Sakkinen <jarkko.sakkinen@opinsys.com>,
	Peter Huewe <peterhuewe@gmx.de>,
	James Bottomley <James.Bottomley@hansenpartnership.com>,
	Mimi Zohar <zohar@linux.ibm.com>,
	David Howells <dhowells@redhat.com>,
	Paul Moore <paul@paul-moore.com>,
	James Morris <jmorris@namei.org>,
	"Serge E. Hallyn" <serge@hallyn.com>,
	"open list:TPM DEVICE DRIVER" <linux-integrity@vger.kernel.org>,
	"open list:SECURITY SUBSYSTEM"
	<linux-security-module@vger.kernel.org>
Subject: Re: [PATCH] tpm: Create cleanup class for tpm_buf
Date: Thu, 26 Jun 2025 21:24:44 +0300	[thread overview]
Message-ID: <aF2QbDmxzGJS903j@kernel.org> (raw)
In-Reply-To: <20250626144915.GD213144@ziepe.ca>

On Thu, Jun 26, 2025 at 11:49:15AM -0300, Jason Gunthorpe wrote:
> 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 did not do this for the sake of conversion. It's just that tpm_buf is
a pretty good fit for such construct, as it is always in function scope
and always heap allocated.

> I would certainly split this into more patches, and it would be nice
> if something mechanical like coccinelle could do the change.

I took this a bit in further:

https://lore.kernel.org/linux-integrity/aF2NNHilFfZwBoxA@kernel.org/T/#t

I did that few dozen times while developing this, running always at
minimum:

1. https://codeberg.org/jarkko/linux-tpmdd-test/src/branch/main/board/pc_x86_64/test_tpm2_kselftest.exp.in
2. https://codeberg.org/jarkko/linux-tpmdd-test/src/branch/main/board/pc_x86_64/test_tpm2_trusted.exp.in

A few times I run some ad-hoc tests too.

And despite 89% is mechanical work there was at least a dozen code
blocks where you need to understand the context too. So actually with
this careful manual work was not that bad idea in the end.

> 
> 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.

This was improved in v2 :-) If you have some proposal how you'd
liked that version to be splitted, please give feedback.
> 
> Jason


BR, Jarkko

  reply	other threads:[~2025-06-26 18:24 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-25 21:37 [PATCH] tpm: Create cleanup class for tpm_buf Jarkko Sakkinen
2025-06-25 21:45 ` Jarkko Sakkinen
2025-06-26 14:49 ` Jason Gunthorpe
2025-06-26 18:24   ` Jarkko Sakkinen [this message]
2025-06-26 22:33     ` Jarkko Sakkinen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aF2QbDmxzGJS903j@kernel.org \
    --to=jarkko@kernel.org \
    --cc=James.Bottomley@hansenpartnership.com \
    --cc=dhowells@redhat.com \
    --cc=jarkko.sakkinen@opinsys.com \
    --cc=jgg@ziepe.ca \
    --cc=jmorris@namei.org \
    --cc=keyrings@vger.kernel.org \
    --cc=linux-integrity@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=paul@paul-moore.com \
    --cc=peterhuewe@gmx.de \
    --cc=serge@hallyn.com \
    --cc=zohar@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.