Re: [PATCH v3 2/5] tpm_crb: refactor check for idle support into TPM into inline function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Feb 13, 2025 at 06:27:42PM -0600, Stuart Yoder wrote:
> Refactor the two checks for whether the TPM supports idle into a single
> inline function.
> 
> Signed-off-by: Stuart Yoder <stuart.yoder@xxxxxxx>
> ---
>  drivers/char/tpm/tpm_crb.c | 18 ++++++++++++------
>  1 file changed, 12 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/char/tpm/tpm_crb.c b/drivers/char/tpm/tpm_crb.c
> index ea085b14ab7c..d696226906a2 100644
> --- a/drivers/char/tpm/tpm_crb.c
> +++ b/drivers/char/tpm/tpm_crb.c
> @@ -115,6 +115,16 @@ struct tpm2_crb_pluton {
>  	u64 reply_addr;
>  };
>  
> +static inline bool tpm_crb_has_idle(u32 start_method)
> +{
> +	if ((start_method == ACPI_TPM2_START_METHOD) ||

Unnecessary parentheses in each condition.

> +	    (start_method == ACPI_TPM2_COMMAND_BUFFER_WITH_START_METHOD) ||
> +	    (start_method == ACPI_TPM2_COMMAND_BUFFER_WITH_ARM_SMC))
> +		return false;
> +	else
> +		return true;
> +}

Could be just plain

/*
 * Returns true, if the start method supports idle.
 */
static inline bool tpm_crb_has_idle(u32 start_method)
{
	return start_method == ACPI_TPM2_START_METHOD ||
	       start_method == ACPI_TPM2_COMMAND_BUFFER_WITH_START_METHOD ||
	       start_method == ACPI_TPM2_COMMAND_BUFFER_WITH_ARM_SMC;
}

> +
>  static bool crb_wait_for_reg_32(u32 __iomem *reg, u32 mask, u32 value,
>  				unsigned long timeout)
>  {
> @@ -173,9 +183,7 @@ static int __crb_go_idle(struct device *dev, struct crb_priv *priv)
>  {
>  	int rc;
>  
> -	if ((priv->sm == ACPI_TPM2_START_METHOD) ||
> -	    (priv->sm == ACPI_TPM2_COMMAND_BUFFER_WITH_START_METHOD) ||
> -	    (priv->sm == ACPI_TPM2_COMMAND_BUFFER_WITH_ARM_SMC))

Right, those parentheses come from legacy code. Still, they should be
removed. Also with this afaik checkpatch.pl --strict should give you
a complain.

> +	if (!tpm_crb_has_idle(priv->sm))
>  		return 0;
>  
>  	iowrite32(CRB_CTRL_REQ_GO_IDLE, &priv->regs_t->ctrl_req);
> @@ -222,9 +230,7 @@ static int __crb_cmd_ready(struct device *dev, struct crb_priv *priv)
>  {
>  	int rc;
>  
> -	if ((priv->sm == ACPI_TPM2_START_METHOD) ||
> -	    (priv->sm == ACPI_TPM2_COMMAND_BUFFER_WITH_START_METHOD) ||
> -	    (priv->sm == ACPI_TPM2_COMMAND_BUFFER_WITH_ARM_SMC))
> +	if (!tpm_crb_has_idle(priv->sm))
>  		return 0;
>  
>  	iowrite32(CRB_CTRL_REQ_CMD_READY, &priv->regs_t->ctrl_req);
> -- 
> 2.34.1
> 

BR, Jarkko




[Index of Archives]     [Linux IBM ACPI]     [Linux Power Management]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]     [Linux Resources]
  Powered by Linux