Statically allocate first node of zfsdev_state_list

This avoids a call to kmem_alloc() during module load. It also
suppresses a defect report from Clang's static analyzer that claims that
we will have a NULL pointer dereference in zfsdev_state_init() because
it does not understand that this has already been allocated in
zfs_kmod_init().

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Brian Atkinson <batkinson@lanl.gov>
Signed-off-by: Richard Yao <richard.yao@alumni.stonybrook.edu>
Closes #14470
This commit is contained in:
Richard Yao 2023-02-07 03:23:45 -05:00 committed by Brian Behlendorf
parent 7fc48f8378
commit 9a14ce43c3
1 changed files with 6 additions and 7 deletions

View File

@ -222,7 +222,7 @@
#include <sys/zfs_ioctl_impl.h>
kmutex_t zfsdev_state_lock;
static zfsdev_state_t *zfsdev_state_list;
static zfsdev_state_t zfsdev_state_listhead;
/*
* Limit maximum nvlist size. We don't want users passing in insane values
@ -7469,7 +7469,7 @@ zfsdev_getminor(zfs_file_t *fp, minor_t *minorp)
mutex_enter(&zfsdev_state_lock);
for (zs = zfsdev_state_list; zs != NULL; zs = zs->zs_next) {
for (zs = &zfsdev_state_listhead; zs != NULL; zs = zs->zs_next) {
if (zs->zs_minor == -1)
continue;
@ -7491,7 +7491,7 @@ zfsdev_get_state(minor_t minor, enum zfsdev_state_type which)
{
zfsdev_state_t *zs;
for (zs = zfsdev_state_list; zs != NULL; zs = zs->zs_next) {
for (zs = &zfsdev_state_listhead; zs != NULL; zs = zs->zs_next) {
if (zs->zs_minor == minor) {
membar_consumer();
switch (which) {
@ -7545,7 +7545,7 @@ zfsdev_state_init(void *priv)
if (minor == 0)
return (SET_ERROR(ENXIO));
for (zs = zfsdev_state_list; zs != NULL; zs = zs->zs_next) {
for (zs = &zfsdev_state_listhead; zs != NULL; zs = zs->zs_next) {
if (zs->zs_minor == -1)
break;
zsprev = zs;
@ -7829,8 +7829,7 @@ zfs_kmod_init(void)
zfs_ioctl_init();
mutex_init(&zfsdev_state_lock, NULL, MUTEX_DEFAULT, NULL);
zfsdev_state_list = kmem_zalloc(sizeof (zfsdev_state_t), KM_SLEEP);
zfsdev_state_list->zs_minor = -1;
zfsdev_state_listhead.zs_minor = -1;
if ((error = zfsdev_attach()) != 0)
goto out;
@ -7857,7 +7856,7 @@ zfs_kmod_fini(void)
mutex_destroy(&zfsdev_state_lock);
for (zs = zfsdev_state_list; zs != NULL; zs = zsnext) {
for (zs = &zfsdev_state_listhead; zs != NULL; zs = zsnext) {
zsnext = zs->zs_next;
if (zs->zs_onexit)
zfs_onexit_destroy(zs->zs_onexit);