diff mbox series

[-next] net/sched: use min() macro instead of doing it manually

Message ID 20211221011455.10163-1-yang.lee@linux.alibaba.com (mailing list archive)
State Accepted
Commit c48c94b0ab75ef3bbfa539e6e212184e315fd5bd
Delegated to: Netdev Maintainers
Headers show
Series [-next] net/sched: use min() macro instead of doing it manually | expand

Checks

Context Check Description
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix warning Target tree name not specified in the subject
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 9 this patch: 9
netdev/cc_maintainers success CCed 6 of 6 maintainers
netdev/build_clang success Errors and warnings before: 20 this patch: 20
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 11 this patch: 11
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 24 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/tree_selection success Guessing tree name failed - patch did not apply

Commit Message

Yang Li Dec. 21, 2021, 1:14 a.m. UTC
Fix following coccicheck warnings:
./net/sched/cls_api.c:3333:17-18: WARNING opportunity for min()
./net/sched/cls_api.c:3389:17-18: WARNING opportunity for min()
./net/sched/cls_api.c:3427:17-18: WARNING opportunity for min()

Reported-by: Abaci Robot <abaci@linux.alibaba.com>
Signed-off-by: Yang Li <yang.lee@linux.alibaba.com>
---
 net/sched/cls_api.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

patchwork-bot+netdevbpf@kernel.org Dec. 21, 2021, 10:20 a.m. UTC | #1
Hello:

This patch was applied to netdev/net-next.git (master)
by David S. Miller <davem@davemloft.net>:

On Tue, 21 Dec 2021 09:14:55 +0800 you wrote:
> Fix following coccicheck warnings:
> ./net/sched/cls_api.c:3333:17-18: WARNING opportunity for min()
> ./net/sched/cls_api.c:3389:17-18: WARNING opportunity for min()
> ./net/sched/cls_api.c:3427:17-18: WARNING opportunity for min()
> 
> Reported-by: Abaci Robot <abaci@linux.alibaba.com>
> Signed-off-by: Yang Li <yang.lee@linux.alibaba.com>
> 
> [...]

Here is the summary with links:
  - [-next] net/sched: use min() macro instead of doing it manually
    https://git.kernel.org/netdev/net-next/c/c48c94b0ab75

You are awesome, thank you!
Joe Perches Dec. 21, 2021, 10:47 a.m. UTC | #2
On Tue, 2021-12-21 at 10:20 +0000, patchwork-bot+netdevbpf@kernel.org
wrote:
> Hello:
> 
> This patch was applied to netdev/net-next.git (master)
> by David S. Miller <davem@davemloft.net>:
> 
> On Tue, 21 Dec 2021 09:14:55 +0800 you wrote:
> > Fix following coccicheck warnings:
> > ./net/sched/cls_api.c:3333:17-18: WARNING opportunity for min()
> > ./net/sched/cls_api.c:3389:17-18: WARNING opportunity for min()
> > ./net/sched/cls_api.c:3427:17-18: WARNING opportunity for min()
> > 
> > Reported-by: Abaci Robot <abaci@linux.alibaba.com>
> > Signed-off-by: Yang Li <yang.lee@linux.alibaba.com>
> > 
> > [...]
> 
> Here is the summary with links:
>   - [-next] net/sched: use min() macro instead of doing it manually
>     https://git.kernel.org/netdev/net-next/c/c48c94b0ab75
> 
> You are awesome, thank you!

The patch contained instances like:

---
diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c
[]
@@ -3333,7 +3333,7 @@ int tc_setup_cb_add(struct tcf_block *block, struct tcf_proto *tp,
 	up_read(&block->cb_lock);
 	if (take_rtnl)
 		rtnl_unlock();
-	return ok_count < 0 ? ok_count : 0;
+	return min(ok_count, 0);
 }
---

I think all of these min uses are somewhat obfuscating and not the
typically used kernel pattern.

If count is negative, it's an error return.

I believe the code would be clearer and more typical if written as:

	if (ok_count < 0)
		return ok_count;

	return 0;
}

The compiler should produce the same object code.
diff mbox series

Patch

diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c
index c93699ddae36..a53c72e6d944 100644
--- a/net/sched/cls_api.c
+++ b/net/sched/cls_api.c
@@ -3333,7 +3333,7 @@  int tc_setup_cb_add(struct tcf_block *block, struct tcf_proto *tp,
 	up_read(&block->cb_lock);
 	if (take_rtnl)
 		rtnl_unlock();
-	return ok_count < 0 ? ok_count : 0;
+	return min(ok_count, 0);
 }
 EXPORT_SYMBOL(tc_setup_cb_add);
 
@@ -3389,7 +3389,7 @@  int tc_setup_cb_replace(struct tcf_block *block, struct tcf_proto *tp,
 	up_read(&block->cb_lock);
 	if (take_rtnl)
 		rtnl_unlock();
-	return ok_count < 0 ? ok_count : 0;
+	return min(ok_count, 0);
 }
 EXPORT_SYMBOL(tc_setup_cb_replace);
 
@@ -3427,7 +3427,7 @@  int tc_setup_cb_destroy(struct tcf_block *block, struct tcf_proto *tp,
 	up_read(&block->cb_lock);
 	if (take_rtnl)
 		rtnl_unlock();
-	return ok_count < 0 ? ok_count : 0;
+	return min(ok_count, 0);
 }
 EXPORT_SYMBOL(tc_setup_cb_destroy);