diff options
author | Michel Dänzer <michel.daenzer@amd.com> | 2017-12-01 16:59:38 +0100 |
---|---|---|
committer | Michel Dänzer <michel@daenzer.net> | 2017-12-05 12:49:13 +0100 |
commit | 5219809a3223e0328ae43a8975bfd6bf713c9ef1 (patch) | |
tree | a6ea422617aaaa58bff80def728f9ea83dba0c2c /amdgpu/amdgpu_asic_id.c | |
parent | 85c6b0b00ab894116880d2338776727ccff2d5c3 (diff) | |
download | libdrm-5219809a3223e0328ae43a8975bfd6bf713c9ef1.tar.gz libdrm-5219809a3223e0328ae43a8975bfd6bf713c9ef1.tar.bz2 libdrm-5219809a3223e0328ae43a8975bfd6bf713c9ef1.zip |
amdgpu: Simplify error handling in parse_one_line
* Move empty/commented line check before the strdup and return -EAGAIN
directly
* Initialize r = -EAGAIN and remove redundant assignments
* Set r = -ENOMEM if last strdup fails, and remove redundant goto
Acked-by: Slava Abramov <slava.abramov@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Diffstat (limited to 'amdgpu/amdgpu_asic_id.c')
-rw-r--r-- | amdgpu/amdgpu_asic_id.c | 45 |
1 files changed, 16 insertions, 29 deletions
diff --git a/amdgpu/amdgpu_asic_id.c b/amdgpu/amdgpu_asic_id.c index eb42bbc2..0b5f2962 100644 --- a/amdgpu/amdgpu_asic_id.c +++ b/amdgpu/amdgpu_asic_id.c @@ -45,63 +45,50 @@ static int parse_one_line(const char *line, struct amdgpu_asic_id *id) char *s_rid; char *s_name; char *endptr; - int r = 0; + int r = -EINVAL; + + /* ignore empty line and commented line */ + if (strlen(line) == 0 || line[0] == '#') + return -EAGAIN; buf = strdup(line); if (!buf) return -ENOMEM; - /* ignore empty line and commented line */ - if (strlen(line) == 0 || line[0] == '#') { - r = -EAGAIN; - goto out; - } - /* device id */ s_did = strtok_r(buf, ",", &saveptr); - if (!s_did) { - r = -EINVAL; + if (!s_did) goto out; - } id->did = strtol(s_did, &endptr, 16); - if (*endptr) { - r = -EINVAL; + if (*endptr) goto out; - } /* revision id */ s_rid = strtok_r(NULL, ",", &saveptr); - if (!s_rid) { - r = -EINVAL; + if (!s_rid) goto out; - } id->rid = strtol(s_rid, &endptr, 16); - if (*endptr) { - r = -EINVAL; + if (*endptr) goto out; - } /* marketing name */ s_name = strtok_r(NULL, ",", &saveptr); - if (!s_name) { - r = -EINVAL; + if (!s_name) goto out; - } + /* trim leading whitespaces or tabs */ while (isblank(*s_name)) s_name++; - if (strlen(s_name) == 0) { - r = -EINVAL; + if (strlen(s_name) == 0) goto out; - } id->marketing_name = strdup(s_name); - if (id->marketing_name == NULL) { - r = -EINVAL; - goto out; - } + if (id->marketing_name) + r = 0; + else + r = -ENOMEM; out: free(buf); |