Skip to content

Commit

Permalink
chore: consider errno in NULL return
Browse files Browse the repository at this point in the history
  • Loading branch information
geyslan committed Oct 26, 2023
1 parent 62f0ccc commit f1738f9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
6 changes: 4 additions & 2 deletions module-iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down
8 changes: 4 additions & 4 deletions module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f1738f9

Please sign in to comment.