Re: [PATCH v1] rtc: m41t80: clean up watchdog on probe failure

From: 최유호

Date: Sun Jun 28 2026 - 11:41:46 EST


On Fri, 26 Jun 2026 at 20:33, Alexandre Mergnat <amergnat@xxxxxxxxxxxx> wrote:
> IMHO the right fix is to move the watchdog to the watchdog core.
>
> The leak comes from the watchdog being built on three non-devres
> save_client. A probe failure strands all three, after which the watchdog
> dereferences freed driver state (wdt_ping() reads
> i2c_get_clientdata(save_client), i.e. the devres-freed m41t80_data).
>
> Built on the watchdog core (CONFIG_WATCHDOG_CORE), none of that
> machinery is needed:
>
> - devm_watchdog_register_device() unregisters automatically on any probe
> failure and on unbind.
> - watchdog_stop_on_reboot() replaces the reboot notifier.
> - watchdog_set/get_drvdata() replaces the global save_client, closing
> the use-after-free surface itself.
> - m41t80_remove() does nothing but watchdog teardown today, so it goes
> away too.
>
> This is exactly what was done for the sibling driver rtc-ds1374, which
> carried the same legacy pattern: d3de4beb14a8 ("rtc: ds1374: wdt: Use
> watchdog core for watchdog part"), net -135 lines, adding "select
> WATCHDOG_CORE" in Kconfig. It is a usable template.
>
> primitives: a misc device, a reboot notifier, and the global

Thanks for the detailed suggestion, Alexandre.

Moving to the watchdog core sounds like a better approach. I will
rework this based on the rtc-ds1374 example and send v2.

Thanks,
Yuho