diff mbox series

[-next,3/3] drm/amdgpu: use clamp() in nvkm_volt_map()

Message ID 20240830012216.603623-4-lizetao1@huawei.com (mailing list archive)
State New, archived
Headers show
Series drm: use clamp() instead of min(max()) | expand

Commit Message

Li Zetao Aug. 30, 2024, 1:22 a.m. UTC
When it needs to get a value within a certain interval, using clamp()
makes the code easier to understand than min(max()).

Signed-off-by: Li Zetao <lizetao1@huawei.com>
---
 drivers/gpu/drm/nouveau/nvkm/subdev/volt/base.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Alex Deucher Aug. 30, 2024, 1:45 p.m. UTC | #1
The patch title prefix should say drm/nouveau.

Alex

On Fri, Aug 30, 2024 at 3:15 AM Li Zetao <lizetao1@huawei.com> wrote:
>
> When it needs to get a value within a certain interval, using clamp()
> makes the code easier to understand than min(max()).
>
> Signed-off-by: Li Zetao <lizetao1@huawei.com>
> ---
>  drivers/gpu/drm/nouveau/nvkm/subdev/volt/base.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/volt/base.c b/drivers/gpu/drm/nouveau/nvkm/subdev/volt/base.c
> index a17a6dd8d3de..803b98df4858 100644
> --- a/drivers/gpu/drm/nouveau/nvkm/subdev/volt/base.c
> +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/volt/base.c
> @@ -142,7 +142,7 @@ nvkm_volt_map(struct nvkm_volt *volt, u8 id, u8 temp)
>                         return -ENODEV;
>                 }
>
> -               result = min(max(result, (s64)info.min), (s64)info.max);
> +               result = clamp(result, (s64)info.min, (s64)info.max);
>
>                 if (info.link != 0xff) {
>                         int ret = nvkm_volt_map(volt, info.link, temp);
> --
> 2.34.1
>
Lyude Paul Aug. 30, 2024, 8:24 p.m. UTC | #2
As long as you make sure to fix the patch name from drm/amdgpu to drm/nouveau
like Alex mentioned:

Reviewed-by: Lyude Paul <lyude@redhat.com>

On Fri, 2024-08-30 at 09:22 +0800, Li Zetao wrote:
> When it needs to get a value within a certain interval, using clamp()
> makes the code easier to understand than min(max()).
> 
> Signed-off-by: Li Zetao <lizetao1@huawei.com>
> ---
>  drivers/gpu/drm/nouveau/nvkm/subdev/volt/base.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/volt/base.c b/drivers/gpu/drm/nouveau/nvkm/subdev/volt/base.c
> index a17a6dd8d3de..803b98df4858 100644
> --- a/drivers/gpu/drm/nouveau/nvkm/subdev/volt/base.c
> +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/volt/base.c
> @@ -142,7 +142,7 @@ nvkm_volt_map(struct nvkm_volt *volt, u8 id, u8 temp)
>  			return -ENODEV;
>  		}
>  
> -		result = min(max(result, (s64)info.min), (s64)info.max);
> +		result = clamp(result, (s64)info.min, (s64)info.max);
>  
>  		if (info.link != 0xff) {
>  			int ret = nvkm_volt_map(volt, info.link, temp);
diff mbox series

Patch

diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/volt/base.c b/drivers/gpu/drm/nouveau/nvkm/subdev/volt/base.c
index a17a6dd8d3de..803b98df4858 100644
--- a/drivers/gpu/drm/nouveau/nvkm/subdev/volt/base.c
+++ b/drivers/gpu/drm/nouveau/nvkm/subdev/volt/base.c
@@ -142,7 +142,7 @@  nvkm_volt_map(struct nvkm_volt *volt, u8 id, u8 temp)
 			return -ENODEV;
 		}
 
-		result = min(max(result, (s64)info.min), (s64)info.max);
+		result = clamp(result, (s64)info.min, (s64)info.max);
 
 		if (info.link != 0xff) {
 			int ret = nvkm_volt_map(volt, info.link, temp);