Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1292005

[PATCH 9/9] phy: core: Get a refcount to phy in devm_of_phy_get_by_index()

From Kishon Vijay Abraham I <kishon@ti.com>
Newsgroups linux.kernel
Subject [PATCH 9/9] phy: core: Get a refcount to phy in devm_of_phy_get_by_index()
Date 2015-12-15 11:10 +0100
Message-ID <qFUIr-2DP-15@gated-at.bofh.it> (permalink)
References <qFUIq-2DP-5@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


From: Chunfeng Yun <chunfeng.yun@mediatek.com>

On driver detach, devm_phy_release() will put a refcount to
the phy, so gets a refconut to it before return.

Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.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.7.9.5

--
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/

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[RESEND GIT PULL 0/9] phy: for 4.4 -rc Kishon Vijay Abraham I <kishon@ti.com> - 2015-12-15 11:10 +0100
  [PATCH 9/9] phy: core: Get a refcount to phy in devm_of_phy_get_by_index() Kishon Vijay Abraham I <kishon@ti.com> - 2015-12-15 11:10 +0100
  [PATCH 7/9] phy: miphy365x: add missing of_node_put Kishon Vijay Abraham I <kishon@ti.com> - 2015-12-15 11:10 +0100
  [PATCH 8/9] phy: cygnus: pcie: add missing of_node_put Kishon Vijay Abraham I <kishon@ti.com> - 2015-12-15 11:10 +0100
  [PATCH 2/9] phy: brcmstb-sata: add missing of_node_put Kishon Vijay Abraham I <kishon@ti.com> - 2015-12-15 11:10 +0100
  [PATCH 5/9] phy: rockchip-usb: add missing of_node_put Kishon Vijay Abraham I <kishon@ti.com> - 2015-12-15 11:20 +0100
  [PATCH 4/9] phy: berlin-sata: add missing of_node_put Kishon Vijay Abraham I <kishon@ti.com> - 2015-12-15 11:20 +0100
  [PATCH 3/9] phy: mt65xx-usb3: add missing of_node_put Kishon Vijay Abraham I <kishon@ti.com> - 2015-12-15 11:20 +0100
  Re: [RESEND GIT PULL 0/9] phy: for 4.4 -rc Greg KH <gregkh@linuxfoundation.org> - 2015-12-18 18:30 +0100
    Re: [RESEND GIT PULL 0/9] phy: for 4.4 -rc Kishon Vijay Abraham I <kishon@ti.com> - 2015-12-20 09:30 +0100

csiph-web