From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752145AbbKQGEz (ORCPT ); Tue, 17 Nov 2015 01:04:55 -0500 Received: from mx0b-0016f401.pphosted.com ([67.231.156.173]:25437 "EHLO mx0b-0016f401.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751151AbbKQGEx (ORCPT ); Tue, 17 Nov 2015 01:04:53 -0500 Date: Tue, 17 Nov 2015 14:00:26 +0800 From: Jisheng Zhang To: Chunfeng Yun CC: Kishon Vijay Abraham I , , , Daniel Kurtz , , Alan Stern , Arun Ramamurthy , Subject: Re: [RESEND] phy: core: Get a refcount to phy in devm_of_phy_get_by_index() Message-ID: <20151117140026.270a408e@xhacker> In-Reply-To: <1447739808-29472-1-git-send-email-chunfeng.yun@mediatek.com> References: <1447739808-29472-1-git-send-email-chunfeng.yun@mediatek.com> X-Mailer: Claws Mail 3.13.0 (GTK+ 2.24.28; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2015-11-17_05:,, signatures=0 X-Proofpoint-Spam-Details: rule=inbound_notspam policy=inbound score=0 spamscore=0 suspectscore=2 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1507310000 definitions=main-1511170101 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On Tue, 17 Nov 2015 13:56:48 +0800 Chunfeng Yun 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 > --- > 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);