Re: [PATCH 1/1] trusted-keys: match tpm_get_ops on all return paths
From: Ben Boeckel
Date: Thu Apr 29 2021 - 15:03:28 EST
On Thu, Apr 29, 2021 at 11:50:50 -0700, James Bottomley wrote:
> Actually, I think this is a better fix to avoid multiple put and
> returns.
>
> James
>
> ---
>
> diff --git a/security/keys/trusted-keys/trusted_tpm2.c b/security/keys/trusted-keys/trusted_tpm2.c
> index d225ad140960..cbf2a932577b 100644
> --- a/security/keys/trusted-keys/trusted_tpm2.c
> +++ b/security/keys/trusted-keys/trusted_tpm2.c
> @@ -336,9 +336,9 @@ int tpm2_seal_trusted(struct tpm_chip *chip,
> rc = -EPERM;
> }
> if (blob_len < 0)
> - return blob_len;
> -
> - payload->blob_len = blob_len;
> + rc = blob_len;
> + else
> + payload->blob_len = blob_len;
>
> tpm_put_ops(chip);
> return rc;
Ah, that does look better. I had first added a new label, but that
didn't seem like an improvement in readability. I grabbed this pattern
from an early return earlier in the function. But given that this is the
end (and appears to be unlikely to have more logic inserted in the
future), this seems more reasonable to me as well. Do you want me to
respin or just let it up to you at this point?
Thanks,
--Ben