Project

General

Profile

Actions

Bug #5253

open

kmem_alloc/kmem_zalloc won't fail with KM_SLEEP

Added by Josef Sipek almost 7 years ago. Updated 2 months ago.

Status:
New
Priority:
Normal
Assignee:
Category:
kernel
Start date:
2014-10-23
Due date:
% Done:

60%

Estimated time:
Difficulty:
Bite-size
Tags:
needs-triage
Gerrit CR:

Description

Passing KM_SLEEP to kmem_alloc or kmem_zalloc guarantees that the return value is not NULL. Therefore any NULL pointer checking on these calls is simply unnecessary and it obfuscates the code.


Related issues

Related to illumos gate - Bug #5254: getrbuf won't fail with KM_SLEEPNewJosef Sipek2014-10-23

Actions
Related to illumos gate - Feature #10704: allocb() should decide about priorityNew2019-04-09

Actions
Actions #1

Updated by Dan McDonald 2 months ago

  • Related to Feature #10704: allocb() should decide about priority added
Actions #2

Updated by Dan McDonald 2 months ago

Two ways to fix an instance of the check-for-NULL kmem_alloc(..., KM_SLEEP); antipattern:

1.) Lose the NULL check altogether.

OR

2.) Replace KM_SLEEP with KM_NOSLEEP | KM_NORMALPRI (to prevent extraordinary reclamation efforts, assuming the caller actually copes with NULL well).

Each instance should be evaluated for which of the above is better.

Actions

Also available in: Atom PDF