phy: core: Get a refcount to phy in devm_of_phy_get_by_index()
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>
This commit is contained in:
parent
a8c24724dd
commit
708744628b
@ -636,8 +636,9 @@ EXPORT_SYMBOL_GPL(devm_of_phy_get);
|
|||||||
* @np: node containing the phy
|
* @np: node containing the phy
|
||||||
* @index: index of the phy
|
* @index: index of the phy
|
||||||
*
|
*
|
||||||
* Gets the phy using _of_phy_get(), and associates a device with it using
|
* Gets the phy using _of_phy_get(), then gets a refcount to it,
|
||||||
* devres. On driver detach, release function is invoked on the devres data,
|
* and associates a device with it using devres. On driver detach,
|
||||||
|
* release function is invoked on the devres data,
|
||||||
* then, devres data is freed.
|
* 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);
|
return ERR_PTR(-ENOMEM);
|
||||||
|
|
||||||
phy = _of_phy_get(np, index);
|
phy = _of_phy_get(np, index);
|
||||||
if (!IS_ERR(phy)) {
|
if (IS_ERR(phy)) {
|
||||||
*ptr = phy;
|
|
||||||
devres_add(dev, ptr);
|
|
||||||
} else {
|
|
||||||
devres_free(ptr);
|
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;
|
return phy;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(devm_of_phy_get_by_index);
|
EXPORT_SYMBOL_GPL(devm_of_phy_get_by_index);
|
||||||
|
Loading…
Reference in New Issue
Block a user