On Thu, Oct 29, 2026 at 11:45:40PM +0530, Arun Menon wrote: > From: Arun Menon <[email protected]> > > A later patch adds CRB chunking, which needs its own send/receive > loops alongside the existing single-shot transfer. Move the body of > crb_send() into tpm_crb_send_no_chunks() and the body of crb_recv() > into tpm_crb_recv_no_chunks(). > > Pure code motion, no behavior change. Also fix the block comment to the > kernel's preferred multi-line style. > > Signed-off-by: Arun Menon <[email protected]> > --- > drivers/char/tpm/tpm_crb.c | 71 ++++++++++++++++++++++++-------------- > 1 file changed, 45 insertions(+), 26 deletions(-) > > diff --git a/drivers/char/tpm/tpm_crb.c b/drivers/char/tpm/tpm_crb.c > index 30ca8192d3a8..f0bac9e1f1e8 100644 > --- a/drivers/char/tpm/tpm_crb.c > +++ b/drivers/char/tpm/tpm_crb.c > @@ -369,24 +369,13 @@ static u8 crb_status(struct tpm_chip *chip) > return sts; > } > > -static int crb_recv(struct tpm_chip *chip, u8 *buf, size_t count) > +static int tpm_crb_recv_no_chunks(struct tpm_chip *chip, u8 *buf, size_t > count) > { > struct crb_priv *priv = dev_get_drvdata(&chip->dev); > unsigned int expected; > > - /* A sanity check that the upper layer wants to get at least the header > - * as that is the minimum size for any TPM response. > - */ > - if (count < TPM_HEADER_SIZE) > - return -EIO; > - > - /* If this bit is set, according to the spec, the TPM is in > - * unrecoverable condition. > - */ > - if (ioread32(&priv->regs_t->ctrl_sts) & CRB_CTRL_STS_ERROR) > - return -EIO; > - > - /* Read the first 8 bytes in order to get the length of the response. > + /* > + * Read the first 8 bytes in order to get the length of the response. > * We read exactly a quad word in order to make sure that the remaining > * reads will be aligned. > */ > @@ -399,6 +388,28 @@ static int crb_recv(struct tpm_chip *chip, u8 *buf, > size_t count) > memcpy_fromio(&buf[8], &priv->rsp[8], expected - 8); > > return expected; > + > +} > + > +static int crb_recv(struct tpm_chip *chip, u8 *buf, size_t count) > +{ > + struct crb_priv *priv = dev_get_drvdata(&chip->dev); > + > + /* > + * A sanity check that the upper layer wants to get at least the header > + * as that is the minimum size for any TPM response. > + */ > + if (count < TPM_HEADER_SIZE) > + return -EIO; > + > + /* > + * If this bit is set, according to the spec, the TPM is in > + * unrecoverable condition. > + */ > + if (ioread32(&priv->regs_t->ctrl_sts) & CRB_CTRL_STS_ERROR) > + return -EIO; > + > + return tpm_crb_recv_no_chunks(chip, buf, count); > } > > static int crb_do_acpi_start(struct tpm_chip *chip) > @@ -474,12 +485,29 @@ static int tpm_crb_start(struct tpm_chip *chip, u32 > start_cmd) > return rc; > } > > -static int crb_send(struct tpm_chip *chip, u8 *buf, size_t bufsiz, size_t > len) > +static int tpm_crb_send_no_chunks(struct tpm_chip *chip, u8 *buf, size_t len) > { > struct crb_priv *priv = dev_get_drvdata(&chip->dev); > int rc = 0; > > - /* Zero the cancel register so that the next command will not get > + memcpy_toio(priv->cmd, buf, len); > + > + /* Make sure that cmd is populated before issuing start. */ > + wmb(); > + > + rc = tpm_crb_start(chip, CRB_START_INVOKE); > + if (rc) > + return rc; > + > + return crb_try_pluton_doorbell(priv, false); > +} > + > +static int crb_send(struct tpm_chip *chip, u8 *buf, size_t bufsiz, size_t > len) > +{ > + struct crb_priv *priv = dev_get_drvdata(&chip->dev); > + > + /* > + * Zero the cancel register so that the next command will not get > * canceled. > */ > iowrite32(0, &priv->regs_t->ctrl_cancel); > @@ -494,16 +522,7 @@ static int crb_send(struct tpm_chip *chip, u8 *buf, > size_t bufsiz, size_t len) > if (priv->sm == ACPI_TPM2_COMMAND_BUFFER_WITH_PLUTON) > __crb_cmd_ready(&chip->dev, priv, chip->locality); > > - memcpy_toio(priv->cmd, buf, len); > - > - /* Make sure that cmd is populated before issuing start. */ > - wmb(); > - > - rc = tpm_crb_start(chip, CRB_START_INVOKE); > - if (rc) > - return rc; > - > - return crb_try_pluton_doorbell(priv, false); > + return tpm_crb_send_no_chunks(chip, buf, len); > } > > static void crb_cancel(struct tpm_chip *chip) > -- > 2.56.0 >
Reviewed-by: Jarkko Sakkinen <[email protected]> Br, Jarkko
