Re: [PATCH v3 2/7] cpu: add function to get the models for an arch

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

 



On 09/11/2013 08:12 AM, Giuseppe Scrivano wrote:
> Signed-off-by: Giuseppe Scrivano <gscrivan@xxxxxxxxxx>
> ---
>  src/cpu/cpu.c            | 56 ++++++++++++++++++++++++++++++++++++++++++++++++
>  src/cpu/cpu.h            |  3 +++
>  src/libvirt_private.syms |  1 +
>  3 files changed, 60 insertions(+)
> 

> +
> +int
> +cpuGetModels(const char *arch, char ***models)
> +{
> +    struct cpuGetModelsData data;
> +
> +    *models = data.data = NULL;

Blind dereference of models; but since I argued in patch 1 that passing
NULL makes sense for the return value count, this needs a tweak...

ACK with this squashed in.

diff --git i/src/cpu/cpu.c w/src/cpu/cpu.c
index 7011b3d..dc0c474 100644
--- i/src/cpu/cpu.c
+++ w/src/cpu/cpu.c
@@ -1,7 +1,7 @@
 /*
  * cpu.c: internal functions for CPU manipulation
  *
- * Copyright (C) 2009-2012 Red Hat, Inc.
+ * Copyright (C) 2009-2013 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -479,6 +479,11 @@ cpuGetArchModelsCb(enum cpuMapElement element,
     if (name == NULL)
         return -1;

+    if (!data->data) {
+        VIR_FREE(name);
+        data->len++;
+        return 0;
+    }
     return VIR_INSERT_ELEMENT(data->data, data->len - 1, data->len, name);
 }

@@ -495,16 +500,17 @@ cpuGetModels(const char *arch, char ***models)
 {
     struct cpuGetModelsData data;

-    *models = data.data = NULL;
+    data.data = NULL;
     data.len = 1;

-    if (VIR_ALLOC_N(data.data, data.len) < 0)
+    if (models && VIR_ALLOC_N(data.data, data.len) < 0)
         goto error;

     if (cpuGetArchModels(arch, &data) < 0)
         goto error;

-    *models = data.data;
+    if (models)
+        *models = data.data;

     return data.len - 1;



-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]