From eb1ed2a66b7fddb30d62fb90bea1f8afa722098a Mon Sep 17 00:00:00 2001 From: Richard Yao Date: Wed, 19 Oct 2022 16:28:52 -0400 Subject: [PATCH] Coverity Model Update When reviewing Clang Static Analyzer reports against a branch that had experimental header changes based on the Coverity model file to inform it that KM_SLEEP allocations cannot return NULL, I found a report saying that a KM_PUSHPAGE allocation returned NULL. The actual implementation does not return NULL unless KM_NOSLEEP has been passed, so we backport the correction from the experimental header changes to the Coverity model. Reviewed-by: Brian Behlendorf Reviewed-by: Ryan Moeller Signed-off-by: Richard Yao Closes #14210 --- contrib/coverity/model.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/contrib/coverity/model.c b/contrib/coverity/model.c index 8e3e83cada..8b4d14ee22 100644 --- a/contrib/coverity/model.c +++ b/contrib/coverity/model.c @@ -24,6 +24,8 @@ #include +#define KM_NOSLEEP 0x0001 /* cannot block for memory; may fail */ + #define UMEM_DEFAULT 0x0000 /* normal -- may fail */ #define UMEM_NOFAIL 0x0100 /* Never fails */ @@ -173,7 +175,7 @@ spl_kmem_alloc(size_t sz, int fl, const char *func, int line) if (condition1) __coverity_sleep__(); - if ((fl == 0) || condition0) { + if (((fl & KM_NOSLEEP) != KM_NOSLEEP) || condition0) { void *buf = __coverity_alloc__(sz); __coverity_mark_as_uninitialized_buffer__(buf); __coverity_mark_as_afm_allocated__(buf, "spl_kmem_free"); @@ -194,7 +196,7 @@ spl_kmem_zalloc(size_t sz, int fl, const char *func, int line) if (condition1) __coverity_sleep__(); - if ((fl == 0) || condition0) { + if (((fl & KM_NOSLEEP) != KM_NOSLEEP) || condition0) { void *buf = __coverity_alloc__(sz); __coverity_writeall0__(buf); __coverity_mark_as_afm_allocated__(buf, "spl_kmem_free"); @@ -276,7 +278,7 @@ spl_vmem_alloc(size_t sz, int fl, const char *func, int line) if (condition1) __coverity_sleep__(); - if ((fl == 0) || condition0) { + if (((fl & KM_NOSLEEP) != KM_NOSLEEP) || condition0) { void *buf = __coverity_alloc__(sz); __coverity_mark_as_uninitialized_buffer__(buf); __coverity_mark_as_afm_allocated__(buf, "spl_vmem_free"); @@ -295,7 +297,7 @@ spl_vmem_zalloc(size_t sz, int fl, const char *func, int line) if (condition1) __coverity_sleep__(); - if ((fl == 0) || condition0) { + if (((fl & KM_NOSLEEP) != KM_NOSLEEP) || condition0) { void *buf = __coverity_alloc__(sz); __coverity_writeall0__(buf); __coverity_mark_as_afm_allocated__(buf, "spl_vmem_free");