From c8a9dc2f6e47087dd5185276e21c9b071297f4f8 Mon Sep 17 00:00:00 2001 From: Patrick Rohr Date: Fri, 22 Nov 2024 11:00:50 -0800 Subject: [PATCH] Use unique_fd for usableProgram Makes 2 lines out of 4. Test: TH Change-Id: I5e2d047105065a189e6393a8f5fcb75ff42922ec --- bpf/syscall_wrappers/include/BpfSyscallWrappers.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/bpf/syscall_wrappers/include/BpfSyscallWrappers.h b/bpf/syscall_wrappers/include/BpfSyscallWrappers.h index 3c4bc6e4c9..a31445ad9f 100644 --- a/bpf/syscall_wrappers/include/BpfSyscallWrappers.h +++ b/bpf/syscall_wrappers/include/BpfSyscallWrappers.h @@ -28,6 +28,7 @@ namespace android { namespace bpf { using ::android::base::borrowed_fd; +using ::android::base::unique_fd; inline uint64_t ptr_to_u64(const void * const x) { return (uint64_t)(uintptr_t)x; @@ -182,10 +183,8 @@ inline int retrieveProgram(const char* pathname) { } inline bool usableProgram(const char* pathname) { - int fd = retrieveProgram(pathname); - bool ok = (fd >= 0); - if (ok) close(fd); - return ok; + unique_fd fd(retrieveProgram(pathname)); + return fd.ok(); } inline int attachProgram(bpf_attach_type type, const borrowed_fd& prog_fd,