From: Alexandre Belloni <alexandre.belloni@bootlin.com>
To: Jacky Huang <ychuang570808@gmail.com>
Cc: a.zummo@towertech.it, robh+dt@kernel.org,
krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org,
linux-rtc@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org, soc@kernel.org,
mjchen@nuvoton.com, schung@nuvoton.com,
Jacky Huang <ychuang3@nuvoton.com>
Subject: Re: [RESEND PATCH v2 3/3] rtc: Add driver for Nuvoton ma35d1 rtc controller
Date: Wed, 9 Aug 2023 04:12:24 +0200 [thread overview]
Message-ID: <20230809021224ab4f229f@mail.local> (raw)
In-Reply-To: <20230809021025a7c0daec@mail.local>
On 09/08/2023 04:10:27+0200, Alexandre Belloni wrote:
> > +static int ma35d1_rtc_probe(struct platform_device *pdev)
> > +{
> > + struct ma35_rtc *rtc;
> > + struct clk *clk;
> > + u32 regval;
> > + int err;
> > +
> > + rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL);
> > + if (!rtc)
> > + return -ENOMEM;
> > +
> > + rtc->rtc_reg = devm_platform_ioremap_resource(pdev, 0);
> > + if (IS_ERR(rtc->rtc_reg))
> > + return PTR_ERR(rtc->rtc_reg);
> > +
> > + clk = of_clk_get(pdev->dev.of_node, 0);
> > + if (IS_ERR(clk))
> > + return dev_err_probe(&pdev->dev, PTR_ERR(clk), "failed to find rtc clock\n");
> > +
> > + err = clk_prepare_enable(clk);
> > + if (err)
> > + return -ENOENT;
> > +
> > + platform_set_drvdata(pdev, rtc);
> > +
> > + rtc->rtcdev = devm_rtc_device_register(&pdev->dev, pdev->name,
> > + &ma35d1_rtc_ops, THIS_MODULE);
> > + if (IS_ERR(rtc->rtcdev))
> > + return dev_err_probe(&pdev->dev, PTR_ERR(rtc->rtcdev),
> > + "failed to register rtc device\n");
>
> This MUST be done last in probe, else you open a race with userspace.
>
>
> > +
> > + err = ma35d1_rtc_init(rtc, RTC_INIT_TIMEOUT);
> > + if (err)
> > + return err;
> > +
>
> I don't believe you should do this on every probe but only when this
> hasn't been done yet.
>
Also, if you can know that the time has never been set, don't discard
this information, this is crucial information and it needs to be
reported to userspace.
--
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
WARNING: multiple messages have this Message-ID (diff)
From: Alexandre Belloni <alexandre.belloni@bootlin.com>
To: Jacky Huang <ychuang570808@gmail.com>
Cc: a.zummo@towertech.it, robh+dt@kernel.org,
krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org,
linux-rtc@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org, soc@kernel.org,
mjchen@nuvoton.com, schung@nuvoton.com,
Jacky Huang <ychuang3@nuvoton.com>
Subject: Re: [RESEND PATCH v2 3/3] rtc: Add driver for Nuvoton ma35d1 rtc controller
Date: Wed, 9 Aug 2023 04:12:24 +0200 [thread overview]
Message-ID: <20230809021224ab4f229f@mail.local> (raw)
In-Reply-To: <20230809021025a7c0daec@mail.local>
On 09/08/2023 04:10:27+0200, Alexandre Belloni wrote:
> > +static int ma35d1_rtc_probe(struct platform_device *pdev)
> > +{
> > + struct ma35_rtc *rtc;
> > + struct clk *clk;
> > + u32 regval;
> > + int err;
> > +
> > + rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL);
> > + if (!rtc)
> > + return -ENOMEM;
> > +
> > + rtc->rtc_reg = devm_platform_ioremap_resource(pdev, 0);
> > + if (IS_ERR(rtc->rtc_reg))
> > + return PTR_ERR(rtc->rtc_reg);
> > +
> > + clk = of_clk_get(pdev->dev.of_node, 0);
> > + if (IS_ERR(clk))
> > + return dev_err_probe(&pdev->dev, PTR_ERR(clk), "failed to find rtc clock\n");
> > +
> > + err = clk_prepare_enable(clk);
> > + if (err)
> > + return -ENOENT;
> > +
> > + platform_set_drvdata(pdev, rtc);
> > +
> > + rtc->rtcdev = devm_rtc_device_register(&pdev->dev, pdev->name,
> > + &ma35d1_rtc_ops, THIS_MODULE);
> > + if (IS_ERR(rtc->rtcdev))
> > + return dev_err_probe(&pdev->dev, PTR_ERR(rtc->rtcdev),
> > + "failed to register rtc device\n");
>
> This MUST be done last in probe, else you open a race with userspace.
>
>
> > +
> > + err = ma35d1_rtc_init(rtc, RTC_INIT_TIMEOUT);
> > + if (err)
> > + return err;
> > +
>
> I don't believe you should do this on every probe but only when this
> hasn't been done yet.
>
Also, if you can know that the time has never been set, don't discard
this information, this is crucial information and it needs to be
reported to userspace.
--
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2023-08-09 2:12 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-09 1:15 [RESEND PATCH v2 0/3] Add support for Nuvoton ma35d1 rtc controller Jacky Huang
2023-08-09 1:15 ` Jacky Huang
2023-08-09 1:15 ` [RESEND PATCH v2 1/3] dt-bindings: rtc: Add Nuvoton ma35d1 rtc Jacky Huang
2023-08-09 1:15 ` Jacky Huang
2023-08-09 1:15 ` [RESEND PATCH v2 2/3] arm64: dts: nuvoton: Add rtc for ma35d1 Jacky Huang
2023-08-09 1:15 ` Jacky Huang
2023-08-09 1:15 ` [RESEND PATCH v2 3/3] rtc: Add driver for Nuvoton ma35d1 rtc controller Jacky Huang
2023-08-09 1:15 ` Jacky Huang
2023-08-09 2:10 ` Alexandre Belloni
2023-08-09 2:10 ` Alexandre Belloni
2023-08-09 2:12 ` Alexandre Belloni [this message]
2023-08-09 2:12 ` Alexandre Belloni
2023-08-09 8:12 ` Jacky Huang
2023-08-09 8:12 ` Jacky Huang
2023-08-09 22:51 ` Alexandre Belloni
2023-08-09 22:51 ` Alexandre Belloni
2023-08-10 7:21 ` Jacky Huang
2023-08-10 7:21 ` Jacky Huang
2023-08-10 7:30 ` Alexandre Belloni
2023-08-10 7:30 ` Alexandre Belloni
2023-08-10 8:26 ` Jacky Huang
2023-08-10 8:26 ` Jacky Huang
2023-08-12 8:53 ` [RESEND PATCH v2 0/3] Add support " Arnd Bergmann
2023-08-12 8:53 ` Arnd Bergmann
2023-08-13 0:16 ` Jacky Huang
2023-08-13 0:16 ` Jacky Huang
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=20230809021224ab4f229f@mail.local \
--to=alexandre.belloni@bootlin.com \
--cc=a.zummo@towertech.it \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rtc@vger.kernel.org \
--cc=mjchen@nuvoton.com \
--cc=robh+dt@kernel.org \
--cc=schung@nuvoton.com \
--cc=soc@kernel.org \
--cc=ychuang3@nuvoton.com \
--cc=ychuang570808@gmail.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.