From: Guenter Roeck <linux@roeck-us.net>
To: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
Cc: Bruno Thomsen <bruno.thomsen@gmail.com>,
linux-rtc@vger.kernel.org,
Alessandro Zummo <a.zummo@towertech.it>,
Alexandre Belloni <alexandre.belloni@bootlin.com>,
linux-watchdog@vger.kernel.org,
"open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS"
<devicetree@vger.kernel.org>,
open list <linux-kernel@vger.kernel.org>,
Rob Herring <robh+dt@kernel.org>,
Sascha Hauer <kernel@pengutronix.de>,
Wim Van Sebroeck <wim@linux-watchdog.org>,
Qiang Zhao <qiang.zhao@nxp.com>
Subject: Re: [PATCH 2/2] [RFC] rtc: pcf2127: only use watchdog when explicitly available
Date: Mon, 28 Sep 2020 09:26:06 -0700 [thread overview]
Message-ID: <20200928162606.GA106276@roeck-us.net> (raw)
In-Reply-To: <20200928084343.cl42lxsiionvq7tg@pengutronix.de>
On Mon, Sep 28, 2020 at 10:43:43AM +0200, Uwe Kleine-König wrote:
> On Sun, Sep 27, 2020 at 08:54:47AM -0700, Guenter Roeck wrote:
> > On 9/27/20 1:09 AM, Bruno Thomsen wrote:
> > > Den tor. 24. sep. 2020 kl. 12.53 skrev Uwe Kleine-König
> > > <u.kleine-koenig@pengutronix.de>:
> > >>
> > >> Most boards using the pcf2127 chip (in my bubble) don't make use of the
> > >> watchdog functionality and the respective output is not connected. The
> > >> effect on such a board is that there is a watchdog device provided that
> > >> doesn't work.
> > >>
> > >> So only register the watchdog if the device tree has a "has-watchdog"
> > >> property.
> > >>
> > >> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> > >> ---
> > >> drivers/rtc/rtc-pcf2127.c | 3 ++-
> > >> 1 file changed, 2 insertions(+), 1 deletion(-)
> > >>
> > >> diff --git a/drivers/rtc/rtc-pcf2127.c b/drivers/rtc/rtc-pcf2127.c
> > >> index 5b1f1949b5e5..8bd89d641578 100644
> > >> --- a/drivers/rtc/rtc-pcf2127.c
> > >> +++ b/drivers/rtc/rtc-pcf2127.c
> > >> @@ -340,7 +340,8 @@ static int pcf2127_watchdog_init(struct device *dev, struct pcf2127 *pcf2127)
> > >> u32 wdd_timeout;
> > >> int ret;
> > >>
> > >> - if (!IS_ENABLED(CONFIG_WATCHDOG))
> > >> + if (!IS_ENABLED(CONFIG_WATCHDOG) ||
> > >> + !device_property_read_bool(dev, "has-watchdog"))
> > >> return 0;
> > >
> > > I don't think the compiler can remove the function if
> > > CONFIG_WATCHDOG is disabled due to the device tree
> > > value check. Maybe it can if split into 2 conditions.
> > >
> >
> > If the first part of the expression is always false, the second
> > part should not even be evaluated.
>
> This is wrong. For || the second expression isn't evaluated if the first
> evaluates to true (and the whole expression becomes true). This is the
> intended behaviour: If CONFIG_WATCHDOG is off, we don't need to check
> for the dt property and just skip the watchdog part.
>
Sorry, I meant to say "If the first part of the expression is always true".
Guenter
> > Either case, the code now hard depends on the compiler optimizing the
> > code away.
> >
> > It calls devm_watchdog_register_device() which doesn't exist
> > if CONFIG_WATCHDOG is not enabled. I didn't know that this is safe,
> > and I would personally not want to rely on it, but we live and
> > learn.
>
> AFAICT this is save and used in other places in the kernel, too. This
> is one of the reasons why you cannot compile the kernel with -O0.
>
> Best regards
> Uwe
>
> --
> Pengutronix e.K. | Uwe Kleine-König |
> Industrial Linux Solutions | https://www.pengutronix.de/ |
next prev parent reply other threads:[~2020-09-28 16:26 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-21 5:48 [Patch v2 1/3] dt-bindings: rtc: pcf2127: Add bindings for nxp,pcf2127 Qiang Zhao
2020-09-21 5:48 ` [Patch v2 2/3] rtc: pcf2127: add "no-watchdog" property Qiang Zhao
2020-09-21 5:48 ` [Patch v2 3/3] arm64: dts: lx2160a: Add "no-watchdog" property to pcf2127 Qiang Zhao
2020-09-23 9:44 ` [Patch v2 1/3] dt-bindings: rtc: pcf2127: Add bindings for nxp,pcf2127 Alexandre Belloni
2020-09-24 3:20 ` Qiang Zhao
2020-09-24 7:04 ` Uwe Kleine-König
2020-09-24 7:23 ` Qiang Zhao
2020-09-24 7:47 ` Alexandre Belloni
2020-09-24 10:52 ` [PATCH 0/2] rtc: pcf2127: only use watchdog when explicitly available Uwe Kleine-König
2020-09-24 10:52 ` [PATCH 1/2] rtc: pcf2127: move watchdog initialisation to a separate function Uwe Kleine-König
2020-09-27 7:50 ` Bruno Thomsen
2020-09-24 10:52 ` [PATCH 2/2] [RFC] rtc: pcf2127: only use watchdog when explicitly available Uwe Kleine-König
2020-09-27 8:09 ` Bruno Thomsen
2020-09-27 15:54 ` Guenter Roeck
2020-09-28 8:43 ` Uwe Kleine-König
2020-09-28 16:26 ` Guenter Roeck [this message]
2020-10-26 7:23 ` [PATCH 0/2] " Qiang Zhao
2020-10-26 20:48 ` Alexandre Belloni
2020-10-26 21:29 ` Guenter Roeck
2020-11-30 9:51 ` Rasmus Villemoes
2020-12-04 9:27 ` Alexandre Belloni
2020-09-24 16:59 ` [Patch v2 1/3] dt-bindings: rtc: pcf2127: Add bindings for nxp,pcf2127 Bruno Thomsen
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=20200928162606.GA106276@roeck-us.net \
--to=linux@roeck-us.net \
--cc=a.zummo@towertech.it \
--cc=alexandre.belloni@bootlin.com \
--cc=bruno.thomsen@gmail.com \
--cc=devicetree@vger.kernel.org \
--cc=kernel@pengutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rtc@vger.kernel.org \
--cc=linux-watchdog@vger.kernel.org \
--cc=qiang.zhao@nxp.com \
--cc=robh+dt@kernel.org \
--cc=u.kleine-koenig@pengutronix.de \
--cc=wim@linux-watchdog.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).