aboutsummaryrefslogtreecommitdiffstats
path: root/amdgpu
diff options
context:
space:
mode:
authorMichel Dänzer2017-12-01 09:59:38 -0600
committerMichel Dänzer2017-12-05 05:49:13 -0600
commit5219809a3223e0328ae43a8975bfd6bf713c9ef1 (patch)
treea6ea422617aaaa58bff80def728f9ea83dba0c2c /amdgpu
parent85c6b0b00ab894116880d2338776727ccff2d5c3 (diff)
downloadexternal-libdrm-5219809a3223e0328ae43a8975bfd6bf713c9ef1.tar.gz
external-libdrm-5219809a3223e0328ae43a8975bfd6bf713c9ef1.tar.xz
external-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')
-rw-r--r--amdgpu/amdgpu_asic_id.c45
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)
45 char *s_rid; 45 char *s_rid;
46 char *s_name; 46 char *s_name;
47 char *endptr; 47 char *endptr;
48 int r = 0; 48 int r = -EINVAL;
49
50 /* ignore empty line and commented line */
51 if (strlen(line) == 0 || line[0] == '#')
52 return -EAGAIN;
49 53
50 buf = strdup(line); 54 buf = strdup(line);
51 if (!buf) 55 if (!buf)
52 return -ENOMEM; 56 return -ENOMEM;
53 57
54 /* ignore empty line and commented line */
55 if (strlen(line) == 0 || line[0] == '#') {
56 r = -EAGAIN;
57 goto out;
58 }
59
60 /* device id */ 58 /* device id */
61 s_did = strtok_r(buf, ",", &saveptr); 59 s_did = strtok_r(buf, ",", &saveptr);
62 if (!s_did) { 60 if (!s_did)
63 r = -EINVAL;
64 goto out; 61 goto out;
65 }
66 62
67 id->did = strtol(s_did, &endptr, 16); 63 id->did = strtol(s_did, &endptr, 16);
68 if (*endptr) { 64 if (*endptr)
69 r = -EINVAL;
70 goto out; 65 goto out;
71 }
72 66
73 /* revision id */ 67 /* revision id */
74 s_rid = strtok_r(NULL, ",", &saveptr); 68 s_rid = strtok_r(NULL, ",", &saveptr);
75 if (!s_rid) { 69 if (!s_rid)
76 r = -EINVAL;
77 goto out; 70 goto out;
78 }
79 71
80 id->rid = strtol(s_rid, &endptr, 16); 72 id->rid = strtol(s_rid, &endptr, 16);
81 if (*endptr) { 73 if (*endptr)
82 r = -EINVAL;
83 goto out; 74 goto out;
84 }
85 75
86 /* marketing name */ 76 /* marketing name */
87 s_name = strtok_r(NULL, ",", &saveptr); 77 s_name = strtok_r(NULL, ",", &saveptr);
88 if (!s_name) { 78 if (!s_name)
89 r = -EINVAL;
90 goto out; 79 goto out;
91 } 80
92 /* trim leading whitespaces or tabs */ 81 /* trim leading whitespaces or tabs */
93 while (isblank(*s_name)) 82 while (isblank(*s_name))
94 s_name++; 83 s_name++;
95 if (strlen(s_name) == 0) { 84 if (strlen(s_name) == 0)
96 r = -EINVAL;
97 goto out; 85 goto out;
98 }
99 86
100 id->marketing_name = strdup(s_name); 87 id->marketing_name = strdup(s_name);
101 if (id->marketing_name == NULL) { 88 if (id->marketing_name)
102 r = -EINVAL; 89 r = 0;
103 goto out; 90 else
104 } 91 r = -ENOMEM;
105 92
106out: 93out:
107 free(buf); 94 free(buf);