From a003ace53200d6a0e5188cec8c20e71a47c01532 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20=C5=BBenczykowski?= Date: Thu, 13 Feb 2025 16:08:18 -0800 Subject: [PATCH] NetBpfLoad: don't call bpfGetFdMapId in kernels < 4.14 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The function is not available in older kernels. But when we do call it, fail on error - should not happen. Test: TreeHugger Signed-off-by: Maciej Żenczykowski Change-Id: I2695bf01762abcbc087a3bd67f1718e0e326576a --- bpf/loader/NetBpfLoad.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/bpf/loader/NetBpfLoad.cpp b/bpf/loader/NetBpfLoad.cpp index 5554104046..c67be66e23 100644 --- a/bpf/loader/NetBpfLoad.cpp +++ b/bpf/loader/NetBpfLoad.cpp @@ -859,11 +859,13 @@ static int createMaps(const char* elfPath, ifstream& elfFile, vector& } } - int mapId = bpfGetFdMapId(fd); - if (mapId == -1) { - if (isAtLeastKernelVersion(4, 14, 0)) - ALOGE("bpfGetFdMapId failed, ret: %d [%d]", mapId, errno); - } else { + if (isAtLeastKernelVersion(4, 14, 0)) { + int mapId = bpfGetFdMapId(fd); + if (mapId == -1) { + const int err = errno; + ALOGE("bpfGetFdMapId failed, errno: %d", err); + return -err; + } ALOGI("map %s id %d", mapPinLoc.c_str(), mapId); }