Thread (9 messages) 9 messages, 4 authors, 2024-01-02

Re: packet: Improve exception handling in fanout_add()

From: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
Date: 2024-01-01 15:29:23
Also in: kernel-janitors, lkml

Markus Elfring wrote:
quoted
It is fine to call kfree with a possible NULL pointer:
quoted
	 * If @object is NULL, no operation is performed.
	 */
	void kfree(const void *object)
Such a function call triggers an input parameter validation
with a corresponding immediate return, doesn't it?
Do you find such data processing really helpful for the desired error/exception handling?
It's not just personal preference. It is an established pattern to
avoid extra NULL tests around kfree.

A quick git log to show a few recent examples of patches that expressly
remove such branches, e.g.,

commit d0110443cf4a ("amd/pds_core: core: No need for Null pointer check before kfree")
commit efd9d065de67 ("drm/radeon: Remove unnecessary NULL test before kfree in 'radeon_connector_free_edid'")

An interesting older thread on the topic:

https://linux-kernel.vger.kernel.narkive.com/KVjlDsTo/kfree-null

My summary, the many branches scattered throughout the kernel likely
are more expensive than the occasional save from seeing the rare NULL
pointer.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help