Linux Documentation
 help / color / mirror / Atom feed
* [PATCH] cleanup: Suggest using IS_ERR_OR_NULL() in cleanup functions
@ 2026-11-19 13:14 Geert Uytterhoeven
  2026-11-19 13:16 ` Dan Carpenter
  0 siblings, 1 reply; 2+ messages in thread
From: Geert Uytterhoeven @ 2026-11-19 13:14 UTC (permalink / raw)
  To: Peter Zijlstra, Dan Carpenter, David Rientjes, Vlastimil Babka,
	Jonathan Corbet
  Cc: linux-kernel, linux-doc, Geert Uytterhoeven

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@glider.be>
---
 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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] cleanup: Suggest using IS_ERR_OR_NULL() in cleanup functions
  2026-11-19 13:14 [PATCH] cleanup: Suggest using IS_ERR_OR_NULL() in cleanup functions Geert Uytterhoeven
@ 2026-11-19 13:16 ` Dan Carpenter
  0 siblings, 0 replies; 2+ messages in thread
From: Dan Carpenter @ 2026-11-19 13:16 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Peter Zijlstra, David Rientjes, Vlastimil Babka, Jonathan Corbet,
	linux-kernel, linux-doc

On Thu, Nov 19, 2026 at 02:14:29PM +0100, Geert Uytterhoeven wrote:
> 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@glider.be>

Acked-by: Dan Carpenter <error27@gmail.com>

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-19 13:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19 13:14 [PATCH] cleanup: Suggest using IS_ERR_OR_NULL() in cleanup functions Geert Uytterhoeven
2026-11-19 13:16 ` Dan Carpenter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox