提交 82aca171 编写于 作者: J Jiri Denemark

cpu_ppc64: Use array of models in CPU map

There's no reason for keeping the models in a linked list. Especially
when we know upfront the total number of models we are loading.

As a nice side effect, this fixes ppc64GetModels to always return a
NULL-terminated list of models.
Signed-off-by: NJiri Denemark <jdenemar@redhat.com>
上级 1bf79d90
...@@ -48,13 +48,13 @@ struct ppc64_model { ...@@ -48,13 +48,13 @@ struct ppc64_model {
char *name; char *name;
const struct ppc64_vendor *vendor; const struct ppc64_vendor *vendor;
virCPUppc64Data *data; virCPUppc64Data *data;
struct ppc64_model *next;
}; };
struct ppc64_map { struct ppc64_map {
size_t nvendors; size_t nvendors;
struct ppc64_vendor **vendors; struct ppc64_vendor **vendors;
struct ppc64_model *models; size_t nmodels;
struct ppc64_model **models;
}; };
/* Convert a legacy CPU definition by transforming /* Convert a legacy CPU definition by transforming
...@@ -230,14 +230,11 @@ static struct ppc64_model * ...@@ -230,14 +230,11 @@ static struct ppc64_model *
ppc64ModelFind(const struct ppc64_map *map, ppc64ModelFind(const struct ppc64_map *map,
const char *name) const char *name)
{ {
struct ppc64_model *model; size_t i;
model = map->models;
while (model) {
if (STREQ(model->name, name))
return model;
model = model->next; for (i = 0; i < map->nmodels; i++) {
if (STREQ(map->models[i]->name, name))
return map->models[i];
} }
return NULL; return NULL;
...@@ -247,16 +244,15 @@ static struct ppc64_model * ...@@ -247,16 +244,15 @@ static struct ppc64_model *
ppc64ModelFindPVR(const struct ppc64_map *map, ppc64ModelFindPVR(const struct ppc64_map *map,
uint32_t pvr) uint32_t pvr)
{ {
struct ppc64_model *model;
size_t i; size_t i;
size_t j;
model = map->models; for (i = 0; i < map->nmodels; i++) {
while (model) { struct ppc64_model *model = map->models[i];
for (i = 0; i < model->data->len; i++) { for (j = 0; j < model->data->len; j++) {
if ((pvr & model->data->pvr[i].mask) == model->data->pvr[i].value) if ((pvr & model->data->pvr[j].mask) == model->data->pvr[j].value)
return model; return model;
} }
model = model->next;
} }
return NULL; return NULL;
...@@ -285,11 +281,9 @@ ppc64MapFree(struct ppc64_map *map) ...@@ -285,11 +281,9 @@ ppc64MapFree(struct ppc64_map *map)
if (!map) if (!map)
return; return;
while (map->models) { for (i = 0; i < map->nmodels; i++)
struct ppc64_model *model = map->models; ppc64ModelFree(map->models[i]);
map->models = model->next; VIR_FREE(map->models);
ppc64ModelFree(model);
}
for (i = 0; i < map->nvendors; i++) for (i = 0; i < map->nvendors; i++)
ppc64VendorFree(map->vendors[i]); ppc64VendorFree(map->vendors[i]);
...@@ -417,12 +411,8 @@ ppc64ModelLoad(xmlXPathContextPtr ctxt, ...@@ -417,12 +411,8 @@ ppc64ModelLoad(xmlXPathContextPtr ctxt,
model->data->pvr[i].mask = pvr; model->data->pvr[i].mask = pvr;
} }
if (!map->models) { if (VIR_APPEND_ELEMENT(map->models, map->nmodels, model) < 0)
map->models = model; goto ignore;
} else {
model->next = map->models;
map->models = model;
}
cleanup: cleanup:
ctxt->node = bookmark; ctxt->node = bookmark;
...@@ -863,44 +853,33 @@ static int ...@@ -863,44 +853,33 @@ static int
ppc64DriverGetModels(char ***models) ppc64DriverGetModels(char ***models)
{ {
struct ppc64_map *map; struct ppc64_map *map;
struct ppc64_model *model; size_t i;
char *name; int ret = -1;
size_t nmodels = 0;
if (!(map = ppc64LoadMap())) if (!(map = ppc64LoadMap()))
goto error; goto error;
if (models && VIR_ALLOC_N(*models, 0) < 0)
goto error;
model = map->models;
while (model) {
if (models) { if (models) {
if (VIR_STRDUP(name, model->name) < 0) if (VIR_ALLOC_N(*models, map->nmodels + 1) < 0)
goto error; goto error;
if (VIR_APPEND_ELEMENT(*models, nmodels, name) < 0) { for (i = 0; i < map->nmodels; i++) {
VIR_FREE(name); if (VIR_STRDUP((*models)[i], map->models[i]->name) < 0)
goto error; goto error;
} }
} else {
nmodels++;
} }
model = model->next; ret = map->nmodels;
}
cleanup: cleanup:
ppc64MapFree(map); ppc64MapFree(map);
return ret;
return nmodels;
error: error:
if (models) { if (models) {
virStringFreeList(*models); virStringFreeList(*models);
*models = NULL; *models = NULL;
} }
nmodels = -1;
goto cleanup; goto cleanup;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册