[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <202412161041586ed7c0ff@mail.local>
Date: Mon, 16 Dec 2024 11:41:58 +0100
From: Alexandre Belloni <alexandre.belloni@...tlin.com>
To: Ming Yu <a0282524688@...il.com>
Cc: tmyu0@...oton.com, lee@...nel.org, linus.walleij@...aro.org,
brgl@...ev.pl, andi.shyti@...nel.org, mkl@...gutronix.de,
mailhol.vincent@...adoo.fr, andrew+netdev@...n.ch,
davem@...emloft.net, edumazet@...gle.com, kuba@...nel.org,
pabeni@...hat.com, wim@...ux-watchdog.org, linux@...ck-us.net,
jdelvare@...e.com, linux-kernel@...r.kernel.org,
linux-gpio@...r.kernel.org, linux-i2c@...r.kernel.org,
linux-can@...r.kernel.org, netdev@...r.kernel.org,
linux-watchdog@...r.kernel.org, linux-hwmon@...r.kernel.org,
linux-rtc@...r.kernel.org
Subject: Re: [PATCH v3 7/7] rtc: Add Nuvoton NCT6694 RTC support
On 10/12/2024 18:45:24+0800, Ming Yu wrote:
> +static int nct6694_rtc_probe(struct platform_device *pdev)
> +{
> + struct nct6694_rtc_data *data;
> + struct nct6694 *nct6694 = dev_get_drvdata(pdev->dev.parent);
> + int ret, irq;
> +
> + irq = irq_create_mapping(nct6694->domain, NCT6694_IRQ_RTC);
> + if (!irq)
> + return -EINVAL;
> +
> + data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
> + if (!data)
> + return -ENOMEM;
> +
> + data->xmit_buf = devm_kcalloc(&pdev->dev, NCT6694_MAX_PACKET_SZ,
> + sizeof(unsigned char), GFP_KERNEL);
> + if (!data->xmit_buf)
> + return -ENOMEM;
> +
> + data->rtc = devm_rtc_allocate_device(&pdev->dev);
> + if (IS_ERR(data->rtc))
> + return PTR_ERR(data->rtc);
> +
> + data->nct6694 = nct6694;
> + data->rtc->ops = &nct6694_rtc_ops;
> + data->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000;
> + data->rtc->range_max = RTC_TIMESTAMP_END_2099;
> +
> + mutex_init(&data->lock);
You should use rtc_lock/rtc_unlock instead of having your own lock. The
core will take and release the lock appropriately before calling the
rtc_ops so you only have to do it in the irq handler.
> +
> + device_set_wakeup_capable(&pdev->dev, 1);
This will cause a memory leak later on, see the discussion here:
https://lore.kernel.org/linux-rtc/a88475b6-08bf-4c7c-ad63-efd1f29307e3@pf.is.s.u-tokyo.ac.jp/T/#mf51fdce6036efa3ea12fe75bd5126d4ac0c6813e
> +
> + platform_set_drvdata(pdev, data);
> +
> + ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
> + nct6694_irq, IRQF_ONESHOT,
> + "nct6694-rtc", data);
> + if (ret < 0)
> + return dev_err_probe(&pdev->dev, ret, "Failed to request irq\n");
> +
> + /* Register rtc device to RTC framework */
> + return devm_rtc_register_device(data->rtc);
> +}
> +
> +static struct platform_driver nct6694_rtc_driver = {
> + .driver = {
> + .name = "nct6694-rtc",
> + },
> + .probe = nct6694_rtc_probe,
> +};
> +
> +module_platform_driver(nct6694_rtc_driver);
> +
> +MODULE_DESCRIPTION("USB-RTC driver for NCT6694");
> +MODULE_AUTHOR("Ming Yu <tmyu0@...oton.com>");
> +MODULE_LICENSE("GPL");
> +MODULE_ALIAS("platform:nct6694-rtc");
> --
> 2.34.1
>
--
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
Powered by blists - more mailing lists