public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: Jiangshan Yi <13667453960@163.com>
Cc: rafael@kernel.org, dri-devel@lists.freedesktop.org,
	linux-kernel@vger.kernel.org,
	Jiangshan Yi <yijiangshan@kylinos.cn>
Subject: Re: [PATCH] component: replace ternary operator with min()
Date: Tue, 12 Jul 2022 09:17:58 +0200	[thread overview]
Message-ID: <Ys0gJlsZap/Qd1Gi@kroah.com> (raw)
In-Reply-To: <20220712071223.301160-1-13667453960@163.com>

On Tue, Jul 12, 2022 at 03:12:23PM +0800, Jiangshan Yi wrote:
> From: Jiangshan Yi <yijiangshan@kylinos.cn>
> 
> Fix the following coccicheck warning:
> 
> drivers/base/component.c:544: WARNING opportunity for min().
> drivers/base/component.c:740: WARNING opportunity for min().
> 
> min() macro is defined in include/linux/minmax.h. It avoids
> multiple evaluations of the arguments when non-constant and performs
> strict type-checking.
> 
> Signed-off-by: Jiangshan Yi <yijiangshan@kylinos.cn>
> ---
>  drivers/base/component.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/base/component.c b/drivers/base/component.c
> index 5eadeac6c532..349c54694481 100644
> --- a/drivers/base/component.c
> +++ b/drivers/base/component.c
> @@ -541,7 +541,7 @@ int component_master_add_with_match(struct device *parent,
>  
>  	mutex_unlock(&component_mutex);
>  
> -	return ret < 0 ? ret : 0;
> +	return min(ret, 0);

This is a traditional "if there is an error, report it, otherwise return
0" pattern, and not really a min() call.  So perhaps the original should
stay, or be turned into:
	if (ret < 0)
		return ret
	return 0;
to make it more obvious?

thanks,

greg k-h

      reply	other threads:[~2022-07-12  7:18 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-12  7:12 [PATCH] component: replace ternary operator with min() Jiangshan Yi
2022-07-12  7:17 ` Greg KH [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=Ys0gJlsZap/Qd1Gi@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=13667453960@163.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rafael@kernel.org \
    --cc=yijiangshan@kylinos.cn \
    /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