* [PATCH 1/2] phy: phy-core: increment refcounting variables only on 'success'
@ 2013-12-19 14:31 Kishon Vijay Abraham I
2013-12-19 14:31 ` [PATCH 2/2] phy: phy-core.c: remove unnecessary initialization of local variables Kishon Vijay Abraham I
2013-12-20 5:06 ` [PATCH v2 1/2] phy: phy-core: increment refcounting variables only on 'success' Kishon Vijay Abraham I
0 siblings, 2 replies; 3+ messages in thread
From: Kishon Vijay Abraham I @ 2013-12-19 14:31 UTC (permalink / raw)
To: balbi, kishon
Cc: linux-kernel, gregkh, s.nawrocki, jg1.han, mporter, andrew,
k.debski, gautamvivek1987, heikki.krogerus, yuvaraj.cd
Increment 'init_count' only if the 'init' callback succeeded and decrement
'init_count' only if the 'exit' callback succeded. Increment 'power_count'
only if 'power_on' callback succeded and if it failed disable the clocks using
phy_pm_runtime_put_sync(). Also decrement 'power_count' only if 'power_off'
callback succeded and if it failed do not disable the clocks.
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
drivers/phy/phy-core.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
index 03cf8fb..e198259 100644
--- a/drivers/phy/phy-core.c
+++ b/drivers/phy/phy-core.c
@@ -155,13 +155,14 @@ int phy_init(struct phy *phy)
return ret;
mutex_lock(&phy->mutex);
- if (phy->init_count++ == 0 && phy->ops->init) {
+ if (phy->init_count == 0 && phy->ops->init) {
ret = phy->ops->init(phy);
if (ret < 0) {
dev_err(&phy->dev, "phy init failed --> %d\n", ret);
goto out;
}
}
+ ++phy->init_count;
out:
mutex_unlock(&phy->mutex);
@@ -179,13 +180,14 @@ int phy_exit(struct phy *phy)
return ret;
mutex_lock(&phy->mutex);
- if (--phy->init_count == 0 && phy->ops->exit) {
+ if (phy->init_count == 1 && phy->ops->exit) {
ret = phy->ops->exit(phy);
if (ret < 0) {
dev_err(&phy->dev, "phy exit failed --> %d\n", ret);
goto out;
}
}
+ --phy->init_count;
out:
mutex_unlock(&phy->mutex);
@@ -203,16 +205,20 @@ int phy_power_on(struct phy *phy)
return ret;
mutex_lock(&phy->mutex);
- if (phy->power_count++ == 0 && phy->ops->power_on) {
+ if (phy->power_count == 0 && phy->ops->power_on) {
ret = phy->ops->power_on(phy);
if (ret < 0) {
dev_err(&phy->dev, "phy poweron failed --> %d\n", ret);
goto out;
}
}
+ ++phy->power_count;
+ mutex_unlock(&phy->mutex);
+ return 0;
out:
mutex_unlock(&phy->mutex);
+ phy_pm_runtime_put_sync(phy);
return ret;
}
@@ -223,13 +229,16 @@ int phy_power_off(struct phy *phy)
int ret = -ENOTSUPP;
mutex_lock(&phy->mutex);
- if (--phy->power_count == 0 && phy->ops->power_off) {
+ if (phy->power_count == 1 && phy->ops->power_off) {
ret = phy->ops->power_off(phy);
if (ret < 0) {
dev_err(&phy->dev, "phy poweroff failed --> %d\n", ret);
goto out;
}
}
+ --phy->power_count;
+ mutex_unlock(&phy->mutex);
+ return 0;
out:
mutex_unlock(&phy->mutex);
--
1.7.10.4
^ permalink raw reply [flat|nested] 3+ messages in thread* [PATCH 2/2] phy: phy-core.c: remove unnecessary initialization of local variables
2013-12-19 14:31 [PATCH 1/2] phy: phy-core: increment refcounting variables only on 'success' Kishon Vijay Abraham I
@ 2013-12-19 14:31 ` Kishon Vijay Abraham I
2013-12-20 5:06 ` [PATCH v2 1/2] phy: phy-core: increment refcounting variables only on 'success' Kishon Vijay Abraham I
1 sibling, 0 replies; 3+ messages in thread
From: Kishon Vijay Abraham I @ 2013-12-19 14:31 UTC (permalink / raw)
To: balbi, kishon
Cc: linux-kernel, gregkh, s.nawrocki, jg1.han, mporter, andrew,
k.debski, gautamvivek1987, heikki.krogerus, yuvaraj.cd
There were a few places where variables are initialized unncessarily.
Remove those initializations.
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
drivers/phy/phy-core.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
index e198259..8d9ef25 100644
--- a/drivers/phy/phy-core.c
+++ b/drivers/phy/phy-core.c
@@ -198,7 +198,7 @@ EXPORT_SYMBOL_GPL(phy_exit);
int phy_power_on(struct phy *phy)
{
- int ret = -ENOTSUPP;
+ int ret;
ret = phy_pm_runtime_get_sync(phy);
if (ret < 0 && ret != -ENOTSUPP)
@@ -226,7 +226,7 @@ EXPORT_SYMBOL_GPL(phy_power_on);
int phy_power_off(struct phy *phy)
{
- int ret = -ENOTSUPP;
+ int ret;
mutex_lock(&phy->mutex);
if (phy->power_count == 1 && phy->ops->power_off) {
@@ -369,7 +369,7 @@ EXPORT_SYMBOL_GPL(of_phy_simple_xlate);
struct phy *phy_get(struct device *dev, const char *string)
{
int index = 0;
- struct phy *phy = NULL;
+ struct phy *phy;
if (string == NULL) {
dev_WARN(dev, "missing string\n");
--
1.7.10.4
^ permalink raw reply [flat|nested] 3+ messages in thread* [PATCH v2 1/2] phy: phy-core: increment refcounting variables only on 'success'
2013-12-19 14:31 [PATCH 1/2] phy: phy-core: increment refcounting variables only on 'success' Kishon Vijay Abraham I
2013-12-19 14:31 ` [PATCH 2/2] phy: phy-core.c: remove unnecessary initialization of local variables Kishon Vijay Abraham I
@ 2013-12-20 5:06 ` Kishon Vijay Abraham I
1 sibling, 0 replies; 3+ messages in thread
From: Kishon Vijay Abraham I @ 2013-12-20 5:06 UTC (permalink / raw)
To: balbi, kishon
Cc: linux-kernel, gregkh, s.nawrocki, jg1.han, mporter, andrew,
k.debski, gautamvivek1987, heikki.krogerus, yuvaraj.cd,
george.cherian
Increment 'init_count' only if the 'init' callback succeeded and decrement
'init_count' only if the 'exit' callback succeded. Increment 'power_count'
only if 'power_on' callback succeded and if it failed disable the clocks using
phy_pm_runtime_put_sync(). Also decrement 'power_count' only if 'power_off'
callback succeded and if it failed do not disable the clocks.
Reported-by: George Cherian <george.cherian@ti.com>
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
Changes from v1:
Fixed power_off to call phy_pm_runtime_put only when there is no error in
power_off callback
drivers/phy/phy-core.c | 22 ++++++++++++++--------
1 file changed, 14 insertions(+), 8 deletions(-)
diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
index 03cf8fb..27b8f3f 100644
--- a/drivers/phy/phy-core.c
+++ b/drivers/phy/phy-core.c
@@ -155,13 +155,14 @@ int phy_init(struct phy *phy)
return ret;
mutex_lock(&phy->mutex);
- if (phy->init_count++ == 0 && phy->ops->init) {
+ if (phy->init_count == 0 && phy->ops->init) {
ret = phy->ops->init(phy);
if (ret < 0) {
dev_err(&phy->dev, "phy init failed --> %d\n", ret);
goto out;
}
}
+ ++phy->init_count;
out:
mutex_unlock(&phy->mutex);
@@ -179,13 +180,14 @@ int phy_exit(struct phy *phy)
return ret;
mutex_lock(&phy->mutex);
- if (--phy->init_count == 0 && phy->ops->exit) {
+ if (phy->init_count == 1 && phy->ops->exit) {
ret = phy->ops->exit(phy);
if (ret < 0) {
dev_err(&phy->dev, "phy exit failed --> %d\n", ret);
goto out;
}
}
+ --phy->init_count;
out:
mutex_unlock(&phy->mutex);
@@ -203,16 +205,20 @@ int phy_power_on(struct phy *phy)
return ret;
mutex_lock(&phy->mutex);
- if (phy->power_count++ == 0 && phy->ops->power_on) {
+ if (phy->power_count == 0 && phy->ops->power_on) {
ret = phy->ops->power_on(phy);
if (ret < 0) {
dev_err(&phy->dev, "phy poweron failed --> %d\n", ret);
goto out;
}
}
+ ++phy->power_count;
+ mutex_unlock(&phy->mutex);
+ return 0;
out:
mutex_unlock(&phy->mutex);
+ phy_pm_runtime_put_sync(phy);
return ret;
}
@@ -223,19 +229,19 @@ int phy_power_off(struct phy *phy)
int ret = -ENOTSUPP;
mutex_lock(&phy->mutex);
- if (--phy->power_count == 0 && phy->ops->power_off) {
+ if (phy->power_count == 1 && phy->ops->power_off) {
ret = phy->ops->power_off(phy);
if (ret < 0) {
dev_err(&phy->dev, "phy poweroff failed --> %d\n", ret);
- goto out;
+ mutex_unlock(&phy->mutex);
+ return ret;
}
}
-
-out:
+ --phy->power_count;
mutex_unlock(&phy->mutex);
phy_pm_runtime_put(phy);
- return ret;
+ return 0;
}
EXPORT_SYMBOL_GPL(phy_power_off);
--
1.7.10.4
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-12-20 5:07 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-12-19 14:31 [PATCH 1/2] phy: phy-core: increment refcounting variables only on 'success' Kishon Vijay Abraham I
2013-12-19 14:31 ` [PATCH 2/2] phy: phy-core.c: remove unnecessary initialization of local variables Kishon Vijay Abraham I
2013-12-20 5:06 ` [PATCH v2 1/2] phy: phy-core: increment refcounting variables only on 'success' Kishon Vijay Abraham I
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®