Re: [PATCH 0/2] net/smc: Adjustments for two function implementations

Wen Gu
2024-01-02T08:13:13Z

On 2023/12/31 22:55, Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Sun, 31 Dec 2023 15:48:45 +0100
>
> A few update suggestions were taken into account
> from static source code analysis.
>
> Markus Elfring (2):
> Return directly after a failed kzalloc() in smc_fill_gid_list()
> Improve exception handling in smc_llc_cli_add_link_invite()
>
> net/smc/af_smc.c | 2 +-
> net/smc/smc_llc.c | 15 +++++++--------
> 2 files changed, 8 insertions(+), 9 deletions(-)
>
> --
> 2.43.0

Hi Markus. I see you want to fix the kfree(NULL) issues in these two patches.

But I am wondering if this is necessary, since kfree() can handle NULL correctly.

/**
* kfree - free previously allocated memory
* @object: pointer returned by kmalloc() or kmem_cache_alloc()
*
* If @object is NULL, no operation is performed.
*/
void kfree(const void *object)
{
struct folio *folio;
struct slab *slab;
struct kmem_cache *s;

trace_kfree(_RET_IP_, object);

if (unlikely(ZERO_OR_NULL_PTR(object)))
return;

folio = virt_to_folio(object);
if (unlikely(!folio_test_slab(folio))) {
free_large_kmalloc(folio, (void *)object);
return;
}

slab = folio_slab(folio);
s = slab->slab_cache;
__kmem_cache_free(s, (void *)object, _RET_IP_);
}
EXPORT_SYMBOL(kfree);

Thanks,
Wen Gu