From 8b3715c1bac8624269ef169a1073bb47102cacc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Geyslan=20Greg=C3=B3rio?= Date: Mon, 28 Aug 2023 17:11:13 -0300 Subject: [PATCH] chore: consider errno in NULL return --- module-iterator.go | 6 ++++-- module.go | 8 ++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/module-iterator.go b/module-iterator.go index c062e7e2..3bdf0aec 100644 --- a/module-iterator.go +++ b/module-iterator.go @@ -23,8 +23,9 @@ func (it *BPFObjectIterator) NextMap() *BPFMap { startMapC = it.prevMap.bpfMap } - bpfMapC := C.bpf_object__next_map(it.m.obj, startMapC) + bpfMapC, errno := C.bpf_object__next_map(it.m.obj, startMapC) if bpfMapC == nil { + _ = errno // intentionally ignored return nil } @@ -63,8 +64,9 @@ func (it *BPFObjectIterator) NextProgram() *BPFProg { startProg = it.prevProg.prog } - progC := C.bpf_object__next_program(it.m.obj, startProg) + progC, errno := C.bpf_object__next_program(it.m.obj, startProg) if progC == nil { + _ = errno // intentionally ignored return nil } diff --git a/module.go b/module.go index ea93d820..139503dc 100644 --- a/module.go +++ b/module.go @@ -330,9 +330,9 @@ func (m *Module) InitRingBuf(mapName string, eventsChan chan []byte) (*RingBuffe return nil, fmt.Errorf("max ring buffers reached") } - rbC := C.cgo_init_ring_buf(C.int(bpfMap.FileDescriptor()), C.uintptr_t(slot)) + rbC, errno := C.cgo_init_ring_buf(C.int(bpfMap.FileDescriptor()), C.uintptr_t(slot)) if rbC == nil { - return nil, fmt.Errorf("failed to initialize ring buffer") + return nil, fmt.Errorf("failed to initialize ring buffer: %w", errno) } ringBuf := &RingBuffer{ @@ -365,10 +365,10 @@ func (m *Module) InitPerfBuf(mapName string, eventsChan chan []byte, lostChan ch return nil, fmt.Errorf("max number of ring/perf buffers reached") } - pbC := C.cgo_init_perf_buf(C.int(bpfMap.FileDescriptor()), C.int(pageCnt), C.uintptr_t(slot)) + pbC, errno := C.cgo_init_perf_buf(C.int(bpfMap.FileDescriptor()), C.int(pageCnt), C.uintptr_t(slot)) if pbC == nil { eventChannels.remove(uint(slot)) - return nil, fmt.Errorf("failed to initialize perf buffer") + return nil, fmt.Errorf("failed to initialize perf buffer: %w", errno) } perfBuf.pb = pbC