From: Mauricio Vásquez Date: Fri, 7 Jan 2022 15:26:19 +0000 (-0500) Subject: libbpf: Use IS_ERR_OR_NULL() in hashmap__free() X-Git-Tag: v5.18-rc1~136^2~544^2~28 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=fba60b171a032283;p=thirdparty%2Flinux.git libbpf: Use IS_ERR_OR_NULL() in hashmap__free() hashmap__new() uses ERR_PTR() to return an error so it's better to use IS_ERR_OR_NULL() in order to check the pointer before calling free(). This will prevent freeing an invalid pointer if somebody calls hashmap__free() with the result of a failed hashmap__new() call. Signed-off-by: Mauricio Vásquez Signed-off-by: Andrii Nakryiko Acked-by: Song Liu Link: https://lore.kernel.org/bpf/20220107152620.192327-1-mauricio@kinvolk.io --- diff --git a/tools/lib/bpf/hashmap.c b/tools/lib/bpf/hashmap.c index 3c20b126d60d8..aeb09c2887162 100644 --- a/tools/lib/bpf/hashmap.c +++ b/tools/lib/bpf/hashmap.c @@ -75,7 +75,7 @@ void hashmap__clear(struct hashmap *map) void hashmap__free(struct hashmap *map) { - if (!map) + if (IS_ERR_OR_NULL(map)) return; hashmap__clear(map); @@ -238,4 +238,3 @@ bool hashmap__delete(struct hashmap *map, const void *key, return true; } -