Commit 0305b709 authored by Alex Elder's avatar Alex Elder Committed by David S. Miller

net: ipa: use refcount_t for IPA clock reference count

Take advantage of the checking provided by refcount_t, rather than
using a plain atomic to represent the IPA clock reference count.

Note that we need to *set* the value to 1 in ipa_clock_get() rather
than incrementing it from 0 (because doing that is considered an
error for a refcount_t).
Signed-off-by: default avatarAlex Elder <elder@linaro.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent ba4ee3c0
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* Copyright (C) 2018-2020 Linaro Ltd. * Copyright (C) 2018-2020 Linaro Ltd.
*/ */
#include <linux/atomic.h> #include <linux/refcount.h>
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/clk.h> #include <linux/clk.h>
#include <linux/device.h> #include <linux/device.h>
...@@ -51,7 +51,7 @@ ...@@ -51,7 +51,7 @@
* @config_path: Configuration space interconnect * @config_path: Configuration space interconnect
*/ */
struct ipa_clock { struct ipa_clock {
atomic_t count; refcount_t count;
struct mutex mutex; /* protects clock enable/disable */ struct mutex mutex; /* protects clock enable/disable */
struct clk *core; struct clk *core;
struct icc_path *memory_path; struct icc_path *memory_path;
...@@ -195,7 +195,7 @@ static void ipa_clock_disable(struct ipa *ipa) ...@@ -195,7 +195,7 @@ static void ipa_clock_disable(struct ipa *ipa)
*/ */
bool ipa_clock_get_additional(struct ipa *ipa) bool ipa_clock_get_additional(struct ipa *ipa)
{ {
return !!atomic_inc_not_zero(&ipa->clock->count); return refcount_inc_not_zero(&ipa->clock->count);
} }
/* Get an IPA clock reference. If the reference count is non-zero, it is /* Get an IPA clock reference. If the reference count is non-zero, it is
...@@ -231,7 +231,7 @@ void ipa_clock_get(struct ipa *ipa) ...@@ -231,7 +231,7 @@ void ipa_clock_get(struct ipa *ipa)
ipa_endpoint_resume(ipa); ipa_endpoint_resume(ipa);
atomic_inc(&clock->count); refcount_set(&clock->count, 1);
out_mutex_unlock: out_mutex_unlock:
mutex_unlock(&clock->mutex); mutex_unlock(&clock->mutex);
...@@ -246,7 +246,7 @@ void ipa_clock_put(struct ipa *ipa) ...@@ -246,7 +246,7 @@ void ipa_clock_put(struct ipa *ipa)
struct ipa_clock *clock = ipa->clock; struct ipa_clock *clock = ipa->clock;
/* If this is not the last reference there's nothing more to do */ /* If this is not the last reference there's nothing more to do */
if (!atomic_dec_and_mutex_lock(&clock->count, &clock->mutex)) if (!refcount_dec_and_mutex_lock(&clock->count, &clock->mutex))
return; return;
ipa_endpoint_suspend(ipa); ipa_endpoint_suspend(ipa);
...@@ -294,7 +294,7 @@ struct ipa_clock *ipa_clock_init(struct device *dev) ...@@ -294,7 +294,7 @@ struct ipa_clock *ipa_clock_init(struct device *dev)
goto err_kfree; goto err_kfree;
mutex_init(&clock->mutex); mutex_init(&clock->mutex);
atomic_set(&clock->count, 0); refcount_set(&clock->count, 0);
return clock; return clock;
...@@ -311,7 +311,7 @@ void ipa_clock_exit(struct ipa_clock *clock) ...@@ -311,7 +311,7 @@ void ipa_clock_exit(struct ipa_clock *clock)
{ {
struct clk *clk = clock->core; struct clk *clk = clock->core;
WARN_ON(atomic_read(&clock->count) != 0); WARN_ON(refcount_read(&clock->count) != 0);
mutex_destroy(&clock->mutex); mutex_destroy(&clock->mutex);
ipa_interconnect_exit(clock); ipa_interconnect_exit(clock);
kfree(clock); kfree(clock);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment