提交 71a234a9 编写于 作者: C Christophe JAILLET 提交者: Zheng Zengkai

usb: bdc: Fix a resource leak in the error handling path of 'bdc_probe()'

stable inclusion
from stable-5.10.65
commit 9ee4ff8cbe392669e187e9c370a09d16493ae1ef
bugzilla: 182361 https://gitee.com/openeuler/kernel/issues/I4EH3U

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=9ee4ff8cbe392669e187e9c370a09d16493ae1ef

--------------------------------

[ Upstream commit 6f15a2a0 ]

If an error occurs after a successful 'clk_prepare_enable()' call, it must
be undone by a corresponding 'clk_disable_unprepare()' call.
This call is already present in the remove function.

Add this call in the error handling path and reorder the code so that the
'clk_prepare_enable()' call happens later in the function.
The goal is to have as much managed resources functions as possible
before the 'clk_prepare_enable()' call in order to keep the error handling
path simple.

While at it, remove the now unneeded 'clk' variable.

Fixes: c87dca04 ("usb: bdc: Add clock enable for new chips with a separate BDC clock")
Acked-by: NFlorian Fainelli <f.fainelli@gmail.com>
Signed-off-by: NChristophe JAILLET <christophe.jaillet@wanadoo.fr>
Link: https://lore.kernel.org/r/f8a4a6897deb0c8cb2e576580790303550f15fcd.1629314734.git.christophe.jaillet@wanadoo.frSigned-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: NSasha Levin <sashal@kernel.org>
Signed-off-by: NChen Jun <chenjun102@huawei.com>
Acked-by: NWeilong Chen <chenweilong@huawei.com>
Signed-off-by: NChen Jun <chenjun102@huawei.com>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
上级 2bea13cc
......@@ -488,27 +488,14 @@ static int bdc_probe(struct platform_device *pdev)
int irq;
u32 temp;
struct device *dev = &pdev->dev;
struct clk *clk;
int phy_num;
dev_dbg(dev, "%s()\n", __func__);
clk = devm_clk_get_optional(dev, "sw_usbd");
if (IS_ERR(clk))
return PTR_ERR(clk);
ret = clk_prepare_enable(clk);
if (ret) {
dev_err(dev, "could not enable clock\n");
return ret;
}
bdc = devm_kzalloc(dev, sizeof(*bdc), GFP_KERNEL);
if (!bdc)
return -ENOMEM;
bdc->clk = clk;
bdc->regs = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(bdc->regs))
return PTR_ERR(bdc->regs);
......@@ -545,10 +532,20 @@ static int bdc_probe(struct platform_device *pdev)
}
}
bdc->clk = devm_clk_get_optional(dev, "sw_usbd");
if (IS_ERR(bdc->clk))
return PTR_ERR(bdc->clk);
ret = clk_prepare_enable(bdc->clk);
if (ret) {
dev_err(dev, "could not enable clock\n");
return ret;
}
ret = bdc_phy_init(bdc);
if (ret) {
dev_err(bdc->dev, "BDC phy init failure:%d\n", ret);
return ret;
goto disable_clk;
}
temp = bdc_readl(bdc->regs, BDC_BDCCAP1);
......@@ -581,6 +578,8 @@ static int bdc_probe(struct platform_device *pdev)
bdc_hw_exit(bdc);
phycleanup:
bdc_phy_exit(bdc);
disable_clk:
clk_disable_unprepare(bdc->clk);
return ret;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册