netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next v3] net: mvneta: Use min macro
@ 2024-08-30  1:04 Yan Zhen
  2024-08-30 15:45 ` Simon Horman
  2024-09-01 10:52 ` David Laight
  0 siblings, 2 replies; 5+ messages in thread
From: Yan Zhen @ 2024-08-30  1:04 UTC (permalink / raw)
  To: marcin.s.wojtas, davem, edumazet, kuba, pabeni
  Cc: netdev, linux-kernel, opensource.kernel, Yan Zhen

Using the real macro is usually more intuitive and readable,
When the original file is guaranteed to contain the minmax.h header file
and compile correctly.

Signed-off-by: Yan Zhen <yanzhen@vivo.com>
---

Changes in v3:
- Rewrite the subject.

 drivers/net/ethernet/marvell/mvneta.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/marvell/mvneta.c b/drivers/net/ethernet/marvell/mvneta.c
index d72b2d5f96db..08d277165f40 100644
--- a/drivers/net/ethernet/marvell/mvneta.c
+++ b/drivers/net/ethernet/marvell/mvneta.c
@@ -4750,8 +4750,7 @@ mvneta_ethtool_set_ringparam(struct net_device *dev,
 
 	if ((ring->rx_pending == 0) || (ring->tx_pending == 0))
 		return -EINVAL;
-	pp->rx_ring_size = ring->rx_pending < MVNETA_MAX_RXD ?
-		ring->rx_pending : MVNETA_MAX_RXD;
+	pp->rx_ring_size = umin(ring->rx_pending, MVNETA_MAX_RXD);
 
 	pp->tx_ring_size = clamp_t(u16, ring->tx_pending,
 				   MVNETA_MAX_SKB_DESCS * 2, MVNETA_MAX_TXD);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH net-next v3] net: mvneta: Use min macro
  2024-08-30  1:04 [PATCH net-next v3] net: mvneta: Use min macro Yan Zhen
@ 2024-08-30 15:45 ` Simon Horman
  2024-08-30 17:39   ` Marcin Wojtas
  2024-09-01 10:52 ` David Laight
  1 sibling, 1 reply; 5+ messages in thread
From: Simon Horman @ 2024-08-30 15:45 UTC (permalink / raw)
  To: Yan Zhen
  Cc: marcin.s.wojtas, davem, edumazet, kuba, pabeni, netdev,
	linux-kernel, opensource.kernel

On Fri, Aug 30, 2024 at 09:04:23AM +0800, Yan Zhen wrote:
> Using the real macro is usually more intuitive and readable,
> When the original file is guaranteed to contain the minmax.h header file
> and compile correctly.
> 
> Signed-off-by: Yan Zhen <yanzhen@vivo.com>
> ---
> 
> Changes in v3:
> - Rewrite the subject.

Thanks for the update.

Reviewed-by: Simon Horman <horms@kernel.org>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net-next v3] net: mvneta: Use min macro
  2024-08-30 15:45 ` Simon Horman
@ 2024-08-30 17:39   ` Marcin Wojtas
  0 siblings, 0 replies; 5+ messages in thread
From: Marcin Wojtas @ 2024-08-30 17:39 UTC (permalink / raw)
  To: Simon Horman
  Cc: Yan Zhen, davem, edumazet, kuba, pabeni, netdev, linux-kernel,
	opensource.kernel

pt., 30 sie 2024 o 17:45 Simon Horman <horms@kernel.org> napisał(a):
>
> On Fri, Aug 30, 2024 at 09:04:23AM +0800, Yan Zhen wrote:
> > Using the real macro is usually more intuitive and readable,
> > When the original file is guaranteed to contain the minmax.h header file
> > and compile correctly.
> >
> > Signed-off-by: Yan Zhen <yanzhen@vivo.com>
> > ---
> >
> > Changes in v3:
> > - Rewrite the subject.
>
> Thanks for the update.
>
> Reviewed-by: Simon Horman <horms@kernel.org>
>

Reviewed-by: Marcin Wojtas <marcin.s.wojtas@gmail.com>

Thanks!

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: [PATCH net-next v3] net: mvneta: Use min macro
  2024-08-30  1:04 [PATCH net-next v3] net: mvneta: Use min macro Yan Zhen
  2024-08-30 15:45 ` Simon Horman
@ 2024-09-01 10:52 ` David Laight
  2024-09-01 18:30   ` Simon Horman
  1 sibling, 1 reply; 5+ messages in thread
From: David Laight @ 2024-09-01 10:52 UTC (permalink / raw)
  To: 'Yan Zhen', marcin.s.wojtas@gmail.com,
	davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
	pabeni@redhat.com
  Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	opensource.kernel@vivo.com

From: Yan Zhen
> Sent: 30 August 2024 02:04
> To: marcin.s.wojtas@gmail.com; davem@davemloft.net; edumazet@google.com; kuba@kernel.org;
> 
> Using the real macro is usually more intuitive and readable,
> When the original file is guaranteed to contain the minmax.h header file
> and compile correctly.
> 
> Signed-off-by: Yan Zhen <yanzhen@vivo.com>
> ---
> 
> Changes in v3:
> - Rewrite the subject.
> 
>  drivers/net/ethernet/marvell/mvneta.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/net/ethernet/marvell/mvneta.c b/drivers/net/ethernet/marvell/mvneta.c
> index d72b2d5f96db..08d277165f40 100644
> --- a/drivers/net/ethernet/marvell/mvneta.c
> +++ b/drivers/net/ethernet/marvell/mvneta.c
> @@ -4750,8 +4750,7 @@ mvneta_ethtool_set_ringparam(struct net_device *dev,
> 
>  	if ((ring->rx_pending == 0) || (ring->tx_pending == 0))
>  		return -EINVAL;
> -	pp->rx_ring_size = ring->rx_pending < MVNETA_MAX_RXD ?
> -		ring->rx_pending : MVNETA_MAX_RXD;
> +	pp->rx_ring_size = umin(ring->rx_pending, MVNETA_MAX_RXD);

Why did you use umin() instead of min() ?

> 
>  	pp->tx_ring_size = clamp_t(u16, ring->tx_pending,
>  				   MVNETA_MAX_SKB_DESCS * 2, MVNETA_MAX_TXD);

Hmmm how about a patch to fix the bug in that line?
A typical example of the complete misuse of the '_t' variants.
The fact that the LHS is u16 doesn't mean that it is anyway
correct to cast the RHS value to u16.
In this case if someone tries to set the ring size to 64k they'll
get the minimum supported size and not the maximum.

	David

> --
> 2.34.1
> 

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net-next v3] net: mvneta: Use min macro
  2024-09-01 10:52 ` David Laight
@ 2024-09-01 18:30   ` Simon Horman
  0 siblings, 0 replies; 5+ messages in thread
From: Simon Horman @ 2024-09-01 18:30 UTC (permalink / raw)
  To: David Laight
  Cc: 'Yan Zhen', marcin.s.wojtas@gmail.com,
	davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
	pabeni@redhat.com, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org, opensource.kernel@vivo.com

On Sun, Sep 01, 2024 at 10:52:38AM +0000, David Laight wrote:
> From: Yan Zhen
> > Sent: 30 August 2024 02:04
> > To: marcin.s.wojtas@gmail.com; davem@davemloft.net; edumazet@google.com; kuba@kernel.org;
> > 
> > Using the real macro is usually more intuitive and readable,
> > When the original file is guaranteed to contain the minmax.h header file
> > and compile correctly.
> > 
> > Signed-off-by: Yan Zhen <yanzhen@vivo.com>
> > ---
> > 
> > Changes in v3:
> > - Rewrite the subject.
> > 
> >  drivers/net/ethernet/marvell/mvneta.c | 3 +--
> >  1 file changed, 1 insertion(+), 2 deletions(-)
> > 
> > diff --git a/drivers/net/ethernet/marvell/mvneta.c b/drivers/net/ethernet/marvell/mvneta.c
> > index d72b2d5f96db..08d277165f40 100644
> > --- a/drivers/net/ethernet/marvell/mvneta.c
> > +++ b/drivers/net/ethernet/marvell/mvneta.c
> > @@ -4750,8 +4750,7 @@ mvneta_ethtool_set_ringparam(struct net_device *dev,
> > 
> >  	if ((ring->rx_pending == 0) || (ring->tx_pending == 0))
> >  		return -EINVAL;
> > -	pp->rx_ring_size = ring->rx_pending < MVNETA_MAX_RXD ?
> > -		ring->rx_pending : MVNETA_MAX_RXD;
> > +	pp->rx_ring_size = umin(ring->rx_pending, MVNETA_MAX_RXD);
> 
> Why did you use umin() instead of min() ?

Possibly because I mistakenly advised it is appropriate, sorry about that.
Given your explanation elsewhere [1], I now agree min() is appropriate.

[1] https://lore.kernel.org/netdev/20240901171150.GA23170@kernel.org/T/#mebc52fc11de13eff8a610e3a63c5d1026d527492

> >  	pp->tx_ring_size = clamp_t(u16, ring->tx_pending,
> >  				   MVNETA_MAX_SKB_DESCS * 2, MVNETA_MAX_TXD);
> 
> Hmmm how about a patch to fix the bug in that line?
> A typical example of the complete misuse of the '_t' variants.
> The fact that the LHS is u16 doesn't mean that it is anyway
> correct to cast the RHS value to u16.
> In this case if someone tries to set the ring size to 64k they'll

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-09-01 18:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-30  1:04 [PATCH net-next v3] net: mvneta: Use min macro Yan Zhen
2024-08-30 15:45 ` Simon Horman
2024-08-30 17:39   ` Marcin Wojtas
2024-09-01 10:52 ` David Laight
2024-09-01 18:30   ` Simon Horman

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).