diff mbox series

xen_disk: avoid use of g_malloc0_n()

Message ID 59B80A35020000780017A344@prv-mh.provo.novell.com
State New
Headers show
Series xen_disk: avoid use of g_malloc0_n() | expand

Commit Message

Jan Beulich Sept. 12, 2017, 2:24 p.m. UTC
Prefer g_new() / g_new0() to be farther backwards compatible with older
glib versions. As there's no point in zeroing the allocation here (the
loop right afterwards fully initializes the memory), use the former.

Signed-off-by: Jan Beulich <jbeulich@suse.com>

Comments

Paul Durrant Sept. 12, 2017, 2:33 p.m. UTC | #1
> -----Original Message-----
> From: Jan Beulich [mailto:JBeulich@suse.com]
> Sent: 12 September 2017 07:24
> To: qemu-devel@nongnu.org
> Cc: Paul Durrant <Paul.Durrant@citrix.com>; Stefano Stabellini
> <sstabellini@kernel.org>; xen-devel <xen-devel@lists.xenproject.org>
> Subject: [PATCH] xen_disk: avoid use of g_malloc0_n()
> 
> Prefer g_new() / g_new0() to be farther backwards compatible with older
> glib versions. As there's no point in zeroing the allocation here (the
> loop right afterwards fully initializes the memory), use the former.
> 
> Signed-off-by: Jan Beulich <jbeulich@suse.com>

Reviewed-by: Paul Durrant <paul.durrant@citrix.com>

> 
> --- a/hw/block/xen_disk.c
> +++ b/hw/block/xen_disk.c
> @@ -1232,7 +1232,7 @@ static int blk_connect(struct XenDevice
>          return -1;
>      }
> 
> -    domids = g_malloc0_n(blkdev->nr_ring_ref, sizeof(uint32_t));
> +    domids = g_new(uint32_t, blkdev->nr_ring_ref);
>      for (i = 0; i < blkdev->nr_ring_ref; i++) {
>          domids[i] = blkdev->xendev.dom;
>      }
> 
>
Anthony PERARD Sept. 14, 2017, 4:23 p.m. UTC | #2
On Tue, Sep 12, 2017 at 08:24:21AM -0600, Jan Beulich wrote:
> Prefer g_new() / g_new0() to be farther backwards compatible with older
> glib versions. As there's no point in zeroing the allocation here (the
> loop right afterwards fully initializes the memory), use the former.
> 
> Signed-off-by: Jan Beulich <jbeulich@suse.com>

Acked-by: Anthony PERARD <anthony.perard@citrix.com>

> --- a/hw/block/xen_disk.c
> +++ b/hw/block/xen_disk.c
> @@ -1232,7 +1232,7 @@ static int blk_connect(struct XenDevice
>          return -1;
>      }
>  
> -    domids = g_malloc0_n(blkdev->nr_ring_ref, sizeof(uint32_t));
> +    domids = g_new(uint32_t, blkdev->nr_ring_ref);
>      for (i = 0; i < blkdev->nr_ring_ref; i++) {
>          domids[i] = blkdev->xendev.dom;
>      }
> 
> 
> 
>
Philippe Mathieu-Daudé Sept. 14, 2017, 4:56 p.m. UTC | #3
Marc-André can you queue this patch in your gnew series?

On 09/12/2017 11:24 AM, Jan Beulich wrote:
> Prefer g_new() / g_new0() to be farther backwards compatible with older
> glib versions. As there's no point in zeroing the allocation here (the
> loop right afterwards fully initializes the memory), use the former.
> 
> Signed-off-by: Jan Beulich <jbeulich@suse.com>

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

> 
> --- a/hw/block/xen_disk.c
> +++ b/hw/block/xen_disk.c
> @@ -1232,7 +1232,7 @@ static int blk_connect(struct XenDevice
>           return -1;
>       }
>   
> -    domids = g_malloc0_n(blkdev->nr_ring_ref, sizeof(uint32_t));
> +    domids = g_new(uint32_t, blkdev->nr_ring_ref);
>       for (i = 0; i < blkdev->nr_ring_ref; i++) {
>           domids[i] = blkdev->xendev.dom;
>       }
diff mbox series

Patch

--- a/hw/block/xen_disk.c
+++ b/hw/block/xen_disk.c
@@ -1232,7 +1232,7 @@  static int blk_connect(struct XenDevice
         return -1;
     }
 
-    domids = g_malloc0_n(blkdev->nr_ring_ref, sizeof(uint32_t));
+    domids = g_new(uint32_t, blkdev->nr_ring_ref);
     for (i = 0; i < blkdev->nr_ring_ref; i++) {
         domids[i] = blkdev->xendev.dom;
     }