[PATCH 33/61] mm: Prefer IS_ERR_OR_NULL over manual NULL check

Philipp Hahn
2026-03-10T11:56:48Z

Prefer using IS_ERR_OR_NULL() over using IS_ERR() and a manual NULL
check.

Change generated with coccinelle and adapted by hand.

To: Catalin Marinas <catalin.marinas@arm.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-mm@kvack.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Philipp Hahn <phahn-oss@avm.de>
---
mm/kmemleak.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/mm/kmemleak.c b/mm/kmemleak.c
index d79acf5c51006c3ed42fd88a2246ca148e401999..91136be23a84d825698e98b4f2d0e666429dd593 100644
--- a/mm/kmemleak.c
+++ b/mm/kmemleak.c
@@ -1092,7 +1092,7 @@ void __ref kmemleak_alloc(const void *ptr, size_t size, int min_count,
{
pr_debug("%s(0x%px, %zu, %d)\n", __func__, ptr, size, min_count);

- if (kmemleak_enabled && ptr && !IS_ERR(ptr))
+ if (kmemleak_enabled && !IS_ERR_OR_NULL(ptr))
create_object((unsigned long)ptr, size, min_count, gfp);
}
EXPORT_SYMBOL_GPL(kmemleak_alloc);
@@ -1152,7 +1152,7 @@ void __ref kmemleak_free(const void *ptr)
{
pr_debug("%s(0x%px)\n", __func__, ptr);

- if (kmemleak_free_enabled && ptr && !IS_ERR(ptr))
+ if (kmemleak_free_enabled && !IS_ERR_OR_NULL(ptr))
delete_object_full((unsigned long)ptr, 0);
}
EXPORT_SYMBOL_GPL(kmemleak_free);
@@ -1170,7 +1170,7 @@ void __ref kmemleak_free_part(const void *ptr, size_t size)
{
pr_debug("%s(0x%px)\n", __func__, ptr);

- if (kmemleak_enabled && ptr && !IS_ERR(ptr))
+ if (kmemleak_enabled && !IS_ERR_OR_NULL(ptr))
delete_object_part((unsigned long)ptr, size, 0);
}
EXPORT_SYMBOL_GPL(kmemleak_free_part);
@@ -1238,7 +1238,7 @@ void __ref kmemleak_not_leak(const void *ptr)
{
pr_debug("%s(0x%px)\n", __func__, ptr);

- if (kmemleak_enabled && ptr && !IS_ERR(ptr))
+ if (kmemleak_enabled && !IS_ERR_OR_NULL(ptr))
make_gray_object((unsigned long)ptr);
}
EXPORT_SYMBOL(kmemleak_not_leak);
@@ -1255,7 +1255,7 @@ void __ref kmemleak_transient_leak(const void *ptr)
{
pr_debug("%s(0x%px)\n", __func__, ptr);

- if (kmemleak_enabled && ptr && !IS_ERR(ptr))
+ if (kmemleak_enabled && !IS_ERR_OR_NULL(ptr))
reset_checksum((unsigned long)ptr);
}
EXPORT_SYMBOL(kmemleak_transient_leak);
@@ -1287,7 +1287,7 @@ void __ref kmemleak_ignore(const void *ptr)
{
pr_debug("%s(0x%px)\n", __func__, ptr);

- if (kmemleak_enabled && ptr && !IS_ERR(ptr))
+ if (kmemleak_enabled && !IS_ERR_OR_NULL(ptr))
make_black_object((unsigned long)ptr, 0);
}
EXPORT_SYMBOL(kmemleak_ignore);
@@ -1307,7 +1307,7 @@ void __ref kmemleak_scan_area(const void *ptr, size_t size, gfp_t gfp)
{
pr_debug("%s(0x%px)\n", __func__, ptr);

- if (kmemleak_enabled && ptr && size && !IS_ERR(ptr))
+ if (kmemleak_enabled && size && !IS_ERR_OR_NULL(ptr))
add_scan_area((unsigned long)ptr, size, gfp);
}
EXPORT_SYMBOL(kmemleak_scan_area);
@@ -1325,7 +1325,7 @@ void __ref kmemleak_no_scan(const void *ptr)
{
pr_debug("%s(0x%px)\n", __func__, ptr);

- if (kmemleak_enabled && ptr && !IS_ERR(ptr))
+ if (kmemleak_enabled && !IS_ERR_OR_NULL(ptr))
object_no_scan((unsigned long)ptr);
}
EXPORT_SYMBOL(kmemleak_no_scan);

--
2.43.0