* [PATCH] drm/amdgpu: Replace ternary operator with min() in 'amdgpu_iomem_read'
@ 2023-08-12 14:47 Srinivasan Shanmugam
2023-08-14 9:15 ` Christian König
0 siblings, 1 reply; 3+ messages in thread
From: Srinivasan Shanmugam @ 2023-08-12 14:47 UTC (permalink / raw)
To: Christian König, Alex Deucher, Guchun Chen, Pan Xinhui
Cc: Srinivasan Shanmugam, amd-gfx
Fixes the following coccicheck:
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c:2427:16-17: 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.
Cc: Guchun Chen <guchun.chen@amd.com>
Cc: Christian König <christian.koenig@amd.com>
Cc: Alex Deucher <alexander.deucher@amd.com>
Cc: "Pan, Xinhui" <Xinhui.Pan@amd.com>
Signed-off-by: Srinivasan Shanmugam <srinivasan.shanmugam@amd.com>
---
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
index df32785a8b36..c03fe7ee555b 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
@@ -2424,7 +2424,7 @@ static ssize_t amdgpu_iomem_read(struct file *f, char __user *buf,
struct page *p;
void *ptr;
- bytes = bytes < size ? bytes : size;
+ bytes = min(bytes, size);
/* Translate the bus address to a physical address. If
* the domain is NULL it means there is no IOMMU active
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] drm/amdgpu: Replace ternary operator with min() in 'amdgpu_iomem_read'
2023-08-12 14:47 [PATCH] drm/amdgpu: Replace ternary operator with min() in 'amdgpu_iomem_read' Srinivasan Shanmugam
@ 2023-08-14 9:15 ` Christian König
2023-08-14 9:31 ` SHANMUGAM, SRINIVASAN
0 siblings, 1 reply; 3+ messages in thread
From: Christian König @ 2023-08-14 9:15 UTC (permalink / raw)
To: Srinivasan Shanmugam, Alex Deucher, Guchun Chen, Pan Xinhui; +Cc: amd-gfx
Am 12.08.23 um 16:47 schrieb Srinivasan Shanmugam:
> Fixes the following coccicheck:
>
> drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c:2427:16-17: 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.
>
> Cc: Guchun Chen <guchun.chen@amd.com>
> Cc: Christian König <christian.koenig@amd.com>
> Cc: Alex Deucher <alexander.deucher@amd.com>
> Cc: "Pan, Xinhui" <Xinhui.Pan@amd.com>
> Signed-off-by: Srinivasan Shanmugam <srinivasan.shanmugam@amd.com>
Please double check that we don't need min_t() here.
With that done this patch and the _write variant are Reviewed-by:
Christian König <christian.koenig@amd.com>.
Regards,
Christian.
> ---
> drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> index df32785a8b36..c03fe7ee555b 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> @@ -2424,7 +2424,7 @@ static ssize_t amdgpu_iomem_read(struct file *f, char __user *buf,
> struct page *p;
> void *ptr;
>
> - bytes = bytes < size ? bytes : size;
> + bytes = min(bytes, size);
>
> /* Translate the bus address to a physical address. If
> * the domain is NULL it means there is no IOMMU active
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] drm/amdgpu: Replace ternary operator with min() in 'amdgpu_iomem_read'
2023-08-14 9:15 ` Christian König
@ 2023-08-14 9:31 ` SHANMUGAM, SRINIVASAN
0 siblings, 0 replies; 3+ messages in thread
From: SHANMUGAM, SRINIVASAN @ 2023-08-14 9:31 UTC (permalink / raw)
To: Christian König, Srinivasan Shanmugam, Alex Deucher,
Guchun Chen, Pan Xinhui
Cc: amd-gfx
On 8/14/2023 2:45 PM, Christian König wrote:
> Am 12.08.23 um 16:47 schrieb Srinivasan Shanmugam:
>> Fixes the following coccicheck:
>>
>> drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c:2427:16-17: 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.
>>
>> Cc: Guchun Chen <guchun.chen@amd.com>
>> Cc: Christian König <christian.koenig@amd.com>
>> Cc: Alex Deucher <alexander.deucher@amd.com>
>> Cc: "Pan, Xinhui" <Xinhui.Pan@amd.com>
>> Signed-off-by: Srinivasan Shanmugam <srinivasan.shanmugam@amd.com>
>
> Please double check that we don't need min_t() here.
Thanks a lot Christian for your reviews! Highly appreciate for your help!
min_t() is needed if there is any explict typecasting for any of the
variables passed to min() please.
For ex: some references pls:
1.
commit 3434392da74953727f6c27bcf24aa7d8ae789c80
Author: Srinivasan Shanmugam <srinivasan.shanmugam@amd.com>
Date: Sun Jul 23 12:29:14 2023 +0530
drm/amdgpu: Update min() to min_t() in 'amdgpu_info_ioctl'
2.
https://patchwork.kernel.org/project/linux-omap/patch/1307877290-26672-1-git-send-email-tlinder@codeaurora.org/#1917462
Best regards,
Srini
>
> With that done this patch and the _write variant are Reviewed-by:
> Christian König <christian.koenig@amd.com>.
>
> Regards,
> Christian.
>
>> ---
>> drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
>> index df32785a8b36..c03fe7ee555b 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
>> @@ -2424,7 +2424,7 @@ static ssize_t amdgpu_iomem_read(struct file
>> *f, char __user *buf,
>> struct page *p;
>> void *ptr;
>> - bytes = bytes < size ? bytes : size;
>> + bytes = min(bytes, size);
>> /* Translate the bus address to a physical address. If
>> * the domain is NULL it means there is no IOMMU active
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-08-14 9:31 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-12 14:47 [PATCH] drm/amdgpu: Replace ternary operator with min() in 'amdgpu_iomem_read' Srinivasan Shanmugam
2023-08-14 9:15 ` Christian König
2023-08-14 9:31 ` SHANMUGAM, SRINIVASAN
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox