Uploaded image for project: 'Lustre'
  1. Lustre
  2. LU-16890

allow OBD_FREE() to ignore NULL pointers

XMLWordPrintable

    • Icon: Improvement Improvement
    • Resolution: Fixed
    • Icon: Minor Minor
    • Lustre 2.16.0
    • None
    • 3
    • 9223372036854775807

      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().

            arshad512 Arshad Hussain
            adilger Andreas Dilger
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: