BPF List
 help / color / mirror / Atom feed
From: Jules Irenge <jbi.octave@gmail.com>
To: martin.lau@linux.dev
Cc: Elana.Copperman@mobileye.com, ast@kernel.org,
	daniel@iogearbox.net, andrii@kernel.org, song@kernel.org,
	yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org,
	linux-kernel@vger.kernel.org, bpf@vger.kernel.org,
	sdf@google.com, haoluo@google.com
Subject: [PATCH 2/2] bpf: Fix warning of incorrect type in return expression
Date: Sat, 3 Sep 2022 20:02:15 +0100	[thread overview]
Message-ID: <YxOkt4An+u1azlvG@playground> (raw)

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 <jbi.octave@gmail.com>
---
 kernel/bpf/arraymap.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/kernel/bpf/arraymap.c b/kernel/bpf/arraymap.c
index 624527401d4d..b1914168c23a 100644
--- a/kernel/bpf/arraymap.c
+++ b/kernel/bpf/arraymap.c
@@ -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);
 }
 
-- 
2.35.1


             reply	other threads:[~2022-09-03 19:02 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-03 19:02 Jules Irenge [this message]
2022-09-06 18:29 ` [PATCH 2/2] bpf: Fix warning of incorrect type in return expression Alexei Starovoitov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YxOkt4An+u1azlvG@playground \
    --to=jbi.octave@gmail.com \
    --cc=Elana.Copperman@mobileye.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=kpsingh@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=sdf@google.com \
    --cc=song@kernel.org \
    --cc=yhs@fb.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox