bpf: Fix warning of incorrect type in return expression
PATCH 2/2 bpf: Fix warning of incorrect type in return expression
Sparse reports a warning at bpf_array_map_seq_start()
"warning: incorrect type in return expression (different address spaces)"
The root cause is the function expect a return of type void * but instead got a percpu value in one of the return.
To fix this a variable of type void * is created
and the complainining return value is saved into the variable and return.
Fix incorrect type in return expression
--- kernel/bpf/arraymap.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
kernel/bpf/arraymap.c +5 -2
@@ -548,6 +548,7 @@ static void *bpf_array_map_seq_start(struct seq_file *seq, loff_t *pos)struct bpf_map *map = info->map;struct bpf_array *array;u32 index; +void *pptrs;if (info->index >= map->max_entries)return NULL ;
@@ -556,8 +557,10 @@ static void *bpf_array_map_seq_start(struct seq_file *seq, loff_t *pos) ++*pos; array = container_of(map, struct bpf_array, map); index = info->index & array->index_mask; -if (info->percpu_value_buf) -return array->pptrs[index]; +if (info->percpu_value_buf) { + pptrs = &array->pptrs[index]; +return pptrs; + }return array_map_elem_ptr (array, index); }
Signature · 1 line
2.35.1
Quoted 31 lines · Jules Irenge
Sparse reports a warning at
bpf_array_map_seq_start()"warning: incorrect type in return expression (different address spaces)"
The root cause is the function expect a return of type void * but instead got a percpu value in one of the return.
To fix this a variable of type void * is created
and the complainining return value is saved into the variable and return.Fix incorrect type in return expression
Signed-off-by Jules Irenge <[email protected]>--- kernel/bpf/arraymap.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)kernel/bpf/arraymap.c +1
-0@@ -548,6 +548,7 @@ static void *bpf_array_map_seq_start(struct seq_file *seq, loff_t *pos)struct bpf_map *map = info->map;struct bpf_array *array;u32 index; +void *pptrs;if (info->index >= map->max_entries)return NULL ;
kernel/bpf/arraymap.c static void *bpf_array_map_seq_start(struct seq_file *seq, loff_t *pos) · line 563
Quoted 9 lines
kernel/bpf/arraymap.c +4
-2@@ -556,8 +557,10 @@ static void *bpf_array_map_seq_start(struct seq_file *seq, loff_t *pos) ++*pos; array = container_of(map, struct bpf_array, map); index = info->index & array->index_mask; -if (info->percpu_value_buf) -return array->pptrs[index]; +if (info->percpu_value_buf) { + pptrs = &array->pptrs[index]; +return pptrs; + }
Somebody will surely send a patch to optimize above back to original code.
Please find a different way to shut up sparse or just ignore it.