Re: [RESEND PATCH v2 3/3] rtc: Add driver for Nuvoton ma35d1 rtc controller

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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



[Index of Archives]     [Device Tree Compilter]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux PCI Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Yosemite Backpacking]


  Powered by Linux