bpf: Replace bpf_lpm_trie_key 0-length array with flexible array
[linux-2.6-microblaze.git] / kernel / bpf / lpm_trie.c
index b32be68..050fe1e 100644 (file)
@@ -164,13 +164,13 @@ static inline int extract_bit(const u8 *data, size_t index)
  */
 static size_t longest_prefix_match(const struct lpm_trie *trie,
                                   const struct lpm_trie_node *node,
-                                  const struct bpf_lpm_trie_key *key)
+                                  const struct bpf_lpm_trie_key_u8 *key)
 {
        u32 limit = min(node->prefixlen, key->prefixlen);
        u32 prefixlen = 0, i = 0;
 
        BUILD_BUG_ON(offsetof(struct lpm_trie_node, data) % sizeof(u32));
-       BUILD_BUG_ON(offsetof(struct bpf_lpm_trie_key, data) % sizeof(u32));
+       BUILD_BUG_ON(offsetof(struct bpf_lpm_trie_key_u8, data) % sizeof(u32));
 
 #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && defined(CONFIG_64BIT)
 
@@ -229,7 +229,7 @@ static void *trie_lookup_elem(struct bpf_map *map, void *_key)
 {
        struct lpm_trie *trie = container_of(map, struct lpm_trie, map);
        struct lpm_trie_node *node, *found = NULL;
-       struct bpf_lpm_trie_key *key = _key;
+       struct bpf_lpm_trie_key_u8 *key = _key;
 
        if (key->prefixlen > trie->max_prefixlen)
                return NULL;
@@ -309,7 +309,7 @@ static long trie_update_elem(struct bpf_map *map,
        struct lpm_trie *trie = container_of(map, struct lpm_trie, map);
        struct lpm_trie_node *node, *im_node = NULL, *new_node = NULL;
        struct lpm_trie_node __rcu **slot;
-       struct bpf_lpm_trie_key *key = _key;
+       struct bpf_lpm_trie_key_u8 *key = _key;
        unsigned long irq_flags;
        unsigned int next_bit;
        size_t matchlen = 0;
@@ -437,7 +437,7 @@ out:
 static long trie_delete_elem(struct bpf_map *map, void *_key)
 {
        struct lpm_trie *trie = container_of(map, struct lpm_trie, map);
-       struct bpf_lpm_trie_key *key = _key;
+       struct bpf_lpm_trie_key_u8 *key = _key;
        struct lpm_trie_node __rcu **trim, **trim2;
        struct lpm_trie_node *node, *parent;
        unsigned long irq_flags;
@@ -536,7 +536,7 @@ out:
                                 sizeof(struct lpm_trie_node))
 #define LPM_VAL_SIZE_MIN       1
 
-#define LPM_KEY_SIZE(X)                (sizeof(struct bpf_lpm_trie_key) + (X))
+#define LPM_KEY_SIZE(X)                (sizeof(struct bpf_lpm_trie_key_u8) + (X))
 #define LPM_KEY_SIZE_MAX       LPM_KEY_SIZE(LPM_DATA_SIZE_MAX)
 #define LPM_KEY_SIZE_MIN       LPM_KEY_SIZE(LPM_DATA_SIZE_MIN)
 
@@ -565,7 +565,7 @@ static struct bpf_map *trie_alloc(union bpf_attr *attr)
        /* copy mandatory map attributes */
        bpf_map_init_from_attr(&trie->map, attr);
        trie->data_size = attr->key_size -
-                         offsetof(struct bpf_lpm_trie_key, data);
+                         offsetof(struct bpf_lpm_trie_key_u8, data);
        trie->max_prefixlen = trie->data_size * 8;
 
        spin_lock_init(&trie->lock);
@@ -616,7 +616,7 @@ static int trie_get_next_key(struct bpf_map *map, void *_key, void *_next_key)
 {
        struct lpm_trie_node *node, *next_node = NULL, *parent, *search_root;
        struct lpm_trie *trie = container_of(map, struct lpm_trie, map);
-       struct bpf_lpm_trie_key *key = _key, *next_key = _next_key;
+       struct bpf_lpm_trie_key_u8 *key = _key, *next_key = _next_key;
        struct lpm_trie_node **node_stack = NULL;
        int err = 0, stack_ptr = -1;
        unsigned int next_bit;
@@ -703,7 +703,7 @@ find_leftmost:
        }
 do_copy:
        next_key->prefixlen = next_node->prefixlen;
-       memcpy((void *)next_key + offsetof(struct bpf_lpm_trie_key, data),
+       memcpy((void *)next_key + offsetof(struct bpf_lpm_trie_key_u8, data),
               next_node->data, trie->data_size);
 free_stack:
        kfree(node_stack);
@@ -715,7 +715,7 @@ static int trie_check_btf(const struct bpf_map *map,
                          const struct btf_type *key_type,
                          const struct btf_type *value_type)
 {
-       /* Keys must have struct bpf_lpm_trie_key embedded. */
+       /* Keys must have struct bpf_lpm_trie_key_u8 embedded. */
        return BTF_INFO_KIND(key_type->info) != BTF_KIND_STRUCT ?
               -EINVAL : 0;
 }