From: Vladimir Oltean <vladimir.oltean@nxp.com>
To: Claudiu Manoil <claudiu.manoil@nxp.com>
Cc: "netdev@vger.kernel.org" <netdev@vger.kernel.org>,
Jakub Kicinski <kuba@kernel.org>,
"David S . Miller" <davem@davemloft.net>
Subject: Re: [PATCH net v2] enetc: Avoid implicit sign extension
Date: Mon, 29 Mar 2021 16:24:22 +0000 [thread overview]
Message-ID: <20210329162421.k5ltz2tkufsueyds@skbuf> (raw)
In-Reply-To: <20210329141443.23245-1-claudiu.manoil@nxp.com>
On Mon, Mar 29, 2021 at 05:14:43PM +0300, Claudiu Manoil wrote:
> Static analysis tool reports:
> "Suspicious implicit sign extension - 'flags' with type u8 (8 bit,
> unsigned) is promoted in 'flags' << 24 to type int (32 bits, signed),
> then sign-extended to type unsigned long long (64 bits, unsigned).
> If flags << 24 is greater than 0x7FFFFFFF, the upper bits of the result
This is a backwards way of saying 'if flags & BIT(7) is set', no? But
BIT(7) is ENETC_TXBD_FLAGS_F (the 'final BD' bit), and I've been testing
SO_TXTIME with single BD frames, and haven't seen this problem.
> will all be 1."
>
> Use lower_32_bits() to avoid this scenario.
>
> Fixes: 82728b91f124 ("enetc: Remove Tx checksumming offload code")
>
> Signed-off-by: Claudiu Manoil <claudiu.manoil@nxp.com>
> ---
> v2 - added 'fixes' tag
>
> drivers/net/ethernet/freescale/enetc/enetc_hw.h | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/ethernet/freescale/enetc/enetc_hw.h b/drivers/net/ethernet/freescale/enetc/enetc_hw.h
> index 00938f7960a4..07e03df8af94 100644
> --- a/drivers/net/ethernet/freescale/enetc/enetc_hw.h
> +++ b/drivers/net/ethernet/freescale/enetc/enetc_hw.h
> @@ -535,8 +535,8 @@ static inline __le32 enetc_txbd_set_tx_start(u64 tx_start, u8 flags)
> {
> u32 temp;
>
> - temp = (tx_start >> 5 & ENETC_TXBD_TXSTART_MASK) |
> - (flags << ENETC_TXBD_FLAGS_OFFSET);
> + temp = lower_32_bits(tx_start >> 5 & ENETC_TXBD_TXSTART_MASK) |
> + (u32)(flags << ENETC_TXBD_FLAGS_OFFSET);
I don't actually understand why lower_32_bits called on the TX time
helps, considering that the value is masked already. The static analysis
tool says that the right hand side of the "|" operator is what is
sign-extended:
(flags << ENETC_TXBD_FLAGS_OFFSET);
Isn't it sufficient that you replace "u8 flags" in the function
prototype with "u32 flags"?
>
> return cpu_to_le32(temp);
> }
> --
> 2.25.1
>
next prev parent reply other threads:[~2021-03-29 16:25 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-29 14:14 [PATCH net v2] enetc: Avoid implicit sign extension Claudiu Manoil
2021-03-29 16:24 ` Vladimir Oltean [this message]
2021-03-29 17:08 ` Claudiu Manoil
2021-03-30 8:40 ` David Laight
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=20210329162421.k5ltz2tkufsueyds@skbuf \
--to=vladimir.oltean@nxp.com \
--cc=claudiu.manoil@nxp.com \
--cc=davem@davemloft.net \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox