* [PATCH 01/10] rtc: rx8025: pass parent I2C device in clock_adjust_ppb sysfs callbacks
2026-11-23 19:59 [PATCH 00/10] rtc: assorted bug fixes across RTC drivers Lee Jones
@ 2026-11-23 19:59 ` Lee Jones
2026-11-23 19:59 ` [PATCH 02/10] rtc: mt6397: handle non-DT platform device matching in probe Lee Jones
` (9 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Lee Jones @ 2026-11-23 19:59 UTC (permalink / raw)
To: lee, Alexandre Belloni, Wolfgang Grandegger, lm-sensors,
Sergei Poselenov, Dmitry Rakhchev, linux-rtc, linux-kernel
Cc: stable
Since rx8025_attr_group was converted to rtc_add_group(), the device
pointer passed to rx8025_sysfs_show_clock_adjust() and
rx8025_sysfs_store_clock_adjust() is the RTC class device (&rtc->dev)
rather than the parent I2C client device. Passing dev directly to
rx8025_read_offset() and rx8025_set_offset() invokes to_i2c_client() on
the RTC class device, causing type confusion and an invalid pointer
dereference during SMBus register access.
Pass dev->parent to rx8025_read_offset() and rx8025_set_offset() so
they operate on the underlying I2C client device.
Fixes: 3d35840dfb75 ("rtc: rx8025: use rtc_add_group")
Closes: https://sashiko.dev/#/bug/linux-39839b9a-7a00-4bdc-8d5a-b28de75dda80
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/rtc/rtc-rx8025.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/rtc/rtc-rx8025.c b/drivers/rtc/rtc-rx8025.c
index 1ccec7b5ae42..ab3a30982863 100644
--- a/drivers/rtc/rtc-rx8025.c
+++ b/drivers/rtc/rtc-rx8025.c
@@ -482,7 +482,7 @@ static ssize_t rx8025_sysfs_show_clock_adjust(struct device *dev,
int err;
dev_warn_once(dev, "clock_adjust_ppb is deprecated, use offset\n");
- err = rx8025_read_offset(dev, &adj);
+ err = rx8025_read_offset(dev->parent, &adj);
if (err)
return err;
@@ -500,7 +500,7 @@ static ssize_t rx8025_sysfs_store_clock_adjust(struct device *dev,
if (kstrtol(buf, 10, &adj) != 0)
return -EINVAL;
- err = rx8025_set_offset(dev, -adj);
+ err = rx8025_set_offset(dev->parent, -adj);
return err ? err : count;
}
--
2.56.1.750.gf70dc682cf-goog
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH 02/10] rtc: mt6397: handle non-DT platform device matching in probe
2026-11-23 19:59 [PATCH 00/10] rtc: assorted bug fixes across RTC drivers Lee Jones
2026-11-23 19:59 ` [PATCH 01/10] rtc: rx8025: pass parent I2C device in clock_adjust_ppb sysfs callbacks Lee Jones
@ 2026-11-23 19:59 ` Lee Jones
2026-11-23 19:59 ` [PATCH 03/10] rtc: ma35d1: allocate RTC device before requesting interrupt Lee Jones
` (8 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Lee Jones @ 2026-11-23 19:59 UTC (permalink / raw)
To: lee, Eddie Huang, Sean Wang, Alexandre Belloni, Matthias Brugger,
AngeloGioacchino Del Regno, Ryan Brue, Tianping.Fang,
Yingjoe Chen, Hsin-Hsiung Wang, Sebastian Reichel,
linux-arm-kernel, linux-mediatek, linux-rtc, linux-kernel
Cc: stable
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@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
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 ab402f9f85c3..c40644ae509a 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.750.gf70dc682cf-goog
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH 03/10] rtc: ma35d1: allocate RTC device before requesting interrupt
2026-11-23 19:59 [PATCH 00/10] rtc: assorted bug fixes across RTC drivers Lee Jones
2026-11-23 19:59 ` [PATCH 01/10] rtc: rx8025: pass parent I2C device in clock_adjust_ppb sysfs callbacks Lee Jones
2026-11-23 19:59 ` [PATCH 02/10] rtc: mt6397: handle non-DT platform device matching in probe Lee Jones
@ 2026-11-23 19:59 ` Lee Jones
2026-11-23 19:59 ` [PATCH 04/10] rtc: mpc5121: get interrupts via platform_get_irq() Lee Jones
` (7 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Lee Jones @ 2026-11-23 19:59 UTC (permalink / raw)
To: lee, Jacky Huang, Shan-Chun Hung, Alexandre Belloni,
Ming-Jen Chen, linux-arm-kernel, linux-rtc, linux-kernel
Cc: stable
ma35d1_rtc_probe() registers ma35d1_rtc_interrupt() via
devm_request_irq() before allocating rtc->rtcdev via
devm_rtc_allocate_device(). During driver unbind or if
devm_rtc_register_device() fails, devres unwinds in reverse order and
frees struct rtc_device in devm_rtc_release_device() before
devm_irq_release() unregisters the interrupt handler. An RTC interrupt
arriving in that teardown window passes a dangling rtc->rtcdev pointer
to rtc_update_irq(), dereferencing freed memory and scheduling a freed
work_struct.
Allocate and initialise rtc->rtcdev before requesting the IRQ so that
devres frees the interrupt handler before releasing the RTC device.
Fixes: dc0684adf3b6 ("rtc: Add driver for Nuvoton ma35d1 rtc controller")
Closes: https://sashiko.dev/#/bug/linux-26674087-baed-4ef2-83a0-78888ea8d16a
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/rtc/rtc-ma35d1.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/drivers/rtc/rtc-ma35d1.c b/drivers/rtc/rtc-ma35d1.c
index eb0da8b091dc..beeef6db92d9 100644
--- a/drivers/rtc/rtc-ma35d1.c
+++ b/drivers/rtc/rtc-ma35d1.c
@@ -235,13 +235,6 @@ static int ma35d1_rtc_probe(struct platform_device *pdev)
return dev_err_probe(&pdev->dev, ret, "rtc init failed\n");
}
- rtc->irq_num = platform_get_irq(pdev, 0);
-
- ret = devm_request_irq(&pdev->dev, rtc->irq_num, ma35d1_rtc_interrupt,
- IRQF_NO_SUSPEND, "ma35d1rtc", rtc);
- if (ret)
- return dev_err_probe(&pdev->dev, ret, "Failed to request rtc irq\n");
-
platform_set_drvdata(pdev, rtc);
device_init_wakeup(&pdev->dev, true);
@@ -254,6 +247,13 @@ static int ma35d1_rtc_probe(struct platform_device *pdev)
rtc->rtcdev->range_min = RTC_TIMESTAMP_BEGIN_2000;
rtc->rtcdev->range_max = RTC_TIMESTAMP_END_2099;
+ rtc->irq_num = platform_get_irq(pdev, 0);
+
+ ret = devm_request_irq(&pdev->dev, rtc->irq_num, ma35d1_rtc_interrupt,
+ IRQF_NO_SUSPEND, "ma35d1rtc", rtc);
+ if (ret)
+ return dev_err_probe(&pdev->dev, ret, "Failed to request rtc irq\n");
+
ret = devm_rtc_register_device(rtc->rtcdev);
if (ret)
return dev_err_probe(&pdev->dev, ret, "Failed to register rtc device\n");
--
2.56.1.750.gf70dc682cf-goog
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH 04/10] rtc: mpc5121: get interrupts via platform_get_irq()
2026-11-23 19:59 [PATCH 00/10] rtc: assorted bug fixes across RTC drivers Lee Jones
` (2 preceding siblings ...)
2026-11-23 19:59 ` [PATCH 03/10] rtc: ma35d1: allocate RTC device before requesting interrupt Lee Jones
@ 2026-11-23 19:59 ` Lee Jones
2026-11-23 19:59 ` [PATCH 05/10] rtc: m41t80: use devm helpers for square-wave clock registration Lee Jones
` (6 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Lee Jones @ 2026-11-23 19:59 UTC (permalink / raw)
To: lee, Alexandre Belloni, Domen Puncer, John Rigby, linux-rtc,
linux-kernel
Cc: stable
mpc5121_rtc_probe() maps its interrupts with irq_of_parse_and_map() and
requests them via devm_request_irq(), while the probe error paths and
mpc5121_rtc_remove() explicitly call irq_dispose_mapping(). This tears
down and frees the IRQ descriptors before devres runs free_irq(),
operating on destroyed IRQ descriptors and leaking irqaction entries.
It also passes IRQ 0 to devm_request_irq() when irq_of_parse_and_map()
fails.
Obtain both interrupts via platform_get_irq(), propagate negative error
codes directly, and drop the manual irq_dispose_mapping() calls.
Fixes: d53d4ae981d0 ("rtc: mpc5121: simplify probe")
Closes: https://sashiko.dev/#/bug/linux-3fc27b53-f5d6-493d-a3c3-2af748b44f7e
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/rtc/rtc-mpc5121.c | 41 ++++++++++++++-------------------------
1 file changed, 15 insertions(+), 26 deletions(-)
diff --git a/drivers/rtc/rtc-mpc5121.c b/drivers/rtc/rtc-mpc5121.c
index e1cef77c1a0e..331851378e8a 100644
--- a/drivers/rtc/rtc-mpc5121.c
+++ b/drivers/rtc/rtc-mpc5121.c
@@ -11,7 +11,6 @@
#include <linux/module.h>
#include <linux/rtc.h>
#include <linux/of.h>
-#include <linux/of_irq.h>
#include <linux/platform_device.h>
#include <linux/io.h>
#include <linux/slab.h>
@@ -72,8 +71,8 @@ struct mpc5121_rtc_regs {
};
struct mpc5121_rtc_data {
- unsigned irq;
- unsigned irq_periodic;
+ int irq;
+ int irq_periodic;
struct mpc5121_rtc_regs __iomem *regs;
struct rtc_device *rtc;
struct rtc_wkalrm wkalarm;
@@ -307,30 +306,34 @@ static int mpc5121_rtc_probe(struct platform_device *op)
platform_set_drvdata(op, rtc);
- rtc->irq = irq_of_parse_and_map(op->dev.of_node, 1);
+ rtc->irq = platform_get_irq(op, 1);
+ if (rtc->irq < 0)
+ return rtc->irq;
+
err = devm_request_irq(&op->dev, rtc->irq, mpc5121_rtc_handler, 0,
"mpc5121-rtc", &op->dev);
if (err) {
dev_err(&op->dev, "%s: could not request irq: %i\n",
__func__, rtc->irq);
- goto out_dispose;
+ return err;
}
- rtc->irq_periodic = irq_of_parse_and_map(op->dev.of_node, 0);
+ rtc->irq_periodic = platform_get_irq(op, 0);
+ if (rtc->irq_periodic < 0)
+ return rtc->irq_periodic;
+
err = devm_request_irq(&op->dev, rtc->irq_periodic,
mpc5121_rtc_handler_upd, 0, "mpc5121-rtc_upd",
&op->dev);
if (err) {
dev_err(&op->dev, "%s: could not request irq: %i\n",
__func__, rtc->irq_periodic);
- goto out_dispose2;
+ return err;
}
rtc->rtc = devm_rtc_allocate_device(&op->dev);
- if (IS_ERR(rtc->rtc)) {
- err = PTR_ERR(rtc->rtc);
- goto out_dispose2;
- }
+ if (IS_ERR(rtc->rtc))
+ return PTR_ERR(rtc->rtc);
rtc->rtc->ops = &mpc5200_rtc_ops;
set_bit(RTC_FEATURE_ALARM_RES_MINUTE, rtc->rtc->features);
@@ -356,18 +359,7 @@ static int mpc5121_rtc_probe(struct platform_device *op)
rtc->rtc->range_max = U32_MAX;
}
- err = devm_rtc_register_device(rtc->rtc);
- if (err)
- goto out_dispose2;
-
- return 0;
-
-out_dispose2:
- irq_dispose_mapping(rtc->irq_periodic);
-out_dispose:
- irq_dispose_mapping(rtc->irq);
-
- return err;
+ return devm_rtc_register_device(rtc->rtc);
}
static void mpc5121_rtc_remove(struct platform_device *op)
@@ -378,9 +370,6 @@ static void mpc5121_rtc_remove(struct platform_device *op)
/* disable interrupt, so there are no nasty surprises */
out_8(®s->alm_enable, 0);
out_8(®s->int_enable, in_8(®s->int_enable) & ~0x1);
-
- irq_dispose_mapping(rtc->irq);
- irq_dispose_mapping(rtc->irq_periodic);
}
#ifdef CONFIG_OF
--
2.56.1.750.gf70dc682cf-goog
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH 05/10] rtc: m41t80: use devm helpers for square-wave clock registration
2026-11-23 19:59 [PATCH 00/10] rtc: assorted bug fixes across RTC drivers Lee Jones
` (3 preceding siblings ...)
2026-11-23 19:59 ` [PATCH 04/10] rtc: mpc5121: get interrupts via platform_get_irq() Lee Jones
@ 2026-11-23 19:59 ` Lee Jones
2026-11-23 19:59 ` [PATCH 06/10] rtc: nct3018y: fix clock provider use-after-free and leak on unbind Lee Jones
` (5 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Lee Jones @ 2026-11-23 19:59 UTC (permalink / raw)
To: lee, Alexandre Belloni, Alexander Bigga, Mark A. Greer,
Gary Bisson, linux-rtc, linux-kernel
Cc: stable
m41t80_sqw_register_clk() registers m41t80->sqw and its OF clock
provider using unmanaged clk_register() and of_clk_add_provider(), and
neither probe failure nor driver unbind unregisters them. Because
m41t80->sqw is embedded inside the devm-allocated m41t80_data
structure, unbinding the device or failing devm_rtc_register_device()
frees m41t80_data while leaving the clock and OF provider registered,
causing a resource leak and a use-after-free when clock callbacks or
debugfs clk_summary access sqw_to_m41t80_data().
Use devm_clk_register() and devm_of_clk_add_hw_provider() tied to the
I2C client device so both the provider and clock are automatically
unregistered before m41t80_data is freed.
Fixes: 1373e77b4f10 ("rtc: m41t80: add clock provider support")
Closes: https://sashiko.dev/#/bug/linux-4d3dfb5c-0f65-4bb5-94e8-653bc0543df5
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/rtc/rtc-m41t80.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/rtc/rtc-m41t80.c b/drivers/rtc/rtc-m41t80.c
index cfab27aaa518..5f8d6dcdeb5b 100644
--- a/drivers/rtc/rtc-m41t80.c
+++ b/drivers/rtc/rtc-m41t80.c
@@ -604,9 +604,10 @@ static struct clk *m41t80_sqw_register_clk(struct m41t80_data *m41t80)
of_property_read_string(node, "clock-output-names", &init.name);
/* register the clock */
- clk = clk_register(&client->dev, &m41t80->sqw);
+ clk = devm_clk_register(&client->dev, &m41t80->sqw);
if (!IS_ERR(clk))
- of_clk_add_provider(node, of_clk_src_simple_get, clk);
+ devm_of_clk_add_hw_provider(&client->dev, of_clk_hw_simple_get,
+ &m41t80->sqw);
return clk;
}
--
2.56.1.750.gf70dc682cf-goog
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH 06/10] rtc: nct3018y: fix clock provider use-after-free and leak on unbind
2026-11-23 19:59 [PATCH 00/10] rtc: assorted bug fixes across RTC drivers Lee Jones
` (4 preceding siblings ...)
2026-11-23 19:59 ` [PATCH 05/10] rtc: m41t80: use devm helpers for square-wave clock registration Lee Jones
@ 2026-11-23 19:59 ` Lee Jones
2026-11-23 19:59 ` [PATCH 07/10] rtc: stmp3xxx: unregister child watchdog platform device " Lee Jones
` (4 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Lee Jones @ 2026-11-23 19:59 UTC (permalink / raw)
To: lee, Andrew Jeffery, Avi Fishman, Tomer Maimon, Tali Perry,
Patrick Venture, Nancy Yuen, Benjamin Fair, Alexandre Belloni,
Eric Liu, Medad CChien, Mia Lin, openbmc, linux-rtc, linux-kernel
Cc: stable
nct3018y_clkout_register_clk() registers the CLKOUT clock via
devm_clk_register() but adds the OF clock provider with unmanaged
of_clk_add_provider() and never removes it. When the driver unbinds or
devm_rtc_register_device() fails, devres unregisters and frees struct
clk and nct3018y state while leaving a dangling pointer on the global
of_clk_providers list, leaking the provider entry and OF node reference
and causing a use-after-free on subsequent clock lookups.
Use devm_of_clk_add_hw_provider() so the OF clock provider is removed
automatically before the clock and driver state are released.
Fixes: 5adbaed16cc6 ("rtc: Add NCT3018Y real time clock driver")
Closes: https://sashiko.dev/#/bug/linux-9509654b-12c7-4bd1-b189-f52692af9457
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/rtc/rtc-nct3018y.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/rtc/rtc-nct3018y.c b/drivers/rtc/rtc-nct3018y.c
index c770450e48b4..8349ddd1a9d6 100644
--- a/drivers/rtc/rtc-nct3018y.c
+++ b/drivers/rtc/rtc-nct3018y.c
@@ -479,7 +479,8 @@ static struct clk *nct3018y_clkout_register_clk(struct nct3018y *nct3018y)
clk = devm_clk_register(&client->dev, &nct3018y->clkout_hw);
if (!IS_ERR(clk))
- of_clk_add_provider(node, of_clk_src_simple_get, clk);
+ devm_of_clk_add_hw_provider(&client->dev, of_clk_hw_simple_get,
+ &nct3018y->clkout_hw);
return clk;
}
--
2.56.1.750.gf70dc682cf-goog
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH 07/10] rtc: stmp3xxx: unregister child watchdog platform device on unbind
2026-11-23 19:59 [PATCH 00/10] rtc: assorted bug fixes across RTC drivers Lee Jones
` (5 preceding siblings ...)
2026-11-23 19:59 ` [PATCH 06/10] rtc: nct3018y: fix clock provider use-after-free and leak on unbind Lee Jones
@ 2026-11-23 19:59 ` Lee Jones
2026-11-23 19:59 ` [PATCH 08/10] rtc: ds1685: check driver data for NULL in ds1685_rtc_poweroff() Lee Jones
` (3 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Lee Jones @ 2026-11-23 19:59 UTC (permalink / raw)
To: lee, Alexandre Belloni, Maxime Coquelin, Alexandre Torgue,
Peter Hartley, dmitry pervushin, Wolfram Sang, Andrew Morton,
Wim Van Sebroeck, linux-rtc, linux-stm32, linux-arm-kernel,
linux-kernel
Cc: stable
stmp3xxx_wdt_register() creates and registers the child
"stmp3xxx_rtc_wdt" platform device without tracking or unregistering it
when the parent RTC driver unbinds, and also assigns static wdt_pdata
directly to dev.platform_data where platform_device_release() passes it
to kfree(). After unbind, devres unmaps rtc_data->io and frees
rtc_data while the parent drvdata is cleared, so subsequent watchdog
operations or reboot notifications invoking stmp3xxx_wdt_set_timeout()
dereference torn-down parent state.
Register the child platform device via platform_device_register_data()
so its platform data is heap-allocated, and tie
platform_device_unregister() to the parent device with
devm_add_action_or_reset() so the watchdog device is torn down before
parent resources are released.
Fixes: 1a71fb84fda6 ("rtc: stmp3xxx: add wdt-accessor function")
Closes: https://sashiko.dev/#/bug/linux-4ddbfe9c-a03c-4a01-a3ce-357545121630
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/rtc/rtc-stmp3xxx.c | 29 +++++++++++++++++------------
1 file changed, 17 insertions(+), 12 deletions(-)
diff --git a/drivers/rtc/rtc-stmp3xxx.c b/drivers/rtc/rtc-stmp3xxx.c
index d79e282e3817..a5281b519540 100644
--- a/drivers/rtc/rtc-stmp3xxx.c
+++ b/drivers/rtc/rtc-stmp3xxx.c
@@ -92,24 +92,29 @@ static void stmp3xxx_wdt_set_timeout(struct device *dev, u32 timeout)
}
}
-static struct stmp3xxx_wdt_pdata wdt_pdata = {
+static const struct stmp3xxx_wdt_pdata wdt_pdata = {
.wdt_set_timeout = stmp3xxx_wdt_set_timeout,
};
+static void stmp3xxx_wdt_unregister(void *data)
+{
+ platform_device_unregister(data);
+}
+
static void stmp3xxx_wdt_register(struct platform_device *rtc_pdev)
{
- int rc = -1;
- struct platform_device *wdt_pdev =
- platform_device_alloc("stmp3xxx_rtc_wdt", rtc_pdev->id);
-
- if (wdt_pdev) {
- wdt_pdev->dev.parent = &rtc_pdev->dev;
- wdt_pdev->dev.platform_data = &wdt_pdata;
- rc = platform_device_add(wdt_pdev);
- if (rc)
- platform_device_put(wdt_pdev);
- }
+ struct platform_device *wdt_pdev;
+ int rc;
+ wdt_pdev = platform_device_register_data(&rtc_pdev->dev,
+ "stmp3xxx_rtc_wdt",
+ rtc_pdev->id, &wdt_pdata,
+ sizeof(wdt_pdata));
+ rc = PTR_ERR_OR_ZERO(wdt_pdev);
+ if (!rc)
+ rc = devm_add_action_or_reset(&rtc_pdev->dev,
+ stmp3xxx_wdt_unregister,
+ wdt_pdev);
if (rc)
dev_err(&rtc_pdev->dev,
"failed to register stmp3xxx_rtc_wdt\n");
--
2.56.1.750.gf70dc682cf-goog
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH 08/10] rtc: ds1685: check driver data for NULL in ds1685_rtc_poweroff()
2026-11-23 19:59 [PATCH 00/10] rtc: assorted bug fixes across RTC drivers Lee Jones
` (6 preceding siblings ...)
2026-11-23 19:59 ` [PATCH 07/10] rtc: stmp3xxx: unregister child watchdog platform device " Lee Jones
@ 2026-11-23 19:59 ` Lee Jones
2026-11-23 19:59 ` [PATCH 09/10] rtc: omap: prevent NULL and dangling pointer dereferences in power-off path Lee Jones
` (2 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Lee Jones @ 2026-11-23 19:59 UTC (permalink / raw)
To: lee, Joshua Kinard, Alexandre Belloni, Imre Kaloz, Matthias Fuchs,
Andrew Morton, linux-rtc, linux-kernel
Cc: stable
ip32_poweroff() invokes ds1685_rtc_poweroff() with the static
ip32_rtc_device platform device. If ds1685_rtc_probe() previously
failed or the device was unbound, platform_get_drvdata() returns NULL
even though pdev is non-NULL, causing a NULL pointer dereference at
rtc->irq_num instead of entering the intended fallback spin loop.
Verify that platform_get_drvdata() is non-NULL alongside pdev before
dereferencing rtc.
Fixes: aaaf5fbf56f1 ("rtc: add driver for DS1685 family of real time clocks")
Closes: https://sashiko.dev/#/bug/linux-0a1838c9-65d2-4d1c-bc21-35a6a2582144
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/rtc/rtc-ds1685.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/drivers/rtc/rtc-ds1685.c b/drivers/rtc/rtc-ds1685.c
index f27d6ae4f783..c577adf8414d 100644
--- a/drivers/rtc/rtc-ds1685.c
+++ b/drivers/rtc/rtc-ds1685.c
@@ -1370,14 +1370,12 @@ ds1685_rtc_poweroff(struct platform_device *pdev)
struct ds1685_priv *rtc;
/* Check for valid RTC data, else, spin forever. */
- if (unlikely(!pdev)) {
+ rtc = pdev ? platform_get_drvdata(pdev) : NULL;
+ if (unlikely(!rtc)) {
pr_emerg("platform device data not available, spinning forever ...\n");
while(1);
unreachable();
} else {
- /* Get the rtc data. */
- rtc = platform_get_drvdata(pdev);
-
/*
* Disable our IRQ. We're powering down, so we're not
* going to worry about cleaning up. Most of that should
--
2.56.1.750.gf70dc682cf-goog
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH 09/10] rtc: omap: prevent NULL and dangling pointer dereferences in power-off path
2026-11-23 19:59 [PATCH 00/10] rtc: assorted bug fixes across RTC drivers Lee Jones
` (7 preceding siblings ...)
2026-11-23 19:59 ` [PATCH 08/10] rtc: ds1685: check driver data for NULL in ds1685_rtc_poweroff() Lee Jones
@ 2026-11-23 19:59 ` Lee Jones
2026-11-23 19:59 ` [PATCH 10/10] rtc: bq32k: use u8 register buffer in trickle_charge_bypass sysfs Lee Jones
2026-11-23 20:16 ` [PATCH 00/10] rtc: assorted bug fixes across RTC drivers sashiko-bot
10 siblings, 0 replies; 12+ messages in thread
From: Lee Jones @ 2026-11-23 19:59 UTC (permalink / raw)
To: lee, Alexandre Belloni, Nishanth Menon, George G. Davis, or,
Johan Hovold, Andrew Morton, linux-rtc, linux-kernel
Cc: stable
omap_rtc_remove() only clears the global omap_rtc_power_off_rtc pointer
if pm_power_off still equals omap_rtc_power_off. If another driver
overwrote pm_power_off after probe, unbinding the RTC leaves
omap_rtc_power_off_rtc pointing to freed memory. Furthermore,
omap_rtc_power_off_program() is exported and called directly from
am33xx_rtc_only_idle() during suspend without checking whether
omap_rtc_power_off_rtc is NULL, causing a NULL pointer dereference if
omap_rtc_power_off_rtc was never assigned or was cleared on unbind.
Always clear omap_rtc_power_off_rtc when removing the matching RTC
instance, and return -ENODEV from omap_rtc_power_off_program() when
omap_rtc_power_off_rtc is NULL.
Fixes: 222a12fca604 ("rtc: omap: add support for pmic_power_en")
Closes: https://sashiko.dev/#/bug/linux-97b795c5-f68f-4228-948f-547a106c6775
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/rtc/rtc-omap.c | 21 +++++++++++++--------
1 file changed, 13 insertions(+), 8 deletions(-)
diff --git a/drivers/rtc/rtc-omap.c b/drivers/rtc/rtc-omap.c
index 3c978edd6c2c..156444fab916 100644
--- a/drivers/rtc/rtc-omap.c
+++ b/drivers/rtc/rtc-omap.c
@@ -416,6 +416,9 @@ int omap_rtc_power_off_program(void)
int seconds;
u32 val;
+ if (!rtc)
+ return -ENODEV;
+
rtc->type->unlock(rtc);
/* enable pmic_power_en control */
val = rtc_readl(rtc, OMAP_RTC_PMIC_REG);
@@ -481,17 +484,19 @@ EXPORT_SYMBOL(omap_rtc_power_off_program);
*/
static void omap_rtc_power_off(void)
{
+ struct omap_rtc *rtc = omap_rtc_power_off_rtc;
u32 val;
- omap_rtc_power_off_program();
+ if (omap_rtc_power_off_program())
+ return;
/* Set PMIC power enable and EXT_WAKEUP in case PB power on is used */
- omap_rtc_power_off_rtc->type->unlock(omap_rtc_power_off_rtc);
- val = rtc_readl(omap_rtc_power_off_rtc, OMAP_RTC_PMIC_REG);
+ rtc->type->unlock(rtc);
+ val = rtc_readl(rtc, OMAP_RTC_PMIC_REG);
val |= OMAP_RTC_PMIC_POWER_EN_EN | OMAP_RTC_PMIC_EXT_WKUP_POL(0) |
OMAP_RTC_PMIC_EXT_WKUP_EN(0);
- rtc_writel(omap_rtc_power_off_rtc, OMAP_RTC_PMIC_REG, val);
- omap_rtc_power_off_rtc->type->lock(omap_rtc_power_off_rtc);
+ rtc_writel(rtc, OMAP_RTC_PMIC_REG, val);
+ rtc->type->lock(rtc);
/*
* Wait for alarm to trigger (within one second) and external PMIC to
@@ -913,9 +918,9 @@ static void omap_rtc_remove(struct platform_device *pdev)
struct omap_rtc *rtc = platform_get_drvdata(pdev);
u8 reg;
- if (pm_power_off == omap_rtc_power_off &&
- omap_rtc_power_off_rtc == rtc) {
- pm_power_off = NULL;
+ if (omap_rtc_power_off_rtc == rtc) {
+ if (pm_power_off == omap_rtc_power_off)
+ pm_power_off = NULL;
omap_rtc_power_off_rtc = NULL;
}
--
2.56.1.750.gf70dc682cf-goog
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH 10/10] rtc: bq32k: use u8 register buffer in trickle_charge_bypass sysfs
2026-11-23 19:59 [PATCH 00/10] rtc: assorted bug fixes across RTC drivers Lee Jones
` (8 preceding siblings ...)
2026-11-23 19:59 ` [PATCH 09/10] rtc: omap: prevent NULL and dangling pointer dereferences in power-off path Lee Jones
@ 2026-11-23 19:59 ` Lee Jones
2026-11-23 20:16 ` [PATCH 00/10] rtc: assorted bug fixes across RTC drivers sashiko-bot
10 siblings, 0 replies; 12+ messages in thread
From: Lee Jones @ 2026-11-23 19:59 UTC (permalink / raw)
To: lee, Alexandre Belloni, Adriana Stancu, Pavel Machek,
Piotr Ziecik, Enric Balletbo i Serra, linux-rtc, linux-kernel
Cc: stable
bq32k_sysfs_show_tricklecharge_bypass() and
bq32k_sysfs_store_tricklecharge_bypass() pass an uninitialised int to
1-byte bq32k_read() and bq32k_write() transfers. This leaves three
bytes of reg uninitialised on the stack, and on big-endian systems
populates the most significant byte while bitwise operations with
BQ32K_TCFE inspect and modify the uninitialised least significant byte,
leaking a bit of stack memory on reads and failing to update the
hardware register on writes.
Declare reg as u8 in both callbacks.
Fixes: 4c466872d8ae ("rtc: bq32000: add support to enable disable the trickle charge FET bypass")
Closes: https://sashiko.dev/#/bug/linux-1ab3635e-98ec-4ca3-a4d3-58033a48c44d
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/rtc/rtc-bq32k.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/rtc/rtc-bq32k.c b/drivers/rtc/rtc-bq32k.c
index 0f50cfce88cb..7e5080eeee3a 100644
--- a/drivers/rtc/rtc-bq32k.c
+++ b/drivers/rtc/rtc-bq32k.c
@@ -204,7 +204,8 @@ static ssize_t bq32k_sysfs_show_tricklecharge_bypass(struct device *dev,
struct device_attribute *attr,
char *buf)
{
- int reg, error;
+ u8 reg;
+ int error;
error = bq32k_read(dev, ®, BQ32K_CFG2, 1);
if (error)
@@ -217,7 +218,8 @@ static ssize_t bq32k_sysfs_store_tricklecharge_bypass(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
- int reg, enable, error;
+ int enable, error;
+ u8 reg;
if (kstrtoint(buf, 0, &enable))
return -EINVAL;
--
2.56.1.750.gf70dc682cf-goog
^ permalink raw reply related [flat|nested] 12+ messages in thread* Re: [PATCH 00/10] rtc: assorted bug fixes across RTC drivers
2026-11-23 19:59 [PATCH 00/10] rtc: assorted bug fixes across RTC drivers Lee Jones
` (9 preceding siblings ...)
2026-11-23 19:59 ` [PATCH 10/10] rtc: bq32k: use u8 register buffer in trickle_charge_bypass sysfs Lee Jones
@ 2026-11-23 20:16 ` sashiko-bot
10 siblings, 0 replies; 12+ messages in thread
From: sashiko-bot @ 2026-11-23 20:16 UTC (permalink / raw)
To: Lee Jones; +Cc: linux-rtc, Alexandre Belloni
Sashiko has reviewed this 10-patch series and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261123200012.502284-1-lee@kernel.org
^ permalink raw reply [flat|nested] 12+ messages in thread