[Qemu-devel] [PATCH] util: vfio-helpers: use ARRAY_SIZE in qemu_vfio_init_pci()

Li Qiang posted 1 patch 5 years, 4 months ago
Test asan passed
Test checkpatch passed
Test docker-quick@centos7 passed
Test docker-mingw@fedora passed
Test docker-clang@ubuntu passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/1543571638-2892-1-git-send-email-liq3ea@gmail.com
util/vfio-helpers.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[Qemu-devel] [PATCH] util: vfio-helpers: use ARRAY_SIZE in qemu_vfio_init_pci()
Posted by Li Qiang 5 years, 4 months ago
Cc: qemu-trivial@nongnu.org

Signed-off-by: Li Qiang <liq3ea@gmail.com>
---
 util/vfio-helpers.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c
index cccc9cd42e..342d4a2285 100644
--- a/util/vfio-helpers.c
+++ b/util/vfio-helpers.c
@@ -348,7 +348,7 @@ static int qemu_vfio_init_pci(QEMUVFIOState *s, const char *device,
         goto fail;
     }
 
-    for (i = 0; i < 6; i++) {
+    for (i = 0; i < ARRAY_SIZE(s->bar_region_info); i++) {
         ret = qemu_vfio_pci_init_bar(s, i, errp);
         if (ret) {
             goto fail;
-- 
2.11.0


Re: [Qemu-devel] [PATCH] util: vfio-helpers: use ARRAY_SIZE in qemu_vfio_init_pci()
Posted by Philippe Mathieu-Daudé 5 years, 4 months ago
On 30/11/18 10:53, Li Qiang wrote:
> Cc: qemu-trivial@nongnu.org
> 
> Signed-off-by: Li Qiang <liq3ea@gmail.com>

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

> ---
>  util/vfio-helpers.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c
> index cccc9cd42e..342d4a2285 100644
> --- a/util/vfio-helpers.c
> +++ b/util/vfio-helpers.c
> @@ -348,7 +348,7 @@ static int qemu_vfio_init_pci(QEMUVFIOState *s, const char *device,
>          goto fail;
>      }
>  
> -    for (i = 0; i < 6; i++) {
> +    for (i = 0; i < ARRAY_SIZE(s->bar_region_info); i++) {
>          ret = qemu_vfio_pci_init_bar(s, i, errp);
>          if (ret) {
>              goto fail;
> 

Re: [Qemu-devel] [PATCH] util: vfio-helpers: use ARRAY_SIZE in qemu_vfio_init_pci()
Posted by Laurent Vivier 5 years, 4 months ago
On 30/11/2018 13:01, Philippe Mathieu-Daudé wrote:
> On 30/11/18 10:53, Li Qiang wrote:
>> Cc: qemu-trivial@nongnu.org
>>
>> Signed-off-by: Li Qiang <liq3ea@gmail.com>
> 
> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> 
>> ---
>>  util/vfio-helpers.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c
>> index cccc9cd42e..342d4a2285 100644
>> --- a/util/vfio-helpers.c
>> +++ b/util/vfio-helpers.c
>> @@ -348,7 +348,7 @@ static int qemu_vfio_init_pci(QEMUVFIOState *s, const char *device,
>>          goto fail;
>>      }
>>  
>> -    for (i = 0; i < 6; i++) {
>> +    for (i = 0; i < ARRAY_SIZE(s->bar_region_info); i++) {
>>          ret = qemu_vfio_pci_init_bar(s, i, errp);
>>          if (ret) {
>>              goto fail;
>>

I'm wondering if adding a #define to define the size of the array and
then using it with the for() loop wouldn't be better?

Laurent

Re: [Qemu-devel] [PATCH] util: vfio-helpers: use ARRAY_SIZE in qemu_vfio_init_pci()
Posted by Michael Tokarev 5 years, 4 months ago
30.11.2018 15:58, Laurent Vivier wrote:

>>> -    for (i = 0; i < 6; i++) {
>>> +    for (i = 0; i < ARRAY_SIZE(s->bar_region_info); i++) {

> I'm wondering if adding a #define to define the size of the array and
> then using it with the for() loop wouldn't be better?

On the other side, it doesn't really matter, one way or another..
It's so.. trivial.. ;)

/mjt

Re: [Qemu-devel] [Qemu-trivial] [PATCH] util: vfio-helpers: use ARRAY_SIZE in qemu_vfio_init_pci()
Posted by Laurent Vivier 5 years, 4 months ago
Le 30/11/2018 à 10:53, Li Qiang a écrit :
> Cc: qemu-trivial@nongnu.org
> 
> Signed-off-by: Li Qiang <liq3ea@gmail.com>
> ---
>  util/vfio-helpers.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c
> index cccc9cd42e..342d4a2285 100644
> --- a/util/vfio-helpers.c
> +++ b/util/vfio-helpers.c
> @@ -348,7 +348,7 @@ static int qemu_vfio_init_pci(QEMUVFIOState *s, const char *device,
>          goto fail;
>      }
>  
> -    for (i = 0; i < 6; i++) {
> +    for (i = 0; i < ARRAY_SIZE(s->bar_region_info); i++) {
>          ret = qemu_vfio_pci_init_bar(s, i, errp);
>          if (ret) {
>              goto fail;
> 

Applied to my trivial-patches branch.

Thanks,
Laurent