All of lore.kernel.org
 help / color / mirror / Atom feed
From: Geert Uytterhoeven <geert@linux-m68k.org>
To: Simon Horman <horms@verge.net.au>
Cc: Phil Edworthy <phil.edworthy@renesas.com>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Jarkko Nikula <jarkko.nikula@linux.intel.com>,
	Linux I2C <linux-i2c@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Linux-Renesas <linux-renesas-soc@vger.kernel.org>,
	Mika Westerberg <mika.westerberg@linux.intel.com>
Subject: Re: [PATCH 2/2] i2c: designware: Add support for a bus clock
Date: Wed, 18 Jul 2018 13:06:12 +0200	[thread overview]
Message-ID: <CAMuHMdWJkwJ5+DDqbaWH-cMhRQynWCxb4MbFtpejqi1HhUBHTQ@mail.gmail.com> (raw)
In-Reply-To: <20180718091448.fw2y7ea6sk2osi3g@verge.net.au>

On Wed, Jul 18, 2018 at 11:14 AM Simon Horman <horms@verge.net.au> wrote:
> On Tue, Jul 17, 2018 at 02:57:27PM +0000, Phil Edworthy wrote:
> > On 17 July 2018 15:47, Andy Shevchenko wrote:
> > > On Tue, 2018-07-17 at 14:40 +0000, Phil Edworthy wrote:
> > > > On 17 July 2018 15:19, Andy Shevchenko wrote:
> > > > > On Tue, 2018-07-17 at 12:42 +0000, Phil Edworthy wrote:
> > > > >
> > > > > > > While your point sounds valid (don't remember how clk_get() is
> > > > > > > implemented), NULL is also OK to have.
> > > > > >
> > > > > > Ok as in there is no bus clock, right?
> > > > > > So it should be:
> > > > > >  if (!IS_ERR_OR_NULL (dev->busclk))
> > > > >
> > > > > Nope, NULL is no error case for optional clock.
> > > >
> > > > I must be missing something here...
> > >
> > > See how clk_prepare_enable() is implemented.
> > Ok, if busclk is NULL the code can safely call clk_prepare_enable()
> >
> > > > I agree that NULL for an optional clock is not an error. However, the
> > > > code above is now:
> > > > + if (prepare) {
> > > > +         /* Optional bus clock */
> > >
> > > > +         if (!IS_ERR_OR_NULL(dev->busclk)) {
> > >
> > > Check for NULL is redundant.
> > >
> > > > +                 ret = clk_prepare_enable(dev->busclk);
> > > > +                 if (ret)
> > > > +                         return ret;
> > > > +         }
> > > > +
> > > >           return clk_prepare_enable(dev->clk);
> > > > + }
> > > >
> > > > So, if you have a valid busclk, it gets enabled, otherwise it is left
> > > > alone.
> > >
> > So the code as sent in the original email is correct (aside from Geert's
> > comments about EPROBE_DEFER handling).
> >
> > Maybe I need some coffee :\
> > Thanks
> > Phil
>
> My point is that errors should be treated as errors.
>
> In i2c_dw_prepare_clk() the following appears:
>
>         if (IS_ERR(dev->clk))
>                 return PTR_ERR(dev->clk);
>
> So dev->clk being an error value is treated as an error that
> is passed up to the caller.
>
> But in your patch (and the snippet below) dev->busclk is treated
> as the optional clock not being present. Even if the error stored
> nothing to do with the clock not being present - f.e.  ENOMEM or
> as Geert mentioned elsewhere, EPROBE_DEFER.
>
> Assuming the absense of the optional clock is indicated by ENOENT,
> in my view correct code would include something like:
>
>         ...
>
>         if (IS_ERR(dev->clk))
>                 return PTR_ERR(dev->clk);
>
>         if (IS_ERR(dev->buslck) && PTR_ERR(dev->busclk) != -ENOENT)
>                 return PTR_ERR(dev->busclk);
>
>         ...

As this is a commonly-used construct, perhaps it would be good to introduce
clk_get_optional() (cfr. gpiod_get_optional()) and devm_clk_get_optional(),
which would return NULL instead of -ENOENT?
Then it becomes a simple check for IS_ERR() in the driver.

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

  parent reply	other threads:[~2018-07-18 11:06 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-16  8:59 [PATCH 0/2] i2c: designware: Add support for a bus clock Phil Edworthy
2018-07-16  8:59 ` Phil Edworthy
2018-07-16  8:59 ` [PATCH 1/2] dt: snps,designware-i2c: Add clock bindings documentation Phil Edworthy
2018-07-20 16:19   ` Rob Herring
2018-07-16  8:59 ` [PATCH 2/2] i2c: designware: Add support for a bus clock Phil Edworthy
2018-07-17 12:07   ` Simon Horman
2018-07-17 12:23     ` Andy Shevchenko
2018-07-17 12:42       ` Phil Edworthy
2018-07-17 12:42         ` Phil Edworthy
2018-07-17 13:01         ` Geert Uytterhoeven
2018-07-17 13:12           ` Phil Edworthy
2018-07-17 14:18         ` Andy Shevchenko
2018-07-17 14:18           ` Andy Shevchenko
2018-07-17 14:40           ` Phil Edworthy
2018-07-17 14:40             ` Phil Edworthy
2018-07-17 14:47             ` Andy Shevchenko
2018-07-17 14:47               ` Andy Shevchenko
2018-07-17 14:57               ` Phil Edworthy
2018-07-17 14:57                 ` Phil Edworthy
2018-07-18  9:14                 ` Simon Horman
2018-07-18  9:14                   ` Simon Horman
2018-07-18  9:21                   ` Phil Edworthy
2018-07-18  9:21                     ` Phil Edworthy
2018-07-19  7:42                     ` Simon Horman
2018-07-19  7:42                       ` Simon Horman
2018-07-18 11:06                   ` Geert Uytterhoeven [this message]
2018-07-18 12:52                     ` Andy Shevchenko

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=CAMuHMdWJkwJ5+DDqbaWH-cMhRQynWCxb4MbFtpejqi1HhUBHTQ@mail.gmail.com \
    --to=geert@linux-m68k.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=horms@verge.net.au \
    --cc=jarkko.nikula@linux.intel.com \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=mika.westerberg@linux.intel.com \
    --cc=phil.edworthy@renesas.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.