mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: patchwork-bot+netdevbpf@kernel.org, Yang Li <yang.lee@linux.alibaba.com>
Cc: davem@davemloft.net, kuba@kernel.org, jhs@mojatatu.com,
	xiyou.wangcong@gmail.com, jiri@resnulli.us,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	abaci@linux.alibaba.com
Subject: Re: [PATCH -next] net/sched: use min() macro instead of doing it manually
Date: Tue, 21 Dec 2021 02:47:44 -0800	[thread overview]
Message-ID: <3f89cfece748d661cc0dc32b29704a3c0fa17fe4.camel@perches.com> (raw)
In-Reply-To: <164008201003.19926.3019516223695943322.git-patchwork-notify@kernel.org>

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.



      reply	other threads:[~2021-12-21 10:47 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-21  1:14 Yang Li
2021-12-21 10:20 ` patchwork-bot+netdevbpf
2021-12-21 10:47   ` Joe Perches [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3f89cfece748d661cc0dc32b29704a3c0fa17fe4.camel@perches.com \
    --to=joe@perches.com \
    --cc=abaci@linux.alibaba.com \
    --cc=davem@davemloft.net \
    --cc=jhs@mojatatu.com \
    --cc=jiri@resnulli.us \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=patchwork-bot+netdevbpf@kernel.org \
    --cc=xiyou.wangcong@gmail.com \
    --cc=yang.lee@linux.alibaba.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®