Re: [PATCH] ext4: remove superfluous check that pointer is not NULL

From: Theodore Ts'o
Date: Mon May 08 2023 - 12:15:16 EST

On Mon, May 08, 2023 at 03:13:37PM +0000, Tudor Ambarus wrote:
> If @buffer is NULL, no operation is performed for kvfree(buffer),
> remove superfluous check.
> Signed-off-by: Tudor Ambarus <tudor.ambarus@xxxxxxxxxx>

I was looking at this just a few weeks ago, and I couldn't find any
actual *documentation* that it was safe to call vfree(NIILL) or
kvfree(NULL). The problem is there are a lot of architecture-specific
functions, and unlike with kfree() there is no top-level "if (ptr ==
NULL) return;" in the top-level vfree() and kvfree().

So I thought about removing the NULL check for kvfree(), and
ultimately chickened out, since I was afraid that there might be
crashes for some obscure architecture or kernel CONFIG setup.

I've added linux-mm@ for their comments, and for a plea that if it
is safe to pass NULL to vfree, kvfree, kvfree_rcu, etc. that it
actually be *documented* somewhere.

- Ted