All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH -next] net/sched: use min() macro instead of doing it manually
@ 2021-12-21  1:14 Yang Li
  2021-12-21 10:20 ` patchwork-bot+netdevbpf
  0 siblings, 1 reply; 3+ messages in thread
From: Yang Li @ 2021-12-21  1:14 UTC (permalink / raw)
  To: davem
  Cc: kuba, jhs, xiyou.wangcong, jiri, netdev, linux-kernel, Yang Li,
	Abaci Robot

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

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);
 
-- 
2.20.1.7.g153144c


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

* Re: [PATCH -next] net/sched: use min() macro instead of doing it manually
  2021-12-21  1:14 [PATCH -next] net/sched: use min() macro instead of doing it manually Yang Li
@ 2021-12-21 10:20 ` patchwork-bot+netdevbpf
  2021-12-21 10:47   ` Joe Perches
  0 siblings, 1 reply; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-12-21 10:20 UTC (permalink / raw)
  To: Yang Li
  Cc: davem, kuba, jhs, xiyou.wangcong, jiri, netdev, linux-kernel, abaci

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!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

* Re: [PATCH -next] net/sched: use min() macro instead of doing it manually
  2021-12-21 10:20 ` patchwork-bot+netdevbpf
@ 2021-12-21 10:47   ` Joe Perches
  0 siblings, 0 replies; 3+ messages in thread
From: Joe Perches @ 2021-12-21 10:47 UTC (permalink / raw)
  To: patchwork-bot+netdevbpf, Yang Li
  Cc: davem, kuba, jhs, xiyou.wangcong, jiri, netdev, linux-kernel, abaci

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.



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

end of thread, other threads:[~2021-12-21 10:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-21  1:14 [PATCH -next] net/sched: use min() macro instead of doing it manually Yang Li
2021-12-21 10:20 ` patchwork-bot+netdevbpf
2021-12-21 10:47   ` Joe Perches

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.