lscpu: (arm) cleanup code

* check for strtol() errors
* fix indention
* fix coding style

Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Karel Zak 2018-01-22 13:20:51 +01:00
parent 8229df2093
commit af808dfa6d
1 changed files with 37 additions and 19 deletions

View File

@ -189,15 +189,22 @@ void arm_cpu_decode(struct lscpu_desc *desc)
{
int j, impl, part;
const struct id_part *parts = NULL;
char buf[8];
char *end;
if (desc->vendor == NULL || desc->model == NULL)
return;
if ((strncmp(desc->vendor,"0x",2) ||
strncmp(desc->model,"0x",2) ))
if ((strncmp(desc->vendor,"0x",2) || strncmp(desc->model,"0x",2) ))
return;
impl=(int)strtol(desc->vendor, NULL, 0);
part=(int)strtol(desc->model, NULL, 0);
errno = 0;
impl = (int) strtol(desc->vendor, &end, 0);
if (errno || desc->vendor == end)
return;
errno = 0;
part = (int) strtol(desc->model, &end, 0);
if (errno || desc->model == end)
return;
for (j = 0; hw_implementer[j].id != -1; j++) {
if (hw_implementer[j].id == impl) {
@ -206,6 +213,7 @@ void arm_cpu_decode(struct lscpu_desc *desc)
break;
}
}
if (parts == NULL)
return;
@ -217,10 +225,20 @@ void arm_cpu_decode(struct lscpu_desc *desc)
}
/* Print out the rXpY string for ARM cores */
if (impl == 0x41 && desc->revision != NULL &&
desc->stepping != NULL) {
int revision = atoi(desc->revision);
int variant = (int)strtol(desc->stepping, NULL, 0);
if (impl == 0x41 && desc->revision && desc->stepping) {
int revision, variant;
char buf[8];
errno = 0;
revision = (int) strtol(desc->revision, &end, 10);
if (errno || desc->revision == end)
return;
errno = 0;
variant = (int) strtol(desc->stepping, &end, 0);
if (errno || desc->stepping == end)
return;
snprintf(buf, sizeof(buf), "r%dp%d", variant, revision);
desc->stepping = xstrdup(buf);
}