tools resolve_btfids: Add support for set symbols
[linux-2.6-microblaze.git] / tools / bpf / resolve_btfids / main.c
index 52d8833..6152d13 100644 (file)
@@ -199,9 +199,16 @@ static char *get_id(const char *prefix_end)
        /*
         * __BTF_ID__func__vfs_truncate__0
         * prefix_end =  ^
+        * pos        =    ^
         */
-       char *p, *id = strdup(prefix_end + sizeof("__") - 1);
+       int len = strlen(prefix_end);
+       int pos = sizeof("__") - 1;
+       char *p, *id;
 
+       if (pos >= len)
+               return NULL;
+
+       id = strdup(prefix_end + pos);
        if (id) {
                /*
                 * __BTF_ID__func__vfs_truncate__0
@@ -220,6 +227,24 @@ static char *get_id(const char *prefix_end)
        return id;
 }
 
+static struct btf_id *add_set(struct object *obj, char *name)
+{
+       /*
+        * __BTF_ID__set__name
+        * name =    ^
+        * id   =         ^
+        */
+       char *id = name + sizeof(BTF_SET "__") - 1;
+       int len = strlen(name);
+
+       if (id >= name + len) {
+               pr_err("FAILED to parse set name: %s\n", name);
+               return NULL;
+       }
+
+       return btf_id__add(&obj->sets, id, true);
+}
+
 static struct btf_id *add_symbol(struct rb_root *root, char *name, size_t size)
 {
        char *id;
@@ -376,7 +401,7 @@ static int symbols_collect(struct object *obj)
                        id = add_symbol(&obj->funcs, prefix, sizeof(BTF_FUNC) - 1);
                /* set */
                } else if (!strncmp(prefix, BTF_SET, sizeof(BTF_SET) - 1)) {
-                       id = add_symbol(&obj->sets, prefix, sizeof(BTF_SET) - 1);
+                       id = add_set(obj, prefix);
                        /*
                         * SET objects store list's count, which is encoded
                         * in symbol's size, together with 'cnt' field hence
@@ -566,6 +591,7 @@ static int sets_patch(struct object *obj)
 
                next = rb_next(next);
        }
+       return 0;
 }
 
 static int symbols_patch(struct object *obj)