[libvirt] [PATCH v3 2/7] cpu: add function to get the models for an arch
Eric Blake
eblake at redhat.com
Fri Sep 13 19:29:41 UTC 2013
On 09/11/2013 08:12 AM, Giuseppe Scrivano wrote:
> Signed-off-by: Giuseppe Scrivano <gscrivan at redhat.com>
> ---
> 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 621 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20130913/6c88f409/attachment-0001.sig>
More information about the libvir-list
mailing list