Having a flag set for an unused channel is irritating. It became especially confusing while developing debugfs support for this subsystem. Inverse the logic which makes the current and the future code easier to follow.
Signed-off-by: Wolfram Sang <[email protected]> --- drivers/hwspinlock/hwspinlock_core.c | 30 ++++++++++++++-------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/drivers/hwspinlock/hwspinlock_core.c b/drivers/hwspinlock/hwspinlock_core.c index cc8e952a6772..7aa597a28eec 100644 --- a/drivers/hwspinlock/hwspinlock_core.c +++ b/drivers/hwspinlock/hwspinlock_core.c @@ -28,7 +28,7 @@ #define HWSPINLOCK_RETRY_DELAY_US 100 /* radix tree tags */ -#define HWSPINLOCK_UNUSED (0) /* tags an hwspinlock as unused */ +#define HWSPINLOCK_USED (0) /* * A radix tree is used to maintain the available hwspinlock instances. @@ -42,8 +42,8 @@ * used as the ID's of the hwspinlock instances). * * The radix tree API supports tagging items in the tree, which this - * framework uses to mark unused hwspinlock instances (see the - * HWSPINLOCK_UNUSED tag above). As a result, the process of querying the + * framework uses to mark used hwspinlock instances (see the + * HWSPINLOCK_USED tag above). As a result, the process of querying the * tree, looking for an unused hwspinlock instance, is now reduced to a * single radix tree API call. */ @@ -465,7 +465,7 @@ static int hwspin_lock_register_single(struct hwspinlock *hwlock, int id) } /* mark this hwspinlock as available */ - tmp = radix_tree_tag_set(&hwspinlock_tree, id, HWSPINLOCK_UNUSED); + tmp = radix_tree_tag_clear(&hwspinlock_tree, id, HWSPINLOCK_USED); /* self-sanity check which should never fail */ WARN_ON(tmp != hwlock); @@ -482,9 +482,9 @@ static struct hwspinlock *hwspin_lock_unregister_single(unsigned int id) mutex_lock(&hwspinlock_tree_lock); - /* make sure the hwspinlock is not in use (tag is set) */ - ret = radix_tree_tag_get(&hwspinlock_tree, id, HWSPINLOCK_UNUSED); - if (ret == 0) { + /* make sure the hwspinlock is not in use */ + ret = radix_tree_tag_get(&hwspinlock_tree, id, HWSPINLOCK_USED); + if (ret) { pr_err("hwspinlock %d still in use (or not present)\n", id); goto out; } @@ -700,8 +700,8 @@ static int __hwspin_lock_request(struct hwspinlock *hwlock) ret = 0; /* mark hwspinlock as used, should not fail */ - tmp = radix_tree_tag_clear(&hwspinlock_tree, hwlock_to_id(hwlock), - HWSPINLOCK_UNUSED); + tmp = radix_tree_tag_set(&hwspinlock_tree, hwlock_to_id(hwlock), + HWSPINLOCK_USED); /* self-sanity check that should never fail */ WARN_ON(tmp != hwlock); @@ -740,8 +740,8 @@ struct hwspinlock *hwspin_lock_request_specific(unsigned int id) WARN_ON(hwlock_to_id(hwlock) != id); /* make sure this hwspinlock is unused */ - ret = radix_tree_tag_get(&hwspinlock_tree, id, HWSPINLOCK_UNUSED); - if (ret == 0) { + ret = radix_tree_tag_get(&hwspinlock_tree, id, HWSPINLOCK_USED); + if (ret) { pr_warn("hwspinlock %u is already in use\n", id); hwlock = NULL; goto out; @@ -786,8 +786,8 @@ int hwspin_lock_free(struct hwspinlock *hwlock) /* make sure the hwspinlock is used */ ret = radix_tree_tag_get(&hwspinlock_tree, hwlock_to_id(hwlock), - HWSPINLOCK_UNUSED); - if (ret == 1) { + HWSPINLOCK_USED); + if (!ret) { dev_err(dev, "%s: hwlock is already free\n", __func__); dump_stack(); ret = -EINVAL; @@ -798,8 +798,8 @@ int hwspin_lock_free(struct hwspinlock *hwlock) pm_runtime_put(dev); /* mark this hwspinlock as available */ - tmp = radix_tree_tag_set(&hwspinlock_tree, hwlock_to_id(hwlock), - HWSPINLOCK_UNUSED); + tmp = radix_tree_tag_clear(&hwspinlock_tree, hwlock_to_id(hwlock), + HWSPINLOCK_USED); /* sanity check (this shouldn't happen) */ WARN_ON(tmp != hwlock); -- 2.51.0

