diff --git a/sys/dev/dm/dm_pdev.c b/sys/dev/dm/dm_pdev.c index 1f63d5f7da13..972122ebf691 100644 --- a/sys/dev/dm/dm_pdev.c +++ b/sys/dev/dm/dm_pdev.c @@ -1,4 +1,4 @@ -/* $NetBSD: dm_pdev.c,v 1.16 2019/12/06 16:46:14 tkusumi Exp $ */ +/* $NetBSD: dm_pdev.c,v 1.17 2019/12/07 06:26:31 tkusumi Exp $ */ /* * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -29,7 +29,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ #include -__KERNEL_RCSID(0, "$NetBSD: dm_pdev.c,v 1.16 2019/12/06 16:46:14 tkusumi Exp $"); +__KERNEL_RCSID(0, "$NetBSD: dm_pdev.c,v 1.17 2019/12/07 06:26:31 tkusumi Exp $"); #include #include @@ -188,16 +188,16 @@ dm_pdev_rem(dm_pdev_t * dmp) int dm_pdev_destroy(void) { - dm_pdev_t *dm_pdev; + dm_pdev_t *dmp; mutex_enter(&dm_pdev_mutex); - while (!SLIST_EMPTY(&dm_pdev_list)) { /* List Deletion. */ - dm_pdev = SLIST_FIRST(&dm_pdev_list); - SLIST_REMOVE_HEAD(&dm_pdev_list, next_pdev); - - dm_pdev_rem(dm_pdev); + while ((dmp = SLIST_FIRST(&dm_pdev_list)) != NULL) { + SLIST_REMOVE(&dm_pdev_list, dmp, dm_pdev, next_pdev); + dm_pdev_rem(dmp); } + KASSERT(SLIST_EMPTY(&dm_pdev_list)); + mutex_exit(&dm_pdev_mutex); mutex_destroy(&dm_pdev_mutex); diff --git a/sys/dev/dm/dm_table.c b/sys/dev/dm/dm_table.c index 54021558725d..47bbece0f515 100644 --- a/sys/dev/dm/dm_table.c +++ b/sys/dev/dm/dm_table.c @@ -1,4 +1,4 @@ -/* $NetBSD: dm_table.c,v 1.10 2019/12/05 16:59:43 tkusumi Exp $ */ +/* $NetBSD: dm_table.c,v 1.11 2019/12/07 06:26:31 tkusumi Exp $ */ /* * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -29,7 +29,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ #include -__KERNEL_RCSID(0, "$NetBSD: dm_table.c,v 1.10 2019/12/05 16:59:43 tkusumi Exp $"); +__KERNEL_RCSID(0, "$NetBSD: dm_table.c,v 1.11 2019/12/07 06:26:31 tkusumi Exp $"); #include #include @@ -160,15 +160,14 @@ dm_table_destroy(dm_table_head_t * head, uint8_t table_id) tbl = &head->tables[id]; - while (!SLIST_EMPTY(tbl)) { /* List Deletion. */ - table_en = SLIST_FIRST(tbl); + while ((table_en = SLIST_FIRST(tbl)) != NULL) { + SLIST_REMOVE(tbl, table_en, dm_table_entry, next); if (table_en->target->destroy(table_en) == 0) table_en->target_config = NULL; - SLIST_REMOVE_HEAD(tbl, next); - kmem_free(table_en, sizeof(*table_en)); } + KASSERT(SLIST_EMPTY(tbl)); mutex_exit(&head->table_mtx); diff --git a/sys/dev/dm/dm_target.c b/sys/dev/dm/dm_target.c index 722b068b0e88..7b46adc2e9f1 100644 --- a/sys/dev/dm/dm_target.c +++ b/sys/dev/dm/dm_target.c @@ -1,4 +1,4 @@ -/* $NetBSD: dm_target.c,v 1.23 2019/12/06 16:11:59 tkusumi Exp $ */ +/* $NetBSD: dm_target.c,v 1.24 2019/12/07 06:26:31 tkusumi Exp $ */ /* * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -29,7 +29,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ #include -__KERNEL_RCSID(0, "$NetBSD: dm_target.c,v 1.23 2019/12/06 16:11:59 tkusumi Exp $"); +__KERNEL_RCSID(0, "$NetBSD: dm_target.c,v 1.24 2019/12/07 06:26:31 tkusumi Exp $"); #include #include @@ -220,14 +220,13 @@ dm_target_destroy(void) dm_target_t *dm_target; mutex_enter(&dm_target_mutex); - while (TAILQ_FIRST(&dm_target_list) != NULL) { - dm_target = TAILQ_FIRST(&dm_target_list); - - TAILQ_REMOVE(&dm_target_list, TAILQ_FIRST(&dm_target_list), - dm_target_next); + while ((dm_target = TAILQ_FIRST(&dm_target_list)) != NULL) { + TAILQ_REMOVE(&dm_target_list, dm_target, dm_target_next); (void)kmem_free(dm_target, sizeof(dm_target_t)); } + KASSERT(TAILQ_EMPTY(&dm_target_list)); + mutex_exit(&dm_target_mutex); mutex_destroy(&dm_target_mutex);