qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PULL 10/19] vfio/pci: Foundation for new quirk structu


From: Wen Congyang
Subject: Re: [Qemu-devel] [PULL 10/19] vfio/pci: Foundation for new quirk structure
Date: Thu, 24 Sep 2015 11:27:59 +0800
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0

On 09/24/2015 11:22 AM, Alex Williamson wrote:
> On Thu, 2015-09-24 at 10:54 +0800, Wen Congyang wrote:
>> On 09/24/2015 04:23 AM, Alex Williamson wrote:
>>> @@ -275,12 +276,15 @@ static void 
>>> vfio_vga_probe_ati_3c3_quirk(VFIOPCIDevice *vdev)
>>>      }
>>>  
>>>      quirk = g_malloc0(sizeof(*quirk));
>>> -    quirk->vdev = vdev;
>>> +    legacy = quirk->data = g_malloc0(sizeof(*legacy));
>>> +    quirk->mem = legacy->mem = g_malloc0_n(sizeof(MemoryRegion), 1);
>>
>> Why do you use g_malloc0_n() here? It is introduced in glib 2.24, but we 
>> only require glib 2.22.
> 
> Because I saw it, I guess in scripts/coverity-model.c, and used it.  In
> this particular instance it seems irrelevant, but VFIOQuirk.mem points
> to an array of MemoryRegions, other users here have more than one array
> entry and I chose to use the same allocator throughout for consistency.
> What's the preferred helper here, simply calloc()?  Thanks,

Yes, there is g_malloc0_n() in scripts/coverity-model.c. But it still breaks
building. calloc()? I guess we don't use it directly in qemu.

g_malloc0_n ()

gpointer
g_malloc0_n (gsize n_blocks,
             gsize n_block_bytes);

This function is similar to g_malloc0(), allocating (n_blocks * n_block_bytes ) 
bytes, but care is taken to detect possible overflow during multiplication.

So I think we can use g_malloc0(sizeof(MemoryRegion) * n).

Thanks
Wen Congyang

> 
> Alex
> 
> .
> 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]