From: Tomas Marek <tomas.marek@elrest.cz>
To: Ahmad Fatoum <a.fatoum@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH 5/6] i2c: efi: avoid 64-bit division
Date: Thu, 15 Aug 2024 07:53:10 +0200 [thread overview]
Message-ID: <Zr2XxoD4Gce7bTB4@debian> (raw)
In-Reply-To: <20240814092424.39878-5-a.fatoum@pengutronix.de>
Hello Ahmad,
Thanks for maintenance of the Barebox EFI.
On Wed, Aug 14, 2024 at 11:24:23AM +0200, Ahmad Fatoum wrote:
> I2C message length is 16 bit, so doing a 64-bit division is overkill.
> Let's remove the cast and just rely on the usual integer promotion
> to 32-bit.
>
> Cc: Tomas Marek <tomas.marek@elrest.cz>
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
> drivers/i2c/busses/i2c-efi.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/i2c/busses/i2c-efi.c b/drivers/i2c/busses/i2c-efi.c
> index 5f6cc0eed28e..a666a28fab51 100644
> --- a/drivers/i2c/busses/i2c-efi.c
> +++ b/drivers/i2c/busses/i2c-efi.c
> @@ -114,7 +114,7 @@ static unsigned int efi_i2c_msg_op_cnt(const struct efi_i2c_priv *i2c_priv,
>
> max_len = efi_i2c_max_len(i2c_priv, msg);
>
> - return ((u64)msg->len + max_len - 1) / max_len;
> + return (msg->len + max_len - 1) / max_len;
The issue here is that max_len, which represents the MaximumReceiveBytes
or MaximumTransmitBytes in EFI I2C capabilities, is 32-bit. In some EFI
implementations (including the one I use), the EFI I2C MaximumReceiveBytes
and MaximumTransmitBytes are set to the maximum value (0xFFFFFFFF). This
causes msg->len + max_len - 1 to overflow, leading to an incorrect number
of returned operations. To address this, the msg->len is extended to 64 bits.
Best regards
Tomas
> }
>
> static unsigned int efi_i2c_req_op_cnt(
> --
> 2.39.2
>
next prev parent reply other threads:[~2024-08-15 5:54 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-14 9:24 [PATCH 1/6] common: pe: fix use of undefined macro for ARMv7 Ahmad Fatoum
2024-08-14 9:24 ` [PATCH 2/6] efi: fs: fix determination of read-only files Ahmad Fatoum
2024-08-14 9:24 ` [PATCH 3/6] filetype: fix else clause indentation Ahmad Fatoum
2024-08-14 9:24 ` [PATCH 4/6] acpi: fix compilation for 32-bit Ahmad Fatoum
2024-08-14 9:24 ` [PATCH 5/6] i2c: efi: avoid 64-bit division Ahmad Fatoum
2024-08-15 5:53 ` Tomas Marek [this message]
2024-08-15 6:57 ` Ahmad Fatoum
2024-08-19 6:16 ` Sascha Hauer
2024-08-14 9:24 ` [PATCH 6/6] net: fsl_enetc: fix compilation for 32-bit Ahmad Fatoum
2024-08-14 11:08 ` [PATCH 1/6] common: pe: fix use of undefined macro for ARMv7 Sascha Hauer
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=Zr2XxoD4Gce7bTB4@debian \
--to=tomas.marek@elrest.cz \
--cc=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.