From: Michel Dänzer <michel.daen...@amd.com>

* 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

Signed-off-by: Michel Dänzer <michel.daen...@amd.com>
---
 amdgpu/amdgpu_asic_id.c | 45 ++++++++++++++++-----------------------------
 1 file 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);
-- 
2.15.0

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

Reply via email to