* [PATCH] component: replace ternary operator with min()
@ 2022-07-12 7:12 ` Jiangshan Yi
0 siblings, 0 replies; 4+ messages in thread
From: Jiangshan Yi @ 2022-07-12 7:12 UTC (permalink / raw)
To: gregkh, rafael; +Cc: dri-devel, linux-kernel, Jiangshan Yi
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);
}
EXPORT_SYMBOL_GPL(component_master_add_with_match);
@@ -737,7 +737,7 @@ static int __component_add(struct device *dev, const struct component_ops *ops,
}
mutex_unlock(&component_mutex);
- return ret < 0 ? ret : 0;
+ return min(ret, 0);
}
/**
--
2.25.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH] component: replace ternary operator with min()
@ 2022-07-12 7:12 ` Jiangshan Yi
0 siblings, 0 replies; 4+ messages in thread
From: Jiangshan Yi @ 2022-07-12 7:12 UTC (permalink / raw)
To: gregkh, rafael; +Cc: linux-kernel, dri-devel, Jiangshan Yi
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);
}
EXPORT_SYMBOL_GPL(component_master_add_with_match);
@@ -737,7 +737,7 @@ static int __component_add(struct device *dev, const struct component_ops *ops,
}
mutex_unlock(&component_mutex);
- return ret < 0 ? ret : 0;
+ return min(ret, 0);
}
/**
--
2.25.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] component: replace ternary operator with min()
2022-07-12 7:12 ` Jiangshan Yi
@ 2022-07-12 7:17 ` Greg KH
-1 siblings, 0 replies; 4+ messages in thread
From: Greg KH @ 2022-07-12 7:17 UTC (permalink / raw)
To: Jiangshan Yi; +Cc: rafael, dri-devel, linux-kernel, Jiangshan Yi
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] component: replace ternary operator with min()
@ 2022-07-12 7:17 ` Greg KH
0 siblings, 0 replies; 4+ messages in thread
From: Greg KH @ 2022-07-12 7:17 UTC (permalink / raw)
To: Jiangshan Yi; +Cc: Jiangshan Yi, linux-kernel, dri-devel, rafael
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
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-07-12 20:05 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-12 7:12 [PATCH] component: replace ternary operator with min() Jiangshan Yi
2022-07-12 7:12 ` Jiangshan Yi
2022-07-12 7:17 ` Greg KH
2022-07-12 7:17 ` Greg KH
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.