[PATCH] cleanup: Suggest using IS_ERR_OR_NULL() in cleanup functions

From: Geert Uytterhoeven

Date: Thu Nov 19 2026 - 08:14:53 EST


Commit cd7eb8f83fcf258f ("mm/slab: make __free(kfree) accept error
pointers") already hardened the cleanup functions for kfree() and
kvfree().

Update the recommendation and example in the documentation, too.

Signed-off-by: Geert Uytterhoeven <geert+renesas@xxxxxxxxx>
---
include/linux/cleanup.h | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/include/linux/cleanup.h b/include/linux/cleanup.h
index 1fb8058b897d4a84..9795fa1dbd35e87f 100644
--- a/include/linux/cleanup.h
+++ b/include/linux/cleanup.h
@@ -157,8 +157,8 @@
* DEFINE_FREE(name, type, free):
* simple helper macro that defines the required wrapper for a __free()
* based cleanup function. @free is an expression using '_T' to access the
- * variable. @free should typically include a NULL test before calling a
- * function, see the example below.
+ * variable. @free should typically include a NULL or IS_ERR_OR_NULL()
+ * test before calling a function, see the example below.
*
* __free(name):
* variable attribute to add a scoped based cleanup to the variable.
@@ -175,7 +175,7 @@
*
* Ex.
*
- * DEFINE_FREE(kfree, void *, if (_T) kfree(_T))
+ * DEFINE_FREE(kfree, void *, if (!IS_ERR_OR_NULL(_T)) kfree(_T))
*
* void *alloc_obj(...)
* {
--
2.43.0