Skip to content

Commit

Permalink
Coverity Model Update
Browse files Browse the repository at this point in the history
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 <behlendorf1@llnl.gov>
Reviewed-by: Ryan Moeller <ryan@iXsystems.com>
Signed-off-by: Richard Yao <richard.yao@alumni.stonybrook.edu>
Closes openzfs#14210
  • Loading branch information
ryao authored and andrewc12 committed Dec 16, 2022
1 parent cd32b58 commit 5bc163a
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions contrib/coverity/model.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

#include <stdarg.h>

#define KM_NOSLEEP 0x0001 /* cannot block for memory; may fail */

#define UMEM_DEFAULT 0x0000 /* normal -- may fail */
#define UMEM_NOFAIL 0x0100 /* Never fails */

Expand Down Expand Up @@ -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");
Expand All @@ -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");
Expand Down Expand Up @@ -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");
Expand All @@ -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");
Expand Down

0 comments on commit 5bc163a

Please sign in to comment.