Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1270884 > unrolled thread
| Started by | Chunfeng Yun <chunfeng.yun@mediatek.com> |
|---|---|
| First post | 2015-11-17 07:00 +0100 |
| Last post | 2015-11-17 07:10 +0100 |
| Articles | 2 — 2 participants |
Back to article view | Back to linux.kernel
[RESEND] phy: core: Get a refcount to phy in devm_of_phy_get_by_index() Chunfeng Yun <chunfeng.yun@mediatek.com> - 2015-11-17 07:00 +0100
Re: [RESEND] phy: core: Get a refcount to phy in devm_of_phy_get_by_index() Jisheng Zhang <jszhang@marvell.com> - 2015-11-17 07:10 +0100
| From | Chunfeng Yun <chunfeng.yun@mediatek.com> |
|---|---|
| Date | 2015-11-17 07:00 +0100 |
| Subject | [RESEND] phy: core: Get a refcount to phy in devm_of_phy_get_by_index() |
| Message-ID | <qvHt7-Um-3@gated-at.bofh.it> |
On driver detach, devm_phy_release() will put a refcount to
the phy, so gets a refconut to it before return.
Change-Id: I56fe428bf945f19c38d56245978c8ca17340eb2c
Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
---
drivers/phy/phy-core.c | 21 +++++++++++++++------
1 file changed, 15 insertions(+), 6 deletions(-)
diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
index fc48fac..8c7f27d 100644
--- a/drivers/phy/phy-core.c
+++ b/drivers/phy/phy-core.c
@@ -636,8 +636,9 @@ EXPORT_SYMBOL_GPL(devm_of_phy_get);
* @np: node containing the phy
* @index: index of the phy
*
- * Gets the phy using _of_phy_get(), and associates a device with it using
- * devres. On driver detach, release function is invoked on the devres data,
+ * Gets the phy using _of_phy_get(), then gets a refcount to it,
+ * and associates a device with it using devres. On driver detach,
+ * release function is invoked on the devres data,
* then, devres data is freed.
*
*/
@@ -651,13 +652,21 @@ struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np,
return ERR_PTR(-ENOMEM);
phy = _of_phy_get(np, index);
- if (!IS_ERR(phy)) {
- *ptr = phy;
- devres_add(dev, ptr);
- } else {
+ if (IS_ERR(phy)) {
devres_free(ptr);
+ return phy;
}
+ if (!try_module_get(phy->ops->owner)) {
+ devres_free(ptr);
+ return ERR_PTR(-EPROBE_DEFER);
+ }
+
+ get_device(&phy->dev);
+
+ *ptr = phy;
+ devres_add(dev, ptr);
+
return phy;
}
EXPORT_SYMBOL_GPL(devm_of_phy_get_by_index);
--
1.8.1.1.dirty
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [next] | [standalone]
| From | Jisheng Zhang <jszhang@marvell.com> |
|---|---|
| Date | 2015-11-17 07:10 +0100 |
| Subject | Re: [RESEND] phy: core: Get a refcount to phy in devm_of_phy_get_by_index() |
| Message-ID | <qvHCN-1dg-7@gated-at.bofh.it> |
| In reply to | #1270884 |
Hi,
On Tue, 17 Nov 2015 13:56:48 +0800
Chunfeng Yun <chunfeng.yun@mediatek.com> wrote:
> On driver detach, devm_phy_release() will put a refcount to
> the phy, so gets a refconut to it before return.
>
> Change-Id: I56fe428bf945f19c38d56245978c8ca17340eb2c
This line need to be removed
> Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
> ---
> drivers/phy/phy-core.c | 21 +++++++++++++++------
> 1 file changed, 15 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
> index fc48fac..8c7f27d 100644
> --- a/drivers/phy/phy-core.c
> +++ b/drivers/phy/phy-core.c
> @@ -636,8 +636,9 @@ EXPORT_SYMBOL_GPL(devm_of_phy_get);
> * @np: node containing the phy
> * @index: index of the phy
> *
> - * Gets the phy using _of_phy_get(), and associates a device with it using
> - * devres. On driver detach, release function is invoked on the devres data,
> + * Gets the phy using _of_phy_get(), then gets a refcount to it,
> + * and associates a device with it using devres. On driver detach,
> + * release function is invoked on the devres data,
> * then, devres data is freed.
> *
> */
> @@ -651,13 +652,21 @@ struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np,
> return ERR_PTR(-ENOMEM);
>
> phy = _of_phy_get(np, index);
> - if (!IS_ERR(phy)) {
> - *ptr = phy;
> - devres_add(dev, ptr);
> - } else {
> + if (IS_ERR(phy)) {
> devres_free(ptr);
> + return phy;
> }
>
> + if (!try_module_get(phy->ops->owner)) {
> + devres_free(ptr);
> + return ERR_PTR(-EPROBE_DEFER);
> + }
> +
> + get_device(&phy->dev);
> +
> + *ptr = phy;
> + devres_add(dev, ptr);
> +
> return phy;
> }
> EXPORT_SYMBOL_GPL(devm_of_phy_get_by_index);
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web