diff mbox series

[net-next,5/8] net/dccp: Use min()/max() to simplify the code

Message ID 20240824074033.2134514-6-lihongbo22@huawei.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series Use max/min to simplify the code | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit fail Errors and warnings before: 14 this patch: 14
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers warning 2 maintainers not CCed: chentao@kylinos.cn jiri@resnulli.us
netdev/build_clang fail Errors and warnings before: 15 this patch: 15
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn fail Errors and warnings before: 22 this patch: 22
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 16 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 7 this patch: 7
netdev/source_inline success Was 0 now: 0

Commit Message

Hongbo Li Aug. 24, 2024, 7:40 a.m. UTC
Let's use min()/max() to simplify the code and fix the
Coccinelle/coccicheck warning reported by minmax.cocci.

Signed-off-by: Hongbo Li <lihongbo22@huawei.com>
---
 net/dccp/ackvec.c | 2 +-
 net/dccp/dccp.h   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

Comments

Simon Horman Aug. 28, 2024, 2:04 p.m. UTC | #1
On Sat, Aug 24, 2024 at 03:40:30PM +0800, Hongbo Li wrote:
> Let's use min()/max() to simplify the code and fix the
> Coccinelle/coccicheck warning reported by minmax.cocci.
> 
> Signed-off-by: Hongbo Li <lihongbo22@huawei.com>
> ---
>  net/dccp/ackvec.c | 2 +-
>  net/dccp/dccp.h   | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/net/dccp/ackvec.c b/net/dccp/ackvec.c
> index 1cba001bb4c8..faadd0190107 100644
> --- a/net/dccp/ackvec.c
> +++ b/net/dccp/ackvec.c
> @@ -305,7 +305,7 @@ void dccp_ackvec_clear_state(struct dccp_ackvec *av, const u64 ackno)
>  	 * Deal with overlapping Ack Vectors: don't subtract more than the
>  	 * number of packets between tail_ackno and ack_ackno.
>  	 */
> -	eff_runlen = delta < avr->avr_ack_runlen ? delta : avr->avr_ack_runlen;
> +	eff_runlen = min(delta, avr->avr_ack_runlen);

delta is s64, but known to be non-negative
avr->avr_ack_runlen is u8

I _think_ this is a candidate for umin().

>  
>  	runlen_now = dccp_ackvec_runlen(av->av_buf + avr->avr_ack_ptr);
>  	/*
> diff --git a/net/dccp/dccp.h b/net/dccp/dccp.h
> index 1f748ed1279d..872d17fb85b5 100644
> --- a/net/dccp/dccp.h
> +++ b/net/dccp/dccp.h
> @@ -149,7 +149,7 @@ static inline u64 dccp_loss_count(const u64 s1, const u64 s2, const u64 ndp)
>  	WARN_ON(delta < 0);
>  	delta -= ndp + 1;
>  
> -	return delta > 0 ? delta : 0;
> +	return max(delta, 0);
>  }

As per my comment on 2/8 [*], I think you should drop this hunk.

[*] https://lore.kernel.org/all/20240828135310.GC1368797@kernel.org/
diff mbox series

Patch

diff --git a/net/dccp/ackvec.c b/net/dccp/ackvec.c
index 1cba001bb4c8..faadd0190107 100644
--- a/net/dccp/ackvec.c
+++ b/net/dccp/ackvec.c
@@ -305,7 +305,7 @@  void dccp_ackvec_clear_state(struct dccp_ackvec *av, const u64 ackno)
 	 * Deal with overlapping Ack Vectors: don't subtract more than the
 	 * number of packets between tail_ackno and ack_ackno.
 	 */
-	eff_runlen = delta < avr->avr_ack_runlen ? delta : avr->avr_ack_runlen;
+	eff_runlen = min(delta, avr->avr_ack_runlen);
 
 	runlen_now = dccp_ackvec_runlen(av->av_buf + avr->avr_ack_ptr);
 	/*
diff --git a/net/dccp/dccp.h b/net/dccp/dccp.h
index 1f748ed1279d..872d17fb85b5 100644
--- a/net/dccp/dccp.h
+++ b/net/dccp/dccp.h
@@ -149,7 +149,7 @@  static inline u64 dccp_loss_count(const u64 s1, const u64 s2, const u64 ndp)
 	WARN_ON(delta < 0);
 	delta -= ndp + 1;
 
-	return delta > 0 ? delta : 0;
+	return max(delta, 0);
 }
 
 /**