[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Mon, 01 Jan 2024 10:29:21 -0500
From: Willem de Bruijn <willemdebruijn.kernel@...il.com>
To: Markus Elfring <Markus.Elfring@....de>,
Willem de Bruijn <willemdebruijn.kernel@...il.com>,
netdev@...r.kernel.org,
kernel-janitors@...r.kernel.org,
"David S. Miller" <davem@...emloft.net>,
Eric Dumazet <edumazet@...gle.com>,
Jakub Kicinski <kuba@...nel.org>,
Paolo Abeni <pabeni@...hat.com>,
Stephen Hemminger <stephen@...workplumber.org>
Cc: LKML <linux-kernel@...r.kernel.org>
Subject: Re: packet: Improve exception handling in fanout_add()
Markus Elfring wrote:
> > It is fine to call kfree with a possible NULL pointer:
> …
> > * 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.
Powered by blists - more mailing lists