From: David Laight <David.Laight@ACULAB.COM>
To: 'Yan Zhen' <yanzhen@vivo.com>,
"marcin.s.wojtas@gmail.com" <marcin.s.wojtas@gmail.com>,
"davem@davemloft.net" <davem@davemloft.net>,
"edumazet@google.com" <edumazet@google.com>,
"kuba@kernel.org" <kuba@kernel.org>,
"pabeni@redhat.com" <pabeni@redhat.com>
Cc: "netdev@vger.kernel.org" <netdev@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"openkernel.kernel@vivo.com" <openkernel.kernel@vivo.com>,
"horms@kernel.org" <horms@kernel.org>
Subject: RE: [PATCH net-next v1] net: mvneta: Avoid the misuse of the '_t' variants
Date: Thu, 5 Sep 2024 08:30:59 +0000 [thread overview]
Message-ID: <d1709ca244ac45cd8a7361d7cbd0ea66@AcuMS.aculab.com> (raw)
In-Reply-To: <20240905063645.586354-1-yanzhen@vivo.com>
From: Yan Zhen
> Sent: 05 September 2024 07:37
>
> Type conversions (especially when narrowing down types) can lead to
> unexpected behavior and should be done with extreme caution.
>
> In this case if someone tries to set the tx_pending to 65536(0x10000),
> after forcing it to convert to u16, it becomes 0x0000, they will get
> the minimum supported size and not the maximum.
>
> Based on previous discussions [1], such behavior may confuse users or even
> create unexpected errors.
>
> [1] https://lore.kernel.org/netdev/d23dfbf563714d7090d163a075ca9a51@AcuMS.aculab.com/
>
> Signed-off-by: Yan Zhen <yanzhen@vivo.com>
Reviewed-by: david.laight@aculab.com
> ---
> drivers/net/ethernet/marvell/mvneta.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/ethernet/marvell/mvneta.c b/drivers/net/ethernet/marvell/mvneta.c
> index d72b2d5f96db..b41de182cc88 100644
> --- a/drivers/net/ethernet/marvell/mvneta.c
> +++ b/drivers/net/ethernet/marvell/mvneta.c
> @@ -4753,8 +4753,8 @@ mvneta_ethtool_set_ringparam(struct net_device *dev,
> pp->rx_ring_size = ring->rx_pending < MVNETA_MAX_RXD ?
> ring->rx_pending : MVNETA_MAX_RXD;
>
> - pp->tx_ring_size = clamp_t(u16, ring->tx_pending,
> - MVNETA_MAX_SKB_DESCS * 2, MVNETA_MAX_TXD);
> + pp->tx_ring_size = clamp(ring->tx_pending,
> + MVNETA_MAX_SKB_DESCS * 2, MVNETA_MAX_TXD);
> if (pp->tx_ring_size != ring->tx_pending)
> netdev_warn(dev, "TX queue size set to %u (requested %u)\n",
> pp->tx_ring_size, ring->tx_pending);
> --
> 2.34.1
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
next prev parent reply other threads:[~2024-09-05 8:31 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-05 6:36 [PATCH net-next v1] net: mvneta: Avoid the misuse of the '_t' variants Yan Zhen
2024-09-05 8:30 ` David Laight [this message]
2024-09-07 1:55 ` Jakub Kicinski
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=d1709ca244ac45cd8a7361d7cbd0ea66@AcuMS.aculab.com \
--to=david.laight@aculab.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marcin.s.wojtas@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=openkernel.kernel@vivo.com \
--cc=pabeni@redhat.com \
--cc=yanzhen@vivo.com \
/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