* [PATCH] usb: chipidea: ci_hdrc_imx: fix potential error pointer dereference in probe
@ 2021-11-17 7:49 Dan Carpenter
2021-11-20 6:16 ` Peter Chen
0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2021-11-17 7:49 UTC (permalink / raw)
To: Peter Chen, Fabio Estevam
Cc: Greg Kroah-Hartman, Shawn Guo, Sascha Hauer,
Pengutronix Kernel Team, NXP Linux Team, Frieder Schrempf,
linux-usb, kernel-janitors
If the first call to devm_usb_get_phy_by_phandle(dev, "fsl,usbphy", 0)
fails with something other than -ENODEV then it leads to an error
pointer dereference. For those errors we should just jump directly to
the error handling.
Fixes: 8253a34bfae3 ("usb: chipidea: ci_hdrc_imx: Also search for 'phys' phandle")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
drivers/usb/chipidea/ci_hdrc_imx.c | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/drivers/usb/chipidea/ci_hdrc_imx.c b/drivers/usb/chipidea/ci_hdrc_imx.c
index f1d100671ee6..097142ffb184 100644
--- a/drivers/usb/chipidea/ci_hdrc_imx.c
+++ b/drivers/usb/chipidea/ci_hdrc_imx.c
@@ -420,15 +420,15 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev)
data->phy = devm_usb_get_phy_by_phandle(dev, "fsl,usbphy", 0);
if (IS_ERR(data->phy)) {
ret = PTR_ERR(data->phy);
- if (ret == -ENODEV) {
- data->phy = devm_usb_get_phy_by_phandle(dev, "phys", 0);
- if (IS_ERR(data->phy)) {
- ret = PTR_ERR(data->phy);
- if (ret == -ENODEV)
- data->phy = NULL;
- else
- goto err_clk;
- }
+ if (ret != -ENODEV)
+ goto err_clk;
+ data->phy = devm_usb_get_phy_by_phandle(dev, "phys", 0);
+ if (IS_ERR(data->phy)) {
+ ret = PTR_ERR(data->phy);
+ if (ret == -ENODEV)
+ data->phy = NULL;
+ else
+ goto err_clk;
}
}
--
2.20.1
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] usb: chipidea: ci_hdrc_imx: fix potential error pointer dereference in probe
2021-11-17 7:49 [PATCH] usb: chipidea: ci_hdrc_imx: fix potential error pointer dereference in probe Dan Carpenter
@ 2021-11-20 6:16 ` Peter Chen
0 siblings, 0 replies; 2+ messages in thread
From: Peter Chen @ 2021-11-20 6:16 UTC (permalink / raw)
To: Dan Carpenter
Cc: Fabio Estevam, Greg Kroah-Hartman, Shawn Guo, Sascha Hauer,
Pengutronix Kernel Team, NXP Linux Team, Frieder Schrempf,
linux-usb, kernel-janitors
On 21-11-17 10:49:23, Dan Carpenter wrote:
> If the first call to devm_usb_get_phy_by_phandle(dev, "fsl,usbphy", 0)
> fails with something other than -ENODEV then it leads to an error
> pointer dereference. For those errors we should just jump directly to
> the error handling.
>
> Fixes: 8253a34bfae3 ("usb: chipidea: ci_hdrc_imx: Also search for 'phys' phandle")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> drivers/usb/chipidea/ci_hdrc_imx.c | 18 +++++++++---------
> 1 file changed, 9 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/usb/chipidea/ci_hdrc_imx.c b/drivers/usb/chipidea/ci_hdrc_imx.c
> index f1d100671ee6..097142ffb184 100644
> --- a/drivers/usb/chipidea/ci_hdrc_imx.c
> +++ b/drivers/usb/chipidea/ci_hdrc_imx.c
> @@ -420,15 +420,15 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev)
> data->phy = devm_usb_get_phy_by_phandle(dev, "fsl,usbphy", 0);
> if (IS_ERR(data->phy)) {
> ret = PTR_ERR(data->phy);
> - if (ret == -ENODEV) {
> - data->phy = devm_usb_get_phy_by_phandle(dev, "phys", 0);
> - if (IS_ERR(data->phy)) {
> - ret = PTR_ERR(data->phy);
> - if (ret == -ENODEV)
> - data->phy = NULL;
> - else
> - goto err_clk;
> - }
> + if (ret != -ENODEV)
> + goto err_clk;
> + data->phy = devm_usb_get_phy_by_phandle(dev, "phys", 0);
> + if (IS_ERR(data->phy)) {
> + ret = PTR_ERR(data->phy);
> + if (ret == -ENODEV)
> + data->phy = NULL;
> + else
> + goto err_clk;
> }
> }
>
> --
> 2.20.1
>
Acked-by: Peter Chen <peter.chen@kernel.org>
--
Thanks,
Peter Chen
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-11-20 6:16 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-11-17 7:49 [PATCH] usb: chipidea: ci_hdrc_imx: fix potential error pointer dereference in probe Dan Carpenter
2021-11-20 6:16 ` Peter Chen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox