Skip to contentSkip to conversation

libbpf: fix warning PTR_ERR_OR_ZERO can be used

PATCH Applied Hariprasad Kelam 3 participants 3 messages May 25, 2019 – May 28, 2019

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libbpf: fix warning PTR_ERR_OR_ZERO can be used

fix below warning reported by coccicheck

/tools/lib/bpf/libbpf.c:3461:1-3: WARNING: PTR_ERR_OR_ZERO can be used

---
 tools/lib/bpf/libbpf.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
tools/lib/bpf/libbpf.c +1 -3
index 197b574..33c25b6 100644
@@ -3458,9 +3458,7 @@ bpf_object__find_map_by_offset(struct bpf_object *obj, size_t offset)
 
 long libbpf_get_error(const void *ptr)
 {
-	if (IS_ERR(ptr))
-		return PTR_ERR(ptr);
-	return 0;
+	return PTR_ERR_OR_ZERO(ptr);
 }
 
 int bpf_prog_load(const char *file, enum bpf_prog_type type,
Signature · 1 line
2.7.4
Acked-by on v1 1/1
#1 lore raw
Quoted 5 lines · Hariprasad Kelam

fix below warning reported by coccicheck

/tools/lib/bpf/libbpf.c:3461:1-3: WARNING: PTR_ERR_OR_ZERO can be used

Quoted 20 lines
---
  tools/lib/bpf/libbpf.c | 4 +---
  1 file changed, 1 insertion(+), 3 deletions(-)
tools/lib/bpf/libbpf.c +1 -3
index 197b574..33c25b6 100644
@@ -3458,9 +3458,7 @@ bpf_object__find_map_by_offset(struct bpf_object *obj, size_t offset)
 
  long libbpf_get_error(const void *ptr)
  {
-	if (IS_ERR(ptr))
-		return PTR_ERR(ptr);
-	return 0;
+	return PTR_ERR_OR_ZERO(ptr);
  }
 
  int bpf_prog_load(const char *file, enum bpf_prog_type type,