diff options
author | Mike Yuan <me@yhndnzj.com> | 2024-05-24 16:52:28 +0200 |
---|---|---|
committer | Mike Yuan <me@yhndnzj.com> | 2024-07-17 17:25:22 +0200 |
commit | 21fed6eaec011969c8550c6009c000e6e2e86852 (patch) | |
tree | c3395ff3dbab8669ccdec8542ac1a405d8954b2e | |
parent | core/unit: drop pointless unit_freezer_state wrapper (diff) | |
download | systemd-21fed6eaec011969c8550c6009c000e6e2e86852.tar.xz systemd-21fed6eaec011969c8550c6009c000e6e2e86852.zip |
core,unit-def: use our usual way of asserting enums
-rw-r--r-- | src/basic/unit-def.c | 4 | ||||
-rw-r--r-- | src/core/cgroup.c | 4 | ||||
-rw-r--r-- | src/core/cgroup.h | 2 | ||||
-rw-r--r-- | src/core/slice.c | 4 | ||||
-rw-r--r-- | src/core/unit.c | 4 |
5 files changed, 10 insertions, 8 deletions
diff --git a/src/basic/unit-def.c b/src/basic/unit-def.c index 6ffdcd37c8..4dc8ceef86 100644 --- a/src/basic/unit-def.c +++ b/src/basic/unit-def.c @@ -140,7 +140,9 @@ static const FreezerState freezer_state_finish_table[_FREEZER_STATE_MAX] = { }; FreezerState freezer_state_finish(FreezerState state) { - assert(state >= 0 && state < _FREEZER_STATE_MAX); + assert(state >= 0); + assert(state < _FREEZER_STATE_MAX); + return freezer_state_finish_table[state]; } diff --git a/src/core/cgroup.c b/src/core/cgroup.c index 9620436f68..218f867f24 100644 --- a/src/core/cgroup.c +++ b/src/core/cgroup.c @@ -5110,8 +5110,8 @@ int unit_cgroup_freezer_action(Unit *u, FreezerAction action) { int r; assert(u); - assert(IN_SET(action, FREEZER_FREEZE, FREEZER_PARENT_FREEZE, - FREEZER_THAW, FREEZER_PARENT_THAW)); + assert(action >= 0); + assert(action < _FREEZER_ACTION_MAX); if (!cg_freezer_supported()) return 0; diff --git a/src/core/cgroup.h b/src/core/cgroup.h index e31e69364e..1c5c1f75ab 100644 --- a/src/core/cgroup.h +++ b/src/core/cgroup.h @@ -60,7 +60,6 @@ typedef enum FreezerAction { FREEZER_PARENT_FREEZE, FREEZER_THAW, FREEZER_PARENT_THAW, - _FREEZER_ACTION_MAX, _FREEZER_ACTION_INVALID = -EINVAL, } FreezerAction; @@ -514,6 +513,7 @@ void unit_cgroup_catchup(Unit *u); bool unit_cgroup_delegate(Unit *u); int unit_get_cpuset(Unit *u, CPUSet *cpus, const char *name); + int unit_cgroup_freezer_action(Unit *u, FreezerAction action); const char* freezer_action_to_string(FreezerAction a) _const_; diff --git a/src/core/slice.c b/src/core/slice.c index 4e71976e4f..d8c507804f 100644 --- a/src/core/slice.c +++ b/src/core/slice.c @@ -356,8 +356,8 @@ static int slice_freezer_action(Unit *s, FreezerAction action) { int r; assert(s); - assert(IN_SET(action, FREEZER_FREEZE, FREEZER_PARENT_FREEZE, - FREEZER_THAW, FREEZER_PARENT_THAW)); + assert(action >= 0); + assert(action < _FREEZER_ACTION_MAX); if (action == FREEZER_FREEZE && !slice_can_freeze(s)) { /* We're intentionally only checking for FREEZER_FREEZE here and ignoring the diff --git a/src/core/unit.c b/src/core/unit.c index 8cdb3a025f..01763d7560 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -6161,8 +6161,8 @@ void unit_next_freezer_state(Unit *u, FreezerAction action, FreezerState *ret, F FreezerState curr, parent, next, tgt; assert(u); - assert(IN_SET(action, FREEZER_FREEZE, FREEZER_PARENT_FREEZE, - FREEZER_THAW, FREEZER_PARENT_THAW)); + assert(action >= 0); + assert(action < _FREEZER_ACTION_MAX); assert(ret); assert(ret_target); |