[PATCH v2 02/10] rtc: mt6397: handle non-DT platform device matching in probe

From: Lee Jones

Date: Wed Dec 02 2026 - 15:22:57 EST


The parent MediaTek PMIC MFD driver instantiates RTC platform
subdevices even when the optional RTC child Device Tree node is omitted,
and devices can also be bound via sysfs driver_override. In those
cases, of_device_get_match_data() returns NULL, yet mtk_rtc_probe()
succeeds with rtc->data left NULL and mtk_rtc_write_trigger()
subsequently crashes when dereferencing rtc->data->wrtgr.

Provide a platform_device_id table covering the MediaTek PMIC RTC cells
and fall back to platform_get_device_id() when no OF match data is
present, returning -ENODEV if neither match path provides driver data.

Fixes: 29ee40091e27 ("rtc: mt6397: Add support for the MediaTek MT6358 RTC")
Closes: https://sashiko.dev/#/bug/linux-35993d35-d776-4f86-9bd2-42c6ee078f88
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Lee Jones <lee@xxxxxxxxxx>
---

v1 => v2:
- No changes

Cc: "Tianping.Fang" <tianping.fang@xxxxxxxxxxxx>
Cc: Alexandre Belloni <alexandre.belloni@xxxxxxxxxxx>
Cc: AngeloGioacchino Del Regno <angelogioacchino.delregno@xxxxxxxxxxxxx>
Cc: Eddie Huang <eddie.huang@xxxxxxxxxxxx>
Cc: linux-arm-kernel@xxxxxxxxxxxxxxxxxxx
Cc: linux-mediatek@xxxxxxxxxxxxxxxxxxx
Cc: linux-rtc@xxxxxxxxxxxxxxx
Cc: Matthias Brugger <matthias.bgg@xxxxxxxxx>
Cc: Ran Bi <ran.bi@xxxxxxxxxxxx>
Cc: Ryan Brue <ryanbrue.dev@xxxxxxxxx>
Cc: Sean Wang <sean.wang@xxxxxxxxxxxx>
Cc: Sebastian Reichel <sre@xxxxxxxxxx>
Cc: Yingjoe Chen <yingjoe.chen@xxxxxxxxxxxx>

drivers/rtc/rtc-mt6397.c | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)

diff --git a/drivers/rtc/rtc-mt6397.c b/drivers/rtc/rtc-mt6397.c
index d6e156516aa6..248073b22a3e 100644
--- a/drivers/rtc/rtc-mt6397.c
+++ b/drivers/rtc/rtc-mt6397.c
@@ -343,6 +343,14 @@ static int mtk_rtc_probe(struct platform_device *pdev)
rtc->addr_base = res->start;

rtc->data = of_device_get_match_data(&pdev->dev);
+ if (!rtc->data) {
+ const struct platform_device_id *id = platform_get_device_id(pdev);
+
+ if (!id)
+ return -ENODEV;
+
+ rtc->data = (const struct mtk_rtc_data *)id->driver_data;
+ }

rtc->irq = platform_get_irq(pdev, 0);
if (rtc->irq < 0)
@@ -427,6 +435,16 @@ static const struct of_device_id mt6397_rtc_of_match[] = {
};
MODULE_DEVICE_TABLE(of, mt6397_rtc_of_match);

+static const struct platform_device_id mt6397_rtc_id[] = {
+ { "mt6323-rtc", (kernel_ulong_t)&mt6397_rtc_data },
+ { "mt6357-rtc", (kernel_ulong_t)&mt6358_rtc_data },
+ { "mt6358-rtc", (kernel_ulong_t)&mt6358_rtc_data },
+ { "mt6359-rtc", (kernel_ulong_t)&mt6358_rtc_data },
+ { "mt6397-rtc", (kernel_ulong_t)&mt6397_rtc_data },
+ { }
+};
+MODULE_DEVICE_TABLE(platform, mt6397_rtc_id);
+
static struct platform_driver mtk_rtc_driver = {
.driver = {
.name = "mt6397-rtc",
@@ -434,6 +452,7 @@ static struct platform_driver mtk_rtc_driver = {
.pm = &mt6397_pm_ops,
},
.probe = mtk_rtc_probe,
+ .id_table = mt6397_rtc_id,
};

module_platform_driver(mtk_rtc_driver);
--
2.56.1.911.g883d8bcb20-goog