All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andreas Kemnade <andreas@kemnade.info>
To: Karol P <karprzy7@gmail.com>
Cc: Roger Quadros <rogerq@kernel.org>,
	aaro.koskinen@iki.fi, khilman@baylibre.com, tony@atomide.com,
	lee@kernel.org, linux-omap@vger.kernel.org,
	linux-kernel@vger.kernel.org, skhan@linuxfoundation.org
Subject: Re: [PATCH] mfd: omap-usb-tll: check clk_prepare return code
Date: Thu, 5 Dec 2024 23:50:56 +0100	[thread overview]
Message-ID: <20241205235056.44b6c980@akair> (raw)
In-Reply-To: <CAKwoAfrvqUxPat9a+4LjRKYx2LZ=n6Q2H+ir3KYkBBj+Rv_HWQ@mail.gmail.com>

Am Thu, 5 Dec 2024 22:54:05 +0100
schrieb Karol P <karprzy7@gmail.com>:

> On Tue, 26 Nov 2024 at 23:06, Andreas Kemnade <andreas@kemnade.info> wrote:
> >
> > Am Tue, 19 Nov 2024 16:16:42 +0200
> > schrieb Roger Quadros <rogerq@kernel.org>:
> >  
> > > On 19/11/2024 15:56, Andreas Kemnade wrote:  
> > > > Am Tue, 19 Nov 2024 15:10:23 +0200
> > > > schrieb Roger Quadros <rogerq@kernel.org>:
> > > >  
> > > >> Hi,
> > > >>
> > > >> On 13/11/2024 23:16, 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 dev_dbg 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 | 11 +++++++----
> > > >>>  1 file changed, 7 insertions(+), 4 deletions(-)
> > > >>>
> > > >>> diff --git a/drivers/mfd/omap-usb-tll.c b/drivers/mfd/omap-usb-tll.c
> > > >>> index 0f7fdb99c809..2e9319ee1b74 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");
> > > >>>
> > > >>> @@ -248,10 +248,13 @@ static int usbtll_omap_probe(struct platform_device *pdev)
> > > >>>                                   "usb_tll_hs_usb_ch%d_clk", i);
> > > >>>           tll->ch_clk[i] = clk_get(dev, clkname);
> > > >>>
> > > >>> -         if (IS_ERR(tll->ch_clk[i]))
> > > >>> +         if (IS_ERR(tll->ch_clk[i])) {
> > > >>>                   dev_dbg(dev, "can't get clock : %s\n", clkname);  
> > > >
> > > > if you want dev_err() later, then why not here?  
> > >
> > > Because clk is optional. If it is not there then we should not complain.
> > > But if it is there then it needs to be enabled successfully.
> > >  
> > I guess you mean *prepared*, the clock is enabled later (with error
> > checking). But your reasoning makes sense.
> >  
> > > >  
> > > >>> -         else
> > > >>> -                 clk_prepare(tll->ch_clk[i]);
> > > >>> +         } else {
> > > >>> +                 err = clk_prepare(tll->ch_clk[i]);
> > > >>> +                 if (err)
> > > >>> +                         dev_dbg(dev, "clock prepare error for: %s\n", clkname);  
> > > >>
> > > >> dev_err()?
> > > >>  
> > > > So why do you want a different return handling here? (I doubt there is
> > > > any clock having a real prepare() involved here)
> > > >
> > > > As said in an earlier incarnation of this patch, the real question is
> > > > whether having partial clocks available is a valid operating scenario.
> > > > If yes, then the error should be ignored. If no, then bailing out early
> > > > is a good idea.  
> > >
> > > In the DT binding, clocks is optional. So if it doesn't exist it is not
> > > an error condition.
> > >  
> > > >
> > > > clk_prepare() errors are catched by failing clk_enable() later,
> > > > ch_clk[i] is checked later, too.
> > > >  
> > > >> I think we should return the error in this case.
> > > >> (after unpreparing the prepared clocks and clk_put())
> > > >>  
> > > > and pm_runtime_put_sync(dev)  
> >
> > which can probably be done before dealing with the clocks. It is only
> > needed for the register access.  
> 
> I'm fairly new to this subsystem and I'm trying to understand the
> conclusion. In the end, we should add dev_err() here after
> clk_prepare() with appropriate handling?
> 
we must make sure pm_runtime_put/get are paired and _put is called in
any case. Looking around a bit:
I think a good solution would be along this lines:
https://lore.kernel.org/linux-omap/34ab5f0b78c2869cc43797a72d6a2f40d9b246f3.camel@siemens.com/T/#u

using devm_clk_get_prepared() things can be simplified.

Regards,
Andreas

      reply	other threads:[~2024-12-05 22:51 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-13 21:16 [PATCH] mfd: omap-usb-tll: check clk_prepare return code Karol Przybylski
2024-11-19 13:10 ` Roger Quadros
2024-11-19 13:56   ` Andreas Kemnade
2024-11-19 14:16     ` Roger Quadros
2024-11-26 22:06       ` Andreas Kemnade
2024-12-05 21:54         ` Karol P
2024-12-05 22:50           ` Andreas Kemnade [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241205235056.44b6c980@akair \
    --to=andreas@kemnade.info \
    --cc=aaro.koskinen@iki.fi \
    --cc=karprzy7@gmail.com \
    --cc=khilman@baylibre.com \
    --cc=lee@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=rogerq@kernel.org \
    --cc=skhan@linuxfoundation.org \
    --cc=tony@atomide.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.