qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] hw/vfio/platform: replace g_malloc0_n by g_malloc0
@ 2015-06-11  7:14 Eric Auger
  2015-06-11  7:55 ` Gonglei
  2015-06-11 11:11 ` Markus Armbruster
  0 siblings, 2 replies; 4+ messages in thread
From: Eric Auger @ 2015-06-11  7:14 UTC (permalink / raw)
  To: eric.auger, eric.auger, qemu-devel, alex.williamson,
	peter.maydell, arei.gonglei

g_malloc0_n() is introduced since glib-2.24 while QEMU currently
requires glib-2.22. This may cause a link error on some distributions.

Signed-off-by: Eric Auger <eric.auger@linaro.org>
---
 hw/vfio/platform.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/hw/vfio/platform.c b/hw/vfio/platform.c
index 35266a8..c0acc8b 100644
--- a/hw/vfio/platform.c
+++ b/hw/vfio/platform.c
@@ -346,8 +346,7 @@ static int vfio_populate_device(VFIODevice *vbasedev)
         return ret;
     }
 
-    vdev->regions = g_malloc0_n(vbasedev->num_regions,
-                                sizeof(VFIORegion *));
+    vdev->regions = g_malloc0(vbasedev->num_regions * sizeof(VFIORegion *));
 
     for (i = 0; i < vbasedev->num_regions; i++) {
         struct vfio_region_info reg_info = { .argsz = sizeof(reg_info) };
-- 
1.8.3.2

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH] hw/vfio/platform: replace g_malloc0_n by g_malloc0
  2015-06-11  7:14 [Qemu-devel] [PATCH] hw/vfio/platform: replace g_malloc0_n by g_malloc0 Eric Auger
@ 2015-06-11  7:55 ` Gonglei
  2015-06-11  8:46   ` Eric Auger
  2015-06-11 11:11 ` Markus Armbruster
  1 sibling, 1 reply; 4+ messages in thread
From: Gonglei @ 2015-06-11  7:55 UTC (permalink / raw)
  To: Eric Auger, eric.auger, qemu-devel, alex.williamson,
	peter.maydell

On 2015/6/11 15:14, Eric Auger wrote:
> g_malloc0_n() is introduced since glib-2.24 while QEMU currently
> requires glib-2.22. This may cause a link error on some distributions.
> 
> Signed-off-by: Eric Auger <eric.auger@linaro.org>
> ---
>  hw/vfio/platform.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/hw/vfio/platform.c b/hw/vfio/platform.c
> index 35266a8..c0acc8b 100644
> --- a/hw/vfio/platform.c
> +++ b/hw/vfio/platform.c
> @@ -346,8 +346,7 @@ static int vfio_populate_device(VFIODevice *vbasedev)
>          return ret;
>      }
>  
> -    vdev->regions = g_malloc0_n(vbasedev->num_regions,
> -                                sizeof(VFIORegion *));
> +    vdev->regions = g_malloc0(vbasedev->num_regions * sizeof(VFIORegion *));
>  

Why not use g_new0() which returned pointer is cast to the given type?

Regards,
-Gonglei
>      for (i = 0; i < vbasedev->num_regions; i++) {
>          struct vfio_region_info reg_info = { .argsz = sizeof(reg_info) };
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH] hw/vfio/platform: replace g_malloc0_n by g_malloc0
  2015-06-11  7:55 ` Gonglei
@ 2015-06-11  8:46   ` Eric Auger
  0 siblings, 0 replies; 4+ messages in thread
From: Eric Auger @ 2015-06-11  8:46 UTC (permalink / raw)
  To: Gonglei, eric.auger, qemu-devel, alex.williamson, peter.maydell

Hi Gonglei,
On 06/11/2015 09:55 AM, Gonglei wrote:
> On 2015/6/11 15:14, Eric Auger wrote:
>> g_malloc0_n() is introduced since glib-2.24 while QEMU currently
>> requires glib-2.22. This may cause a link error on some distributions.
>>
>> Signed-off-by: Eric Auger <eric.auger@linaro.org>
>> ---
>>  hw/vfio/platform.c | 3 +--
>>  1 file changed, 1 insertion(+), 2 deletions(-)
>>
>> diff --git a/hw/vfio/platform.c b/hw/vfio/platform.c
>> index 35266a8..c0acc8b 100644
>> --- a/hw/vfio/platform.c
>> +++ b/hw/vfio/platform.c
>> @@ -346,8 +346,7 @@ static int vfio_populate_device(VFIODevice *vbasedev)
>>          return ret;
>>      }
>>  
>> -    vdev->regions = g_malloc0_n(vbasedev->num_regions,
>> -                                sizeof(VFIORegion *));
>> +    vdev->regions = g_malloc0(vbasedev->num_regions * sizeof(VFIORegion *));
>>  
> 
> Why not use g_new0() which returned pointer is cast to the given type?
Looks relevant indeed.

g_malloc0 is used in similar situations in rest of the VFIO code so I
posted a new version and let Alex choose among both.

Thanks

Eric
> 
> Regards,
> -Gonglei
>>      for (i = 0; i < vbasedev->num_regions; i++) {
>>          struct vfio_region_info reg_info = { .argsz = sizeof(reg_info) };
>>
> 
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH] hw/vfio/platform: replace g_malloc0_n by g_malloc0
  2015-06-11  7:14 [Qemu-devel] [PATCH] hw/vfio/platform: replace g_malloc0_n by g_malloc0 Eric Auger
  2015-06-11  7:55 ` Gonglei
@ 2015-06-11 11:11 ` Markus Armbruster
  1 sibling, 0 replies; 4+ messages in thread
From: Markus Armbruster @ 2015-06-11 11:11 UTC (permalink / raw)
  To: Eric Auger
  Cc: peter.maydell, alex.williamson, arei.gonglei, eric.auger,
	qemu-devel

Eric Auger <eric.auger@linaro.org> writes:

> g_malloc0_n() is introduced since glib-2.24 while QEMU currently
> requires glib-2.22. This may cause a link error on some distributions.
>
> Signed-off-by: Eric Auger <eric.auger@linaro.org>
> ---
>  hw/vfio/platform.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/hw/vfio/platform.c b/hw/vfio/platform.c
> index 35266a8..c0acc8b 100644
> --- a/hw/vfio/platform.c
> +++ b/hw/vfio/platform.c
> @@ -346,8 +346,7 @@ static int vfio_populate_device(VFIODevice *vbasedev)
>          return ret;
>      }
>  
> -    vdev->regions = g_malloc0_n(vbasedev->num_regions,
> -                                sizeof(VFIORegion *));
> +    vdev->regions = g_malloc0(vbasedev->num_regions * sizeof(VFIORegion *));
>  
>      for (i = 0; i < vbasedev->num_regions; i++) {
>          struct vfio_region_info reg_info = { .argsz = sizeof(reg_info) };

Please use g_new0(VFIORegion, vbasedev->num_regions) for extra
compile-time checking and integer overflow protection.  See commits
58889fe net: Use g_new() & friends where that makes obvious sense
3c55fe2 scsi: Use g_new() & friends where that makes obvious sense
ab3ad07 x86: Use g_new() & friends where that makes obvious sense
3ba235a block: Use g_new0() for a bit of extra type checking
e1cf558 util: Use g_new() & friends where that makes obvious sense
02c4f26 block: Use g_new() & friends to avoid multiplying sizes
5839e53 block: Use g_new() & friends where that makes obvious sense

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-06-11 11:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-11  7:14 [Qemu-devel] [PATCH] hw/vfio/platform: replace g_malloc0_n by g_malloc0 Eric Auger
2015-06-11  7:55 ` Gonglei
2015-06-11  8:46   ` Eric Auger
2015-06-11 11:11 ` Markus Armbruster

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).