From: Jarkko Sakkinen <jarkko@kernel.org>
To: david.laight.linux@gmail.com
Cc: linux-kernel@vger.kernel.org, linux-integrity@vger.kernel.org,
Peter Huewe <peterhuewe@gmx.de>
Subject: Re: [PATCH 15/44] drivers/char/tpm: use min() instead of min_t()
Date: Fri, 21 Nov 2025 22:11:54 +0200 [thread overview]
Message-ID: <aSDHihcWOHGLAjTb@kernel.org> (raw)
In-Reply-To: <20251119224140.8616-16-david.laight.linux@gmail.com>
On Wed, Nov 19, 2025 at 10:41:11PM +0000, david.laight.linux@gmail.com wrote:
> From: David Laight <david.laight.linux@gmail.com>
>
> min_t(int, a, b) casts an 'long' to 'int'.
> Use min(a, b) instead as it promotes any 'int' to 'long'
> and so cannot discard significant bits.
>
> In this case the 'long' value is small enough that the result is ok.
>
> Detected by an extra check added to min_t().
>
> Signed-off-by: David Laight <david.laight.linux@gmail.com>
> ---
> drivers/char/tpm/tpm1-cmd.c | 2 +-
> drivers/char/tpm/tpm_tis_core.c | 4 ++--
> 2 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/char/tpm/tpm1-cmd.c b/drivers/char/tpm/tpm1-cmd.c
> index cf64c7385105..11088bda4e68 100644
> --- a/drivers/char/tpm/tpm1-cmd.c
> +++ b/drivers/char/tpm/tpm1-cmd.c
> @@ -530,7 +530,7 @@ struct tpm1_get_random_out {
> int tpm1_get_random(struct tpm_chip *chip, u8 *dest, size_t max)
> {
> struct tpm1_get_random_out *out;
> - u32 num_bytes = min_t(u32, max, TPM_MAX_RNG_DATA);
> + u32 num_bytes = min(max, TPM_MAX_RNG_DATA);
> struct tpm_buf buf;
> u32 total = 0;
> int retries = 5;
> diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c
> index 8954a8660ffc..2676e3a241b5 100644
> --- a/drivers/char/tpm/tpm_tis_core.c
> +++ b/drivers/char/tpm/tpm_tis_core.c
> @@ -310,7 +310,7 @@ static int get_burstcount(struct tpm_chip *chip)
> return -EBUSY;
> }
>
> -static int recv_data(struct tpm_chip *chip, u8 *buf, size_t count)
> +static int recv_data(struct tpm_chip *chip, u8 *buf, u32 count)
> {
> struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
> int size = 0, burstcnt, rc;
> @@ -453,7 +453,7 @@ static int tpm_tis_send_data(struct tpm_chip *chip, const u8 *buf, size_t len)
> rc = burstcnt;
> goto out_err;
> }
> - burstcnt = min_t(int, burstcnt, len - count - 1);
> + burstcnt = min(burstcnt, len - count - 1);
> rc = tpm_tis_write_bytes(priv, TPM_DATA_FIFO(priv->locality),
> burstcnt, buf + count);
> if (rc < 0)
> --
> 2.39.5
>
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
BR, Jarkko
next prev parent reply other threads:[~2025-11-21 20:11 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-19 22:40 [PATCH 00/44] Change a lot of min_t() that might mask high bits david.laight.linux
2025-11-19 22:41 ` [PATCH 15/44] drivers/char/tpm: use min() instead of min_t() david.laight.linux
2025-11-21 20:11 ` Jarkko Sakkinen [this message]
2025-11-20 1:47 ` [PATCH 00/44] Change a lot of min_t() that might mask high bits Jakub Kicinski
2025-11-20 9:38 ` Lorenzo Stoakes
2025-11-20 14:52 ` (subset) " Jens Axboe
2025-11-24 9:49 ` Herbert Xu
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=aSDHihcWOHGLAjTb@kernel.org \
--to=jarkko@kernel.org \
--cc=david.laight.linux@gmail.com \
--cc=linux-integrity@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=peterhuewe@gmx.de \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).