Patchwork [01/16] Allow zero alloc_hint in qemu_sglist_init()

login
register
mail settings
Submitter Hannes Reinecke
Date Nov. 18, 2010, 2:44 p.m.
Message ID <20101118144434.3B68DF90AB@ochil.suse.de>
Download mbox | patch
Permalink /patch/72099/
State New
Headers show

Comments

Hannes Reinecke - Nov. 18, 2010, 2:44 p.m.
qemu_malloc doesn't check for zero argument, so we need to
check ourselves.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 dma-helpers.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
Christoph Hellwig - Nov. 19, 2010, 6:28 p.m.
On Thu, Nov 18, 2010 at 03:44:34PM +0100, Hannes Reinecke wrote:
> 
> qemu_malloc doesn't check for zero argument, so we need to
> check ourselves.

I'm not sure if it's a that good idea to remove the implicit
->sg != NULL assumption.  Any reason you can't simply call
qemu_sglist_init later?
Hannes Reinecke - Nov. 22, 2010, 9:01 a.m.
On 11/19/2010 07:28 PM, Christoph Hellwig wrote:
> On Thu, Nov 18, 2010 at 03:44:34PM +0100, Hannes Reinecke wrote:
>>
>> qemu_malloc doesn't check for zero argument, so we need to
>> check ourselves.
> 
> I'm not sure if it's a that good idea to remove the implicit
> ->sg != NULL assumption.  Any reason you can't simply call
> qemu_sglist_init later?
> 
We can actually drop this. It's a leftover from the old interface.

Cheers,

Hannes

Patch

diff --git a/dma-helpers.c b/dma-helpers.c
index 712ed89..877b2c3 100644
--- a/dma-helpers.c
+++ b/dma-helpers.c
@@ -12,7 +12,10 @@ 
 
 void qemu_sglist_init(QEMUSGList *qsg, int alloc_hint)
 {
-    qsg->sg = qemu_malloc(alloc_hint * sizeof(ScatterGatherEntry));
+    if (alloc_hint > 0)
+       qsg->sg = qemu_malloc(alloc_hint * sizeof(ScatterGatherEntry));
+    else
+       qsg->sg = NULL;
     qsg->nsg = 0;
     qsg->nalloc = alloc_hint;
     qsg->size = 0;