Skip to contentSkip to conversation

trace: Fix passing zero to PTR_ERR()

PATCH Superseded Wang Qing 2 participants 2 messages Nov 7, 2020

Subsystems (6)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Wang Qing

author
#0 lore raw

PATCH v2 1/1 trace: Fix passing zero to PTR_ERR()

There is a bug when passing zero to PTR_ERR() and return. Fix smatch err.

---
 kernel/trace/bpf_trace.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/bpf_trace.c +1 -1
index 4517c8b..5113fd4
@@ -1198,7 +1198,7 @@ static int bpf_btf_printf_prepare(struct btf_ptr *ptr, u32 btf_ptr_size,
 	*btf = bpf_get_btf_vmlinux();
 
 	if (IS_ERR_OR_NULL(*btf))
-		return PTR_ERR(*btf);
+		return IS_ERR(*btf) ? PTR_ERR(*btf) : -EINVAL;
 
 	if (ptr->type_id > 0)
 		*btf_id = ptr->type_id;
Signature · 1 line
2.7.4
#1 lore raw
Quoted 4 lines · Wang Qing

There is a bug when passing zero to PTR_ERR() and return. Fix smatch err.

For clarity, the subject probably should be
bpf: Fix passing zero to PTR_ERR()
to indicate this is a bpf related fix. The tag should be something like
[PATCH bpf v2] or [PATCH v2 bpf]
depending on your preference, to indicate this is for bpf tree.

If another version is sent, the above "v2" should change to "v3".

Quoted 18 lines
---
  kernel/trace/bpf_trace.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/bpf_trace.c +1 -1
index 4517c8b..5113fd4
@@ -1198,7 +1198,7 @@ static int bpf_btf_printf_prepare(struct btf_ptr *ptr, u32 btf_ptr_size,
  	*btf = bpf_get_btf_vmlinux();
 
  	if (IS_ERR_OR_NULL(*btf))
-		return PTR_ERR(*btf);
+		return IS_ERR(*btf) ? PTR_ERR(*btf) : -EINVAL;
 
  	if (ptr->type_id > 0)
  		*btf_id = ptr->type_id;