]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
tpm: add bufsiz parameter in the .send callback
authorStefano Garzarella <sgarzare@redhat.com>
Fri, 20 Jun 2025 13:08:07 +0000 (15:08 +0200)
committerJarkko Sakkinen <jarkko@kernel.org>
Tue, 22 Jul 2025 23:23:18 +0000 (02:23 +0300)
Add a new `bufsiz` parameter to the `.send` callback in `tpm_class_ops`.
This parameter will allow drivers to differentiate between the actual
command length to send and the total buffer size. Currently `bufsiz` is
not used, but it will be used to implement devices with synchronous send()
to send the command and receive the response on the same buffer.

Also rename the previous parameter `len` to `cmd_len` in the declaration
to make it clear that it contains the length in bytes of the command
stored in the buffer. The semantics don't change and it can be used as
before by drivers. This is an optimization since the drivers could get it
from the header, but let's avoid duplicating code.

While we are here, resolve a checkpatch warning:
  WARNING: Unnecessary space before function pointer arguments
  #66: FILE: include/linux/tpm.h:90:
  + int (*send) (struct tpm_chip *chip, u8 *buf, size_t bufsiz,

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
Suggested-by: Jarkko Sakkinen <jarkko@kernel.org>
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
17 files changed:
drivers/char/tpm/st33zp24/st33zp24.c
drivers/char/tpm/tpm-interface.c
drivers/char/tpm/tpm_atmel.c
drivers/char/tpm/tpm_crb.c
drivers/char/tpm/tpm_ftpm_tee.c
drivers/char/tpm/tpm_i2c_atmel.c
drivers/char/tpm/tpm_i2c_infineon.c
drivers/char/tpm/tpm_i2c_nuvoton.c
drivers/char/tpm/tpm_ibmvtpm.c
drivers/char/tpm/tpm_infineon.c
drivers/char/tpm/tpm_nsc.c
drivers/char/tpm/tpm_svsm.c
drivers/char/tpm/tpm_tis_core.c
drivers/char/tpm/tpm_tis_i2c_cr50.c
drivers/char/tpm/tpm_vtpm_proxy.c
drivers/char/tpm/xen-tpmfront.c
include/linux/tpm.h

index c0771980bc2ff1cceabd21a2060b6c9d0d0195e4..2ed7815e4899b74f998f0d62c97eb3ee2ef3e8ac 100644 (file)
@@ -300,7 +300,7 @@ static irqreturn_t tpm_ioserirq_handler(int irq, void *dev_id)
  * send TPM commands through the I2C bus.
  */
 static int st33zp24_send(struct tpm_chip *chip, unsigned char *buf,
-                        size_t len)
+                        size_t bufsiz, size_t len)
 {
        struct st33zp24_dev *tpm_dev = dev_get_drvdata(&chip->dev);
        u32 status, i, size, ordinal;
index 8d7e4da6ed538a0621dc83847ccc9859c0534df3..816b7c690bc92dd6c920feed60388138bfbd33cc 100644 (file)
@@ -106,7 +106,7 @@ static ssize_t tpm_try_transmit(struct tpm_chip *chip, void *buf, size_t bufsiz)
                return -E2BIG;
        }
 
-       rc = chip->ops->send(chip, buf, count);
+       rc = chip->ops->send(chip, buf, bufsiz, count);
        if (rc < 0) {
                if (rc != -EPIPE)
                        dev_err(&chip->dev,
index 54a0360a3c95ea5bfed9507143c49b7debe744a9..f25faf468bba8c2bef4e46076de97dc0663c5a8b 100644 (file)
@@ -148,7 +148,8 @@ static int tpm_atml_recv(struct tpm_chip *chip, u8 *buf, size_t count)
        return size;
 }
 
-static int tpm_atml_send(struct tpm_chip *chip, u8 *buf, size_t count)
+static int tpm_atml_send(struct tpm_chip *chip, u8 *buf, size_t bufsiz,
+                        size_t count)
 {
        struct tpm_atmel_priv *priv = dev_get_drvdata(&chip->dev);
        int i;
index 876edf2705abb7fdc22a11e591197e10583e3672..ed97344f23242e2862324bd1373cb1030c7123e1 100644 (file)
@@ -426,7 +426,7 @@ static int tpm_crb_smc_start(struct device *dev, unsigned long func_id)
 }
 #endif
 
-static int crb_send(struct tpm_chip *chip, u8 *buf, size_t len)
+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);
        int rc = 0;
index 53ba28ccd5d3e292499d68e38d4aa5346d62d536..dbad83bf798edcba1e8191523abda8cad147aa73 100644 (file)
@@ -63,13 +63,15 @@ static int ftpm_tee_tpm_op_recv(struct tpm_chip *chip, u8 *buf, size_t count)
  * ftpm_tee_tpm_op_send() - send TPM commands through the TEE shared memory.
  * @chip:      the tpm_chip description as specified in driver/char/tpm/tpm.h
  * @buf:       the buffer to send.
+ * @bufsiz:    the size of the buffer.
  * @len:       the number of bytes to send.
  *
  * Return:
  *     In case of success, returns 0.
  *     On failure, -errno
  */
-static int ftpm_tee_tpm_op_send(struct tpm_chip *chip, u8 *buf, size_t len)
+static int ftpm_tee_tpm_op_send(struct tpm_chip *chip, u8 *buf, size_t bufsiz,
+                               size_t len)
 {
        struct ftpm_tee_private *pvt_data = dev_get_drvdata(chip->dev.parent);
        size_t resp_len;
index d1d27fdfe523313b8c0ed54f234f149f167342ae..4f229656a8e2f797015c8c25890bb6c563a8025f 100644 (file)
@@ -37,7 +37,8 @@ struct priv_data {
        u8 buffer[sizeof(struct tpm_header) + 25];
 };
 
-static int i2c_atmel_send(struct tpm_chip *chip, u8 *buf, size_t len)
+static int i2c_atmel_send(struct tpm_chip *chip, u8 *buf, size_t bufsiz,
+                         size_t len)
 {
        struct priv_data *priv = dev_get_drvdata(&chip->dev);
        struct i2c_client *client = to_i2c_client(chip->dev.parent);
index 81d8a78dc65528f21a640947b8200a4d6c4af11b..bdf1f329a67946144fb6ec6bc79e12d87f42ac12 100644 (file)
@@ -514,7 +514,8 @@ out:
        return size;
 }
 
-static int tpm_tis_i2c_send(struct tpm_chip *chip, u8 *buf, size_t len)
+static int tpm_tis_i2c_send(struct tpm_chip *chip, u8 *buf, size_t bufsiz,
+                           size_t len)
 {
        int rc, status;
        ssize_t burstcnt;
index 3c3ee5f551db1bca4faf43a8294024f92a848fa3..d44903b299294d32d1ea4fb22304c47a215d577e 100644 (file)
@@ -350,7 +350,8 @@ static int i2c_nuvoton_recv(struct tpm_chip *chip, u8 *buf, size_t count)
  * tpm.c can skip polling for the data to be available as the interrupt is
  * waited for here
  */
-static int i2c_nuvoton_send(struct tpm_chip *chip, u8 *buf, size_t len)
+static int i2c_nuvoton_send(struct tpm_chip *chip, u8 *buf, size_t bufsiz,
+                           size_t len)
 {
        struct priv_data *priv = dev_get_drvdata(&chip->dev);
        struct device *dev = chip->dev.parent;
index 76d048f63d55b57646c4a910ca15b05c7df64c75..4734a69406ce20dbcdb24d725dbd6d5c02309e0b 100644 (file)
@@ -191,13 +191,15 @@ static int tpm_ibmvtpm_resume(struct device *dev)
  * tpm_ibmvtpm_send() - Send a TPM command
  * @chip:      tpm chip struct
  * @buf:       buffer contains data to send
- * @count:     size of buffer
+ * @bufsiz:    size of the buffer
+ * @count:     length of the command
  *
  * Return:
  *   0 on success,
  *   -errno on error
  */
-static int tpm_ibmvtpm_send(struct tpm_chip *chip, u8 *buf, size_t count)
+static int tpm_ibmvtpm_send(struct tpm_chip *chip, u8 *buf, size_t bufsiz,
+                           size_t count)
 {
        struct ibmvtpm_dev *ibmvtpm = dev_get_drvdata(&chip->dev);
        bool retry = true;
index 2d2ae37153ba00c3a1eacde3cf3daf8c76d4522a..7638b65b851b98d697a26bf26664ab06154ba8d6 100644 (file)
@@ -312,7 +312,8 @@ recv_begin:
        return -EIO;
 }
 
-static int tpm_inf_send(struct tpm_chip *chip, u8 * buf, size_t count)
+static int tpm_inf_send(struct tpm_chip *chip, u8 *buf, size_t bufsiz,
+                       size_t count)
 {
        int i;
        int ret;
index 0f62bbc940daa814b260ba55dce04a6dd7ecd5f7..879ac88f5783c982638a25df7beaa80008020f07 100644 (file)
@@ -178,7 +178,8 @@ static int tpm_nsc_recv(struct tpm_chip *chip, u8 * buf, size_t count)
        return size;
 }
 
-static int tpm_nsc_send(struct tpm_chip *chip, u8 * buf, size_t count)
+static int tpm_nsc_send(struct tpm_chip *chip, u8 *buf, size_t bufsiz,
+                       size_t count)
 {
        struct tpm_nsc_priv *priv = dev_get_drvdata(&chip->dev);
        u8 data;
index 4280edf427d68ef51b0172c7b68022fbaf3dc661..0847cbf450b414db3cce5854c0cb605cb2d64ed4 100644 (file)
@@ -25,7 +25,8 @@ struct tpm_svsm_priv {
        void *buffer;
 };
 
-static int tpm_svsm_send(struct tpm_chip *chip, u8 *buf, size_t len)
+static int tpm_svsm_send(struct tpm_chip *chip, u8 *buf, size_t bufsiz,
+                        size_t len)
 {
        struct tpm_svsm_priv *priv = dev_get_drvdata(&chip->dev);
        int ret;
index ed0d3d8449b306ae07cc9b85b6cfbd854351ff4e..4b12c4b9da8befc4a284e5ecf433d71e738ae3a7 100644 (file)
@@ -580,7 +580,8 @@ out_err:
        return rc;
 }
 
-static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len)
+static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t bufsiz,
+                       size_t len)
 {
        int rc, irq;
        struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
index 3b55a7b05c46a91d963530cf2bb9eb5792b35a46..fc6891a0b6936de9679474932bdd5c5f88e735a4 100644 (file)
@@ -546,13 +546,15 @@ out_err:
  * tpm_cr50_i2c_tis_send() - TPM transmission callback.
  * @chip:      A TPM chip.
  * @buf:       Buffer to send.
- * @len:       Buffer length.
+ * @bufsiz:    Buffer size.
+ * @len:       Command length.
  *
  * Return:
  * - 0:                Success.
  * - -errno:   A POSIX error code.
  */
-static int tpm_cr50_i2c_tis_send(struct tpm_chip *chip, u8 *buf, size_t len)
+static int tpm_cr50_i2c_tis_send(struct tpm_chip *chip, u8 *buf, size_t bufsiz,
+                                size_t len)
 {
        size_t burstcnt, limit, sent = 0;
        u8 tpm_go[4] = { TPM_STS_GO };
index 8fe4a01eea1234e780c61b2e50506efb7e64bd49..0818bb517805f0cfbda60668c1d3eb110841665d 100644 (file)
@@ -321,12 +321,14 @@ static int vtpm_proxy_is_driver_command(struct tpm_chip *chip,
  *
  * @chip: tpm chip to use
  * @buf: send buffer
+ * @bufsiz: size of the buffer
  * @count: bytes to send
  *
  * Return:
  *      0 in case of success, negative error value otherwise.
  */
-static int vtpm_proxy_tpm_op_send(struct tpm_chip *chip, u8 *buf, size_t count)
+static int vtpm_proxy_tpm_op_send(struct tpm_chip *chip, u8 *buf, size_t bufsiz,
+                                 size_t count)
 {
        struct proxy_dev *proxy_dev = dev_get_drvdata(&chip->dev);
 
index 80cca3b83b226aa10918fc6e7a7468a43bd91996..556bf22567163a0d76fc60c802dbe546c5357f42 100644 (file)
@@ -131,7 +131,8 @@ static size_t shr_data_offset(struct vtpm_shared_page *shr)
        return struct_size(shr, extra_pages, shr->nr_extra_pages);
 }
 
-static int vtpm_send(struct tpm_chip *chip, u8 *buf, size_t count)
+static int vtpm_send(struct tpm_chip *chip, u8 *buf, size_t bufsiz,
+                    size_t count)
 {
        struct tpm_private *priv = dev_get_drvdata(&chip->dev);
        struct vtpm_shared_page *shr = priv->shr;
index a3d8305e88a51ec41c3fe1286c3b54f360d281db..cafe8c283e8890dbf45228246c37acbb42fc7024 100644 (file)
@@ -87,7 +87,8 @@ struct tpm_class_ops {
        const u8 req_complete_val;
        bool (*req_canceled)(struct tpm_chip *chip, u8 status);
        int (*recv) (struct tpm_chip *chip, u8 *buf, size_t len);
-       int (*send) (struct tpm_chip *chip, u8 *buf, size_t len);
+       int (*send)(struct tpm_chip *chip, u8 *buf, size_t bufsiz,
+                   size_t cmd_len);
        void (*cancel) (struct tpm_chip *chip);
        u8 (*status) (struct tpm_chip *chip);
        void (*update_timeouts)(struct tpm_chip *chip,