[LU-16890] allow OBD_FREE() to ignore NULL pointers Created: 12/Jun/23  Updated: 16/Aug/23  Resolved: 09/Jul/23

Status: Resolved
Project: Lustre
Component/s: None
Affects Version/s: None
Fix Version/s: Lustre 2.16.0

Type: Improvement Priority: Minor
Reporter: Andreas Dilger Assignee: Arshad Hussain
Resolution: Fixed Votes: 0
Labels: easy

Issue Links:
Related
is related to LU-16688 Client crash due to an assertion in l... Resolved
Severity: 3
Rank (Obsolete): 9223372036854775807

 Description   

The OBD_FREE(ptr) macro will internally (via OBD_FREE_PRE()) assert that ptr != NULL, even though the kernel accepts kfree(NULL) without complaint.

It would make sense to remove the LASSERT(ptr) call from OBD_FREE_PRE() and change the callers to silently accept this case:

#define OBD_FREE(ptr, size)                                                  \
if (likely(ptr)) {                                                           \
        OBD_FREE_PRE(ptr, size, "kfreed");                                   \
        POISON(ptr, 0x5a, size);                                             \
        kfree(ptr);                                                          \
        POISON_PTR(ptr);                                                     \
}

#define OBD_SLAB_FREE(ptr, slab, size)                                       \
if (likely(ptr)) {                                                           \
        OBD_FREE_PRE(ptr, size, "slab-freed");                               \
        POISON(ptr, 0x5a, size);                                             \
        kmem_cache_free(slab, ptr);                                          \
        POISON_PTR(ptr);                                                     \
}

It isn't strictly needed for OBD_FREE_LARGE() since is_vmalloc_addr(ptr) will return false for a NULL pointer and fall back to OBD_FREE().



 Comments   
Comment by Gerrit Updater [ 15/Jun/23 ]

"Arshad Hussain <arshad.hussain@aeoncomputing.com>" uploaded a new patch: https://review.whamcloud.com/c/fs/lustre-release/+/51332
Subject: LU-16890 obd: OBD_FREE_PRE() to ignore NULL pointers
Project: fs/lustre-release
Branch: master
Current Patch Set: 1
Commit: 9f42be0e1c77aa1e3914a52854f51ac07ab37f4a

Comment by Gerrit Updater [ 08/Jul/23 ]

"Oleg Drokin <green@whamcloud.com>" merged in patch https://review.whamcloud.com/c/fs/lustre-release/+/51332/
Subject: LU-16890 obd: OBD_FREE_PRE() to ignore NULL pointers
Project: fs/lustre-release
Branch: master
Current Patch Set:
Commit: 46a9abf4330e7a12fde41fb922d6dfc4547c6243

Comment by Peter Jones [ 09/Jul/23 ]

Landed for 2.16

Generated at Sat Feb 10 03:30:51 UTC 2024 using Jira 9.4.14#940014-sha1:734e6822bbf0d45eff9af51f82432957f73aa32c.