[PATCH bpf] libbpf: reset errno after probing kernel features

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The kernel feature probing results in 'errno' being set if the probing
fails (as is often the case). This can stick around and leak to the caller,
which can lead to confusion later. So let's make sure we always reset errno
after calling a probe function.

Fixes: 47b6cb4d0add ("libbpf: Make kernel feature probing lazy")
Signed-off-by: Toke Høiland-Jørgensen <toke@xxxxxxxxxx>
---
 tools/lib/bpf/libbpf.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 28baee7ba1ca..8d05132e1945 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -4021,6 +4021,8 @@ static bool kernel_supports(enum kern_feature_id feat_id)
 			pr_warn("Detection of kernel %s support failed: %d\n", feat->desc, ret);
 			WRITE_ONCE(feat->res, FEAT_MISSING);
 		}
+		/* reset errno after probing to prevent leaking it to caller */
+		errno = 0;
 	}
 
 	return READ_ONCE(feat->res) == FEAT_SUPPORTED;
-- 
2.29.2




[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux