diff mbox series

mfd: omap-usb-tll: handle clk_prepare return code in usbtll_omap_probe

Message ID 20241106223324.479341-1-karprzy7@gmail.com (mailing list archive)
State New
Headers show
Series mfd: omap-usb-tll: handle clk_prepare return code in usbtll_omap_probe | expand

Commit Message

Karol P Nov. 6, 2024, 10:33 p.m. UTC
clk_prepare() is called in usbtll_omap_probe to fill clk array.
Return code is not checked, leaving possible error condition unhandled.

Added variable to hold return value from clk_prepare() and return statement
when it's not successful.

Found in coverity scan, CID 1594680

Signed-off-by: Karol Przybylski <karprzy7@gmail.com>
---
 drivers/mfd/omap-usb-tll.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Comments

Shuah Khan Nov. 6, 2024, 11:03 p.m. UTC | #1
On 11/6/24 15:33, Karol Przybylski wrote:
> clk_prepare() is called in usbtll_omap_probe to fill clk array.
> Return code is not checked, leaving possible error condition unhandled.
> 
> Added variable to hold return value from clk_prepare() and return statement
> when it's not successful.
> 
> Found in coverity scan, CID 1594680
> 
> Signed-off-by: Karol Przybylski <karprzy7@gmail.com>
> ---
>   drivers/mfd/omap-usb-tll.c | 8 ++++++--
>   1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/mfd/omap-usb-tll.c b/drivers/mfd/omap-usb-tll.c
> index 0f7fdb99c809..28446b082c85 100644
> --- a/drivers/mfd/omap-usb-tll.c
> +++ b/drivers/mfd/omap-usb-tll.c
> @@ -202,7 +202,7 @@ static int usbtll_omap_probe(struct platform_device *pdev)
>   	struct device				*dev =  &pdev->dev;
>   	struct usbtll_omap			*tll;
>   	void __iomem				*base;
> -	int					i, nch, ver;
> +	int					i, nch, ver, err;
>   
>   	dev_dbg(dev, "starting TI HSUSB TLL Controller\n");
>   
> @@ -251,7 +251,11 @@ static int usbtll_omap_probe(struct platform_device *pdev)
>   		if (IS_ERR(tll->ch_clk[i]))
>   			dev_dbg(dev, "can't get clock : %s\n", clkname);
>   		else
> -			clk_prepare(tll->ch_clk[i]);

Braces for the conditional don't looks right.

> +			err = clk_prepare(tll->ch_clk[i]);
> +			if (err) {
> +				dev_err(dev, "Unable to prepare clock\n");
> +				return err;

Did you check to see if callers handle this new error return
in this path?

> +	}

Same here

>   	}
>   

Same here
>   	pm_runtime_put_sync(dev);

thanks,
-- Shuah
Andreas Kemnade Nov. 6, 2024, 11:15 p.m. UTC | #2
Am Wed,  6 Nov 2024 23:33:24 +0100
schrieb Karol Przybylski <karprzy7@gmail.com>:

> clk_prepare() is called in usbtll_omap_probe to fill clk array.
> Return code is not checked, leaving possible error condition unhandled.
> 
> Added variable to hold return value from clk_prepare() and return statement
> when it's not successful.
> 
> Found in coverity scan, CID 1594680
> 
> Signed-off-by: Karol Przybylski <karprzy7@gmail.com>
> ---
>  drivers/mfd/omap-usb-tll.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/mfd/omap-usb-tll.c b/drivers/mfd/omap-usb-tll.c
> index 0f7fdb99c809..28446b082c85 100644
> --- a/drivers/mfd/omap-usb-tll.c
> +++ b/drivers/mfd/omap-usb-tll.c
> @@ -202,7 +202,7 @@ static int usbtll_omap_probe(struct platform_device *pdev)
>  	struct device				*dev =  &pdev->dev;
>  	struct usbtll_omap			*tll;
>  	void __iomem				*base;
> -	int					i, nch, ver;
> +	int					i, nch, ver, err;
>  
>  	dev_dbg(dev, "starting TI HSUSB TLL Controller\n");
>  
> @@ -251,7 +251,11 @@ static int usbtll_omap_probe(struct platform_device *pdev)
>  		if (IS_ERR(tll->ch_clk[i]))
>  			dev_dbg(dev, "can't get clock : %s\n", clkname);

if you add more intensive error checking, then why is this error
ignored and not returned?

>  		else
> -			clk_prepare(tll->ch_clk[i]);
> +			err = clk_prepare(tll->ch_clk[i]);
> +			if (err) {
unnatural braces, if (err) is not in the else branch ?!
> +				dev_err(dev, "Unable to prepare clock\n");
> +				return err;
> +	}
>  	}
>  
>  	pm_runtime_put_sync(dev);
and this one is not called if you return early.

Regards,
Andreas
Karol P Nov. 7, 2024, 11:12 a.m. UTC | #3
On Thu, 7 Nov 2024 at 00:15, Andreas Kemnade <andreas@kemnade.info> wrote:
>
> Am Wed,  6 Nov 2024 23:33:24 +0100
> schrieb Karol Przybylski <karprzy7@gmail.com>:
>
> > clk_prepare() is called in usbtll_omap_probe to fill clk array.
> > Return code is not checked, leaving possible error condition unhandled.
> >
> > Added variable to hold return value from clk_prepare() and return statement
> > when it's not successful.
> >
> > Found in coverity scan, CID 1594680
> >
> > Signed-off-by: Karol Przybylski <karprzy7@gmail.com>
> > ---
> >  drivers/mfd/omap-usb-tll.c | 8 ++++++--
> >  1 file changed, 6 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/mfd/omap-usb-tll.c b/drivers/mfd/omap-usb-tll.c
> > index 0f7fdb99c809..28446b082c85 100644
> > --- a/drivers/mfd/omap-usb-tll.c
> > +++ b/drivers/mfd/omap-usb-tll.c
> > @@ -202,7 +202,7 @@ static int usbtll_omap_probe(struct platform_device *pdev)
> >       struct device                           *dev =  &pdev->dev;
> >       struct usbtll_omap                      *tll;
> >       void __iomem                            *base;
> > -     int                                     i, nch, ver;
> > +     int                                     i, nch, ver, err;
> >
> >       dev_dbg(dev, "starting TI HSUSB TLL Controller\n");
> >
> > @@ -251,7 +251,11 @@ static int usbtll_omap_probe(struct platform_device *pdev)
> >               if (IS_ERR(tll->ch_clk[i]))
> >                       dev_dbg(dev, "can't get clock : %s\n", clkname);
>
> if you add more intensive error checking, then why is this error
> ignored and not returned?

Thank you for the feedback. It does seem that elevated error checking
is not the way
to go in this case. Do you think it would be good to add a similar
statement instead of
my initial changes? It would look something like this:

+               else {
                        err = clk_prepare(tll->ch_clk[i]);
+                       if (err)
+                               dev_dbg(dev, "clock prepare error for:
%s\n", clkname);
+               }

>
> >               else
> > -                     clk_prepare(tll->ch_clk[i]);
> > +                     err = clk_prepare(tll->ch_clk[i]);
> > +                     if (err) {
> unnatural braces, if (err) is not in the else branch ?!
> > +                             dev_err(dev, "Unable to prepare clock\n");
> > +                             return err;
> > +     }
> >       }
> >
> >       pm_runtime_put_sync(dev);
> and this one is not called if you return early.
>
> Regards,
> Andreas
diff mbox series

Patch

diff --git a/drivers/mfd/omap-usb-tll.c b/drivers/mfd/omap-usb-tll.c
index 0f7fdb99c809..28446b082c85 100644
--- a/drivers/mfd/omap-usb-tll.c
+++ b/drivers/mfd/omap-usb-tll.c
@@ -202,7 +202,7 @@  static int usbtll_omap_probe(struct platform_device *pdev)
 	struct device				*dev =  &pdev->dev;
 	struct usbtll_omap			*tll;
 	void __iomem				*base;
-	int					i, nch, ver;
+	int					i, nch, ver, err;
 
 	dev_dbg(dev, "starting TI HSUSB TLL Controller\n");
 
@@ -251,7 +251,11 @@  static int usbtll_omap_probe(struct platform_device *pdev)
 		if (IS_ERR(tll->ch_clk[i]))
 			dev_dbg(dev, "can't get clock : %s\n", clkname);
 		else
-			clk_prepare(tll->ch_clk[i]);
+			err = clk_prepare(tll->ch_clk[i]);
+			if (err) {
+				dev_err(dev, "Unable to prepare clock\n");
+				return err;
+	}
 	}
 
 	pm_runtime_put_sync(dev);