Skip to content

Commit 54632eb

Browse files
author
Sharmi
authored
Set errno for bpf_object__find_map_by_name (#3712)
* Initial Commit * Initialize errno * Set errno for bpf_object__find_map_by_name * Added Doxygen comment
1 parent 2448139 commit 54632eb

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

include/bpf/libbpf.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,8 @@ bpf_object__close(struct bpf_object* object);
247247
* @param[in] name The name to look for.
248248
*
249249
* @returns The map found, or NULL if none.
250+
*
251+
* @exception ENOENT The map was not found.
250252
*/
251253
struct bpf_map*
252254
bpf_object__find_map_by_name(const struct bpf_object* obj, const char* name);

libs/api/libbpf_map.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ bpf_object__find_map_by_name(const struct bpf_object* obj, const char* name)
241241
return pos;
242242
}
243243
}
244-
return NULL;
244+
return (struct bpf_map*)libbpf_err_ptr(-ENOENT);
245245
}
246246

247247
int

tests/unit/libbpf_test.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,9 +480,15 @@ TEST_CASE("libbpf program", "[libbpf]")
480480
struct bpf_program* program = bpf_object__find_program_by_name(object, "test_program_entry");
481481
REQUIRE(program != nullptr);
482482

483+
errno = 0;
483484
REQUIRE(bpf_object__find_program_by_name(object, "not_a_valid_name") == NULL);
484485
REQUIRE(errno == ENOENT);
485486

487+
// Testing invalid map name.
488+
errno = 0;
489+
REQUIRE(bpf_object__find_map_by_name(object, "not_a_valid_map") == NULL);
490+
REQUIRE(errno == ENOENT);
491+
486492
name = bpf_program__section_name(program);
487493
REQUIRE(strcmp(name, "sample_ext") == 0);
488494

0 commit comments

Comments
 (0)