[PATCH net v2 3/3] rtase: Fix a type error in min_t

Justin Lai posted 3 patches 8 months ago
[PATCH net v2 3/3] rtase: Fix a type error in min_t
Posted by Justin Lai 8 months ago
Fix a type error in min_t.

Fixes: a36e9f5cfe9e ("rtase: Add support for a pci table in this module")
Signed-off-by: Justin Lai <justinlai0215@realtek.com>
---
 drivers/net/ethernet/realtek/rtase/rtase_main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/realtek/rtase/rtase_main.c b/drivers/net/ethernet/realtek/rtase/rtase_main.c
index 55b8d3666153..bc856fb3d6f3 100644
--- a/drivers/net/ethernet/realtek/rtase/rtase_main.c
+++ b/drivers/net/ethernet/realtek/rtase/rtase_main.c
@@ -1923,7 +1923,7 @@ static u16 rtase_calc_time_mitigation(u32 time_us)
 	u8 msb, time_count, time_unit;
 	u16 int_miti;
 
-	time_us = min_t(int, time_us, RTASE_MITI_MAX_TIME);
+	time_us = min_t(u32, time_us, RTASE_MITI_MAX_TIME);
 
 	if (time_us > RTASE_MITI_TIME_COUNT_MASK) {
 		msb = fls(time_us);
@@ -1945,7 +1945,7 @@ static u16 rtase_calc_packet_num_mitigation(u16 pkt_num)
 	u8 msb, pkt_num_count, pkt_num_unit;
 	u16 int_miti;
 
-	pkt_num = min_t(int, pkt_num, RTASE_MITI_MAX_PKT_NUM);
+	pkt_num = min_t(u16, pkt_num, RTASE_MITI_MAX_PKT_NUM);
 
 	if (pkt_num > 60) {
 		pkt_num_unit = RTASE_MITI_MAX_PKT_NUM_IDX;
-- 
2.34.1
Re: [PATCH net v2 3/3] rtase: Fix a type error in min_t
Posted by David Laight 7 months, 3 weeks ago
On Wed, 16 Apr 2025 20:45:34 +0800
Justin Lai <justinlai0215@realtek.com> wrote:

> Fix a type error in min_t.

NAK, in particular u16 is likely to be buggy
Consider what would happen if RTBASE_MITI_MAX_PKT_NUM was 65536.
(Yes, I know that isn't the intent of the code...)

As pointed out earlier using min() shouldn't generate a compile warning
and won't mask off significant bits.

Also I think it isn't a bug in any sense because the two functions
have a single caller that passes a constant.

	David


> 
> Fixes: a36e9f5cfe9e ("rtase: Add support for a pci table in this module")
> Signed-off-by: Justin Lai <justinlai0215@realtek.com>
> ---
>  drivers/net/ethernet/realtek/rtase/rtase_main.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/ethernet/realtek/rtase/rtase_main.c b/drivers/net/ethernet/realtek/rtase/rtase_main.c
> index 55b8d3666153..bc856fb3d6f3 100644
> --- a/drivers/net/ethernet/realtek/rtase/rtase_main.c
> +++ b/drivers/net/ethernet/realtek/rtase/rtase_main.c
> @@ -1923,7 +1923,7 @@ static u16 rtase_calc_time_mitigation(u32 time_us)
>  	u8 msb, time_count, time_unit;
>  	u16 int_miti;
>  
> -	time_us = min_t(int, time_us, RTASE_MITI_MAX_TIME);
> +	time_us = min_t(u32, time_us, RTASE_MITI_MAX_TIME);
>  
>  	if (time_us > RTASE_MITI_TIME_COUNT_MASK) {
>  		msb = fls(time_us);
> @@ -1945,7 +1945,7 @@ static u16 rtase_calc_packet_num_mitigation(u16 pkt_num)
>  	u8 msb, pkt_num_count, pkt_num_unit;
>  	u16 int_miti;
>  
> -	pkt_num = min_t(int, pkt_num, RTASE_MITI_MAX_PKT_NUM);
> +	pkt_num = min_t(u16, pkt_num, RTASE_MITI_MAX_PKT_NUM);
>  
>  	if (pkt_num > 60) {
>  		pkt_num_unit = RTASE_MITI_MAX_PKT_NUM_IDX;
RE: [PATCH net v2 3/3] rtase: Fix a type error in min_t
Posted by Justin Lai 7 months, 3 weeks ago
> On Wed, 16 Apr 2025 20:45:34 +0800
> Justin Lai <justinlai0215@realtek.com> wrote:
> 
> > Fix a type error in min_t.
> 
> NAK, in particular u16 is likely to be buggy Consider what would happen if
> RTBASE_MITI_MAX_PKT_NUM was 65536.
> (Yes, I know that isn't the intent of the code...)
> 
> As pointed out earlier using min() shouldn't generate a compile warning and
> won't mask off significant bits.
> 
> Also I think it isn't a bug in any sense because the two functions have a single
> caller that passes a constant.
> 
>         David

Hi David,

This is indeed not a bug fix, and I have modified it to use min instead
of min_t, and posted it to net-next.

Thanks,
Justin

> 
> 
> >
> > Fixes: a36e9f5cfe9e ("rtase: Add support for a pci table in this
> > module")
> > Signed-off-by: Justin Lai <justinlai0215@realtek.com>
> > ---
> >  drivers/net/ethernet/realtek/rtase/rtase_main.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/net/ethernet/realtek/rtase/rtase_main.c
> > b/drivers/net/ethernet/realtek/rtase/rtase_main.c
> > index 55b8d3666153..bc856fb3d6f3 100644
> > --- a/drivers/net/ethernet/realtek/rtase/rtase_main.c
> > +++ b/drivers/net/ethernet/realtek/rtase/rtase_main.c
> > @@ -1923,7 +1923,7 @@ static u16 rtase_calc_time_mitigation(u32
> time_us)
> >       u8 msb, time_count, time_unit;
> >       u16 int_miti;
> >
> > -     time_us = min_t(int, time_us, RTASE_MITI_MAX_TIME);
> > +     time_us = min_t(u32, time_us, RTASE_MITI_MAX_TIME);
> >
> >       if (time_us > RTASE_MITI_TIME_COUNT_MASK) {
> >               msb = fls(time_us);
> > @@ -1945,7 +1945,7 @@ static u16 rtase_calc_packet_num_mitigation(u16
> pkt_num)
> >       u8 msb, pkt_num_count, pkt_num_unit;
> >       u16 int_miti;
> >
> > -     pkt_num = min_t(int, pkt_num, RTASE_MITI_MAX_PKT_NUM);
> > +     pkt_num = min_t(u16, pkt_num, RTASE_MITI_MAX_PKT_NUM);
> >
> >       if (pkt_num > 60) {
> >               pkt_num_unit = RTASE_MITI_MAX_PKT_NUM_IDX;
Re: [PATCH net v2 3/3] rtase: Fix a type error in min_t
Posted by Andrew Lunn 8 months ago
On Wed, Apr 16, 2025 at 08:45:34PM +0800, Justin Lai wrote:
> Fix a type error in min_t.
> 
> Fixes: a36e9f5cfe9e ("rtase: Add support for a pci table in this module")
> Signed-off-by: Justin Lai <justinlai0215@realtek.com>

Reviewed-by: Andrew Lunn <andrew@lunn.ch>

    Andrew