Re: [PATCH] drm/amdgpu: use ARRAY_SIZE() to add amdgpu debugfs files

2020-07-13 Thread Christian König

Am 13.07.20 um 15:34 schrieb Yuan, Xiaojie:

[AMD Official Use Only - Internal Distribution Only]

Hi Chris,

This was observed when I was trying to add a new debugfs file.


In this case please add the new file using debugfs_create_file() 
directly and don't touch this old code.



  Some similar
occurrences using ARRAY_SIZE() are:

- amdgpu_kms.c :: amdgpu_firmware_info_list
- amdgpu_pm.c :: amdgpu_debugfs_pm_info
- amdgpu_ttm.c :: amdgpu_ttm_debugfs_list
- amdgpu_dm_debugfs.c :: amdgpu_dm_debugfs_list

This patch simply unified the usage of amdgpu_debugfs_add_files().

BTW, do you intended to use:
debugfs_create_file() - need to call debugfs_remove() explicitly
or the drm helper
drm_debugfs_create_files() - debugfs files will be removed automatically


No, exactly that's the point. All debugfs files are automatically 
removed when the driver unloads because the parent directory is removed.


See the debugfs.h file in the Linux source code:

void  debugfs_remove 
<https://elixir.bootlin.com/linux/latest/C/ident/debugfs_remove>(struct  dentry <https://elixir.bootlin.com/linux/latest/C/ident/dentry>  *dentry <https://elixir.bootlin.com/linux/latest/C/ident/dentry>);
#define debugfs_remove_recursive 
<https://elixir.bootlin.com/linux/latest/C/ident/debugfs_remove_recursive> 
debugfs_remove 
<https://elixir.bootlin.com/linux/latest/C/ident/debugfs_remove>


The whole tracking amdgpu_debugfs_add_files() and the underlying DRM 
function do are completely nonsense and was only added because somebody 
didn't knew that this stuff is automatically removed.


The only functionality amdgpu_debugfs_add_files() still provides is 
protecting to not try to add files twice. And that in turn is a coding 
bug we should probably fix :)


Regards,
Christian.



If so, we need a separate patch to cleanup them in a batch.

BR,
Xiaojie


From: Christian König 
Sent: Monday, July 13, 2020 4:38 PM
To: Yuan, Xiaojie; amd-gfx@lists.freedesktop.org
Subject: Re: [PATCH] drm/amdgpu: use ARRAY_SIZE() to add amdgpu debugfs files

Am 13.07.20 um 07:59 schrieb Xiaojie Yuan:

to easily add new debugfs file w/o changing the hardcoded list count.

In general a good idea, but I would rather like to see
amdgpu_debugfs_add_files() completely removed and debugfs_create_file()
used directly instead.

Christian.


Signed-off-by: Xiaojie Yuan 
---
   drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c | 6 --
   drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c   | 3 ++-
   drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c| 3 ++-
   3 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c
index b8ce43c28116..58d4c219178a 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c
@@ -781,8 +781,10 @@ int amdgpu_debugfs_fence_init(struct amdgpu_device *adev)
   {
   #if defined(CONFIG_DEBUG_FS)
   if (amdgpu_sriov_vf(adev))
- return amdgpu_debugfs_add_files(adev, 
amdgpu_debugfs_fence_list_sriov, 1);
- return amdgpu_debugfs_add_files(adev, amdgpu_debugfs_fence_list, 2);
+ return amdgpu_debugfs_add_files(adev, 
amdgpu_debugfs_fence_list_sriov,
+ 
ARRAY_SIZE(amdgpu_debugfs_fence_list_sriov));
+ return amdgpu_debugfs_add_files(adev, amdgpu_debugfs_fence_list,
+ ARRAY_SIZE(amdgpu_debugfs_fence_list));
   #else
   return 0;
   #endif
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
index 77d988a0033f..8c64d8d6cb82 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
@@ -928,7 +928,8 @@ static const struct drm_info_list amdgpu_debugfs_gem_list[] 
= {
   int amdgpu_debugfs_gem_init(struct amdgpu_device *adev)
   {
   #if defined(CONFIG_DEBUG_FS)
- return amdgpu_debugfs_add_files(adev, amdgpu_debugfs_gem_list, 1);
+ return amdgpu_debugfs_add_files(adev, amdgpu_debugfs_gem_list,
+ ARRAY_SIZE(amdgpu_debugfs_gem_list));
   #endif
   return 0;
   }
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c
index 4ffc32b78745..dcd492170598 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c
@@ -468,7 +468,8 @@ static const struct drm_info_list amdgpu_debugfs_sa_list[] 
= {
   int amdgpu_debugfs_sa_init(struct amdgpu_device *adev)
   {
   #if defined(CONFIG_DEBUG_FS)
- return amdgpu_debugfs_add_files(adev, amdgpu_debugfs_sa_list, 1);
+ return amdgpu_debugfs_add_files(adev, amdgpu_debugfs_sa_list,
+ ARRAY_SIZE(amdgpu_debugfs_sa_list));
   #else
   return 0;
   #endif


___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


Re: [PATCH] drm/amdgpu: use ARRAY_SIZE() to add amdgpu debugfs files

2020-07-13 Thread Yuan, Xiaojie
[AMD Official Use Only - Internal Distribution Only]

Hi Chris,

This was observed when I was trying to add a new debugfs file. Some similar
occurrences using ARRAY_SIZE() are:

- amdgpu_kms.c :: amdgpu_firmware_info_list
- amdgpu_pm.c :: amdgpu_debugfs_pm_info
- amdgpu_ttm.c :: amdgpu_ttm_debugfs_list
- amdgpu_dm_debugfs.c :: amdgpu_dm_debugfs_list

This patch simply unified the usage of amdgpu_debugfs_add_files().

BTW, do you intended to use:
debugfs_create_file() - need to call debugfs_remove() explicitly
or the drm helper
drm_debugfs_create_files() - debugfs files will be removed automatically

If so, we need a separate patch to cleanup them in a batch.

BR,
Xiaojie


From: Christian König 
Sent: Monday, July 13, 2020 4:38 PM
To: Yuan, Xiaojie; amd-gfx@lists.freedesktop.org
Subject: Re: [PATCH] drm/amdgpu: use ARRAY_SIZE() to add amdgpu debugfs files

Am 13.07.20 um 07:59 schrieb Xiaojie Yuan:
> to easily add new debugfs file w/o changing the hardcoded list count.

In general a good idea, but I would rather like to see
amdgpu_debugfs_add_files() completely removed and debugfs_create_file()
used directly instead.

Christian.

>
> Signed-off-by: Xiaojie Yuan 
> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c | 6 --
>   drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c   | 3 ++-
>   drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c| 3 ++-
>   3 files changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c
> index b8ce43c28116..58d4c219178a 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c
> @@ -781,8 +781,10 @@ int amdgpu_debugfs_fence_init(struct amdgpu_device *adev)
>   {
>   #if defined(CONFIG_DEBUG_FS)
>   if (amdgpu_sriov_vf(adev))
> - return amdgpu_debugfs_add_files(adev, 
> amdgpu_debugfs_fence_list_sriov, 1);
> - return amdgpu_debugfs_add_files(adev, amdgpu_debugfs_fence_list, 2);
> + return amdgpu_debugfs_add_files(adev, 
> amdgpu_debugfs_fence_list_sriov,
> + 
> ARRAY_SIZE(amdgpu_debugfs_fence_list_sriov));
> + return amdgpu_debugfs_add_files(adev, amdgpu_debugfs_fence_list,
> + ARRAY_SIZE(amdgpu_debugfs_fence_list));
>   #else
>   return 0;
>   #endif
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
> index 77d988a0033f..8c64d8d6cb82 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
> @@ -928,7 +928,8 @@ static const struct drm_info_list 
> amdgpu_debugfs_gem_list[] = {
>   int amdgpu_debugfs_gem_init(struct amdgpu_device *adev)
>   {
>   #if defined(CONFIG_DEBUG_FS)
> - return amdgpu_debugfs_add_files(adev, amdgpu_debugfs_gem_list, 1);
> + return amdgpu_debugfs_add_files(adev, amdgpu_debugfs_gem_list,
> + ARRAY_SIZE(amdgpu_debugfs_gem_list));
>   #endif
>   return 0;
>   }
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c
> index 4ffc32b78745..dcd492170598 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c
> @@ -468,7 +468,8 @@ static const struct drm_info_list 
> amdgpu_debugfs_sa_list[] = {
>   int amdgpu_debugfs_sa_init(struct amdgpu_device *adev)
>   {
>   #if defined(CONFIG_DEBUG_FS)
> - return amdgpu_debugfs_add_files(adev, amdgpu_debugfs_sa_list, 1);
> + return amdgpu_debugfs_add_files(adev, amdgpu_debugfs_sa_list,
> + ARRAY_SIZE(amdgpu_debugfs_sa_list));
>   #else
>   return 0;
>   #endif

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


Re: [PATCH] drm/amdgpu: use ARRAY_SIZE() to add amdgpu debugfs files

2020-07-13 Thread Christian König

Am 13.07.20 um 07:59 schrieb Xiaojie Yuan:

to easily add new debugfs file w/o changing the hardcoded list count.


In general a good idea, but I would rather like to see 
amdgpu_debugfs_add_files() completely removed and debugfs_create_file() 
used directly instead.


Christian.



Signed-off-by: Xiaojie Yuan 
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c | 6 --
  drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c   | 3 ++-
  drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c| 3 ++-
  3 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c
index b8ce43c28116..58d4c219178a 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c
@@ -781,8 +781,10 @@ int amdgpu_debugfs_fence_init(struct amdgpu_device *adev)
  {
  #if defined(CONFIG_DEBUG_FS)
if (amdgpu_sriov_vf(adev))
-   return amdgpu_debugfs_add_files(adev, 
amdgpu_debugfs_fence_list_sriov, 1);
-   return amdgpu_debugfs_add_files(adev, amdgpu_debugfs_fence_list, 2);
+   return amdgpu_debugfs_add_files(adev, 
amdgpu_debugfs_fence_list_sriov,
+   
ARRAY_SIZE(amdgpu_debugfs_fence_list_sriov));
+   return amdgpu_debugfs_add_files(adev, amdgpu_debugfs_fence_list,
+   ARRAY_SIZE(amdgpu_debugfs_fence_list));
  #else
return 0;
  #endif
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
index 77d988a0033f..8c64d8d6cb82 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
@@ -928,7 +928,8 @@ static const struct drm_info_list amdgpu_debugfs_gem_list[] 
= {
  int amdgpu_debugfs_gem_init(struct amdgpu_device *adev)
  {
  #if defined(CONFIG_DEBUG_FS)
-   return amdgpu_debugfs_add_files(adev, amdgpu_debugfs_gem_list, 1);
+   return amdgpu_debugfs_add_files(adev, amdgpu_debugfs_gem_list,
+   ARRAY_SIZE(amdgpu_debugfs_gem_list));
  #endif
return 0;
  }
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c
index 4ffc32b78745..dcd492170598 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c
@@ -468,7 +468,8 @@ static const struct drm_info_list amdgpu_debugfs_sa_list[] 
= {
  int amdgpu_debugfs_sa_init(struct amdgpu_device *adev)
  {
  #if defined(CONFIG_DEBUG_FS)
-   return amdgpu_debugfs_add_files(adev, amdgpu_debugfs_sa_list, 1);
+   return amdgpu_debugfs_add_files(adev, amdgpu_debugfs_sa_list,
+   ARRAY_SIZE(amdgpu_debugfs_sa_list));
  #else
return 0;
  #endif


___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


RE: [PATCH] drm/amdgpu: use ARRAY_SIZE() to add amdgpu debugfs files

2020-07-13 Thread Zhang, Hawking
[AMD Public Use]

Reviewed-by: Hawking Zhang 

Regards,
Hawking
-Original Message-
From: amd-gfx  On Behalf Of Xiaojie Yuan
Sent: Monday, July 13, 2020 14:00
To: amd-gfx@lists.freedesktop.org
Cc: Yuan, Xiaojie 
Subject: [PATCH] drm/amdgpu: use ARRAY_SIZE() to add amdgpu debugfs files

to easily add new debugfs file w/o changing the hardcoded list count.

Signed-off-by: Xiaojie Yuan 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c | 6 --
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c   | 3 ++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c| 3 ++-
 3 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c
index b8ce43c28116..58d4c219178a 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c
@@ -781,8 +781,10 @@ int amdgpu_debugfs_fence_init(struct amdgpu_device *adev)  
{  #if defined(CONFIG_DEBUG_FS)
if (amdgpu_sriov_vf(adev))
-   return amdgpu_debugfs_add_files(adev, 
amdgpu_debugfs_fence_list_sriov, 1);
-   return amdgpu_debugfs_add_files(adev, amdgpu_debugfs_fence_list, 2);
+   return amdgpu_debugfs_add_files(adev, 
amdgpu_debugfs_fence_list_sriov,
+   
ARRAY_SIZE(amdgpu_debugfs_fence_list_sriov));
+   return amdgpu_debugfs_add_files(adev, amdgpu_debugfs_fence_list,
+   ARRAY_SIZE(amdgpu_debugfs_fence_list));
 #else
return 0;
 #endif
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
index 77d988a0033f..8c64d8d6cb82 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
@@ -928,7 +928,8 @@ static const struct drm_info_list amdgpu_debugfs_gem_list[] 
= {  int amdgpu_debugfs_gem_init(struct amdgpu_device *adev)  {  #if 
defined(CONFIG_DEBUG_FS)
-   return amdgpu_debugfs_add_files(adev, amdgpu_debugfs_gem_list, 1);
+   return amdgpu_debugfs_add_files(adev, amdgpu_debugfs_gem_list,
+   ARRAY_SIZE(amdgpu_debugfs_gem_list));
 #endif
return 0;
 }
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c
index 4ffc32b78745..dcd492170598 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c
@@ -468,7 +468,8 @@ static const struct drm_info_list amdgpu_debugfs_sa_list[] 
= {  int amdgpu_debugfs_sa_init(struct amdgpu_device *adev)  {  #if 
defined(CONFIG_DEBUG_FS)
-   return amdgpu_debugfs_add_files(adev, amdgpu_debugfs_sa_list, 1);
+   return amdgpu_debugfs_add_files(adev, amdgpu_debugfs_sa_list,
+   ARRAY_SIZE(amdgpu_debugfs_sa_list));
 #else
return 0;
 #endif
--
2.20.1

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfxdata=02%7C01%7Chawking.zhang%40amd.com%7C22bf311806fe4925f70c08d826f206b6%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637302168223168477sdata=4U%2BsydWtuJp3XUmMmB9H8ApnBORKYF9eL5yRBjQgYa4%3Dreserved=0
___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


Re: [PATCH] drm/amdgpu: use ARRAY_SIZE

2017-10-16 Thread Alex Deucher
On Mon, Oct 16, 2017 at 3:48 AM, Christian König
 wrote:
> Am 16.10.2017 um 04:29 schrieb Jérémy Lefaure:
>>
>> Using the ARRAY_SIZE macro improves the readability of the code.
>>
>> Found with Coccinelle with the following semantic patch:
>> @r depends on (org || report)@
>> type T;
>> T[] E;
>> position p;
>> @@
>> (
>>   (sizeof(E)@p /sizeof(*E))
>> |
>>   (sizeof(E)@p /sizeof(E[...]))
>> |
>>   (sizeof(E)@p /sizeof(T))
>> )
>>
>> Reviewed-by: Thierry Reding 
>> Signed-off-by: Jérémy Lefaure 
>
>
> Reviewed-by: Christian König 
>

Applied. Thanks!

Alex


>
>> ---
>> This patch was part of a bigger patch [1] reviewed by Thierry Reding
>> before it was split in several patches.
>>
>> [1]: https://patchwork.kernel.org/patch/9979843/
>>
>>   drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c | 9 +
>>   drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c | 9 +
>>   2 files changed, 10 insertions(+), 8 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
>> b/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
>> index 147e92b3a959..c9f542b4e05c 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
>> @@ -20,6 +20,7 @@
>>* OTHER DEALINGS IN THE SOFTWARE.
>>*
>>*/
>> +#include 
>>   #include 
>>   #include 
>>   #include "amdgpu.h"
>> @@ -3952,10 +3953,10 @@ static int gfx_v8_0_init_save_restore_list(struct
>> amdgpu_device *adev)
>> adev->gfx.rlc.reg_list_format_size_bytes
>> >> 2,
>> unique_indices,
>> _count,
>> -   sizeof(unique_indices) / sizeof(int),
>> +   ARRAY_SIZE(unique_indices),
>> indirect_start_offsets,
>> _count,
>> -
>> sizeof(indirect_start_offsets)/sizeof(int));
>> +   ARRAY_SIZE(indirect_start_offsets));
>> /* save and restore list */
>> WREG32_FIELD(RLC_SRM_CNTL, AUTO_INCR_ADDR, 1);
>> @@ -3977,14 +3978,14 @@ static int gfx_v8_0_init_save_restore_list(struct
>> amdgpu_device *adev)
>> /* starting offsets starts */
>> WREG32(mmRLC_GPM_SCRATCH_ADDR,
>> adev->gfx.rlc.starting_offsets_start);
>> -   for (i = 0; i < sizeof(indirect_start_offsets)/sizeof(int); i++)
>> +   for (i = 0; i < ARRAY_SIZE(indirect_start_offsets); i++)
>> WREG32(mmRLC_GPM_SCRATCH_DATA,
>> indirect_start_offsets[i]);
>> /* unique indices */
>> temp = mmRLC_SRM_INDEX_CNTL_ADDR_0;
>> data = mmRLC_SRM_INDEX_CNTL_DATA_0;
>> -   for (i = 0; i < sizeof(unique_indices) / sizeof(int); i++) {
>> +   for (i = 0; i < ARRAY_SIZE(unique_indices); i++) {
>> if (unique_indices[i] != 0) {
>> WREG32(temp + i, unique_indices[i] & 0x3);
>> WREG32(data + i, unique_indices[i] >> 20);
>> diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c
>> b/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c
>> index 99a5b3b92e8e..7f15bb2c5233 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c
>> @@ -20,6 +20,7 @@
>>* OTHER DEALINGS IN THE SOFTWARE.
>>*
>>*/
>> +#include 
>>   #include 
>>   #include 
>>   #include "amdgpu.h"
>> @@ -1730,10 +1731,10 @@ static int
>> gfx_v9_0_init_rlc_save_restore_list(struct amdgpu_device *adev)
>> adev->gfx.rlc.reg_list_format_size_bytes
>> >> 2,
>> unique_indirect_regs,
>> _indirect_reg_count,
>> -   sizeof(unique_indirect_regs)/sizeof(int),
>> +   ARRAY_SIZE(unique_indirect_regs),
>> indirect_start_offsets,
>> _start_offsets_count,
>> -
>> sizeof(indirect_start_offsets)/sizeof(int));
>> +   ARRAY_SIZE(indirect_start_offsets));
>> /* enable auto inc in case it is disabled */
>> tmp = RREG32(SOC15_REG_OFFSET(GC, 0, mmRLC_SRM_CNTL));
>> @@ -1770,12 +1771,12 @@ static int
>> gfx_v9_0_init_rlc_save_restore_list(struct amdgpu_device *adev)
>> /* write the starting offsets to RLC scratch ram */
>> WREG32(SOC15_REG_OFFSET(GC, 0, mmRLC_GPM_SCRATCH_ADDR),
>> adev->gfx.rlc.starting_offsets_start);
>> -   for (i = 0; i < sizeof(indirect_start_offsets)/sizeof(int); i++)
>> +   for (i = 0; i < ARRAY_SIZE(indirect_start_offsets); i++)
>> WREG32(SOC15_REG_OFFSET(GC, 0, mmRLC_GPM_SCRATCH_DATA),
>> indirect_start_offsets[i]);
>> /* load unique indirect regs*/
>> -   for (i = 0; i < sizeof(unique_indirect_regs)/sizeof(int); i++) {
>> +   for (i = 

Re: [PATCH] drm/amdgpu: use ARRAY_SIZE

2017-10-16 Thread Christian König

Am 16.10.2017 um 04:29 schrieb Jérémy Lefaure:

Using the ARRAY_SIZE macro improves the readability of the code.

Found with Coccinelle with the following semantic patch:
@r depends on (org || report)@
type T;
T[] E;
position p;
@@
(
  (sizeof(E)@p /sizeof(*E))
|
  (sizeof(E)@p /sizeof(E[...]))
|
  (sizeof(E)@p /sizeof(T))
)

Reviewed-by: Thierry Reding 
Signed-off-by: Jérémy Lefaure 


Reviewed-by: Christian König 


---
This patch was part of a bigger patch [1] reviewed by Thierry Reding
before it was split in several patches.

[1]: https://patchwork.kernel.org/patch/9979843/

  drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c | 9 +
  drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c | 9 +
  2 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c 
b/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
index 147e92b3a959..c9f542b4e05c 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
@@ -20,6 +20,7 @@
   * OTHER DEALINGS IN THE SOFTWARE.
   *
   */
+#include 
  #include 
  #include 
  #include "amdgpu.h"
@@ -3952,10 +3953,10 @@ static int gfx_v8_0_init_save_restore_list(struct 
amdgpu_device *adev)
adev->gfx.rlc.reg_list_format_size_bytes >> 2,
unique_indices,
_count,
-   sizeof(unique_indices) / sizeof(int),
+   ARRAY_SIZE(unique_indices),
indirect_start_offsets,
_count,
-   sizeof(indirect_start_offsets)/sizeof(int));
+   ARRAY_SIZE(indirect_start_offsets));
  
  	/* save and restore list */

WREG32_FIELD(RLC_SRM_CNTL, AUTO_INCR_ADDR, 1);
@@ -3977,14 +3978,14 @@ static int gfx_v8_0_init_save_restore_list(struct 
amdgpu_device *adev)
/* starting offsets starts */
WREG32(mmRLC_GPM_SCRATCH_ADDR,
adev->gfx.rlc.starting_offsets_start);
-   for (i = 0; i < sizeof(indirect_start_offsets)/sizeof(int); i++)
+   for (i = 0; i < ARRAY_SIZE(indirect_start_offsets); i++)
WREG32(mmRLC_GPM_SCRATCH_DATA,
indirect_start_offsets[i]);
  
  	/* unique indices */

temp = mmRLC_SRM_INDEX_CNTL_ADDR_0;
data = mmRLC_SRM_INDEX_CNTL_DATA_0;
-   for (i = 0; i < sizeof(unique_indices) / sizeof(int); i++) {
+   for (i = 0; i < ARRAY_SIZE(unique_indices); i++) {
if (unique_indices[i] != 0) {
WREG32(temp + i, unique_indices[i] & 0x3);
WREG32(data + i, unique_indices[i] >> 20);
diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c 
b/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c
index 99a5b3b92e8e..7f15bb2c5233 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c
@@ -20,6 +20,7 @@
   * OTHER DEALINGS IN THE SOFTWARE.
   *
   */
+#include 
  #include 
  #include 
  #include "amdgpu.h"
@@ -1730,10 +1731,10 @@ static int gfx_v9_0_init_rlc_save_restore_list(struct 
amdgpu_device *adev)
adev->gfx.rlc.reg_list_format_size_bytes >> 2,
unique_indirect_regs,
_indirect_reg_count,
-   sizeof(unique_indirect_regs)/sizeof(int),
+   ARRAY_SIZE(unique_indirect_regs),
indirect_start_offsets,
_start_offsets_count,
-   sizeof(indirect_start_offsets)/sizeof(int));
+   ARRAY_SIZE(indirect_start_offsets));
  
  	/* enable auto inc in case it is disabled */

tmp = RREG32(SOC15_REG_OFFSET(GC, 0, mmRLC_SRM_CNTL));
@@ -1770,12 +1771,12 @@ static int gfx_v9_0_init_rlc_save_restore_list(struct 
amdgpu_device *adev)
/* write the starting offsets to RLC scratch ram */
WREG32(SOC15_REG_OFFSET(GC, 0, mmRLC_GPM_SCRATCH_ADDR),
adev->gfx.rlc.starting_offsets_start);
-   for (i = 0; i < sizeof(indirect_start_offsets)/sizeof(int); i++)
+   for (i = 0; i < ARRAY_SIZE(indirect_start_offsets); i++)
WREG32(SOC15_REG_OFFSET(GC, 0, mmRLC_GPM_SCRATCH_DATA),
indirect_start_offsets[i]);
  
  	/* load unique indirect regs*/

-   for (i = 0; i < sizeof(unique_indirect_regs)/sizeof(int); i++) {
+   for (i = 0; i < ARRAY_SIZE(unique_indirect_regs); i++) {
WREG32(SOC15_REG_OFFSET(GC, 0, mmRLC_SRM_INDEX_CNTL_ADDR_0) + i,
unique_indirect_regs[i] & 0x3);
WREG32(SOC15_REG_OFFSET(GC, 0, mmRLC_SRM_INDEX_CNTL_DATA_0) + i,



___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org