[PATCH 3/9] watchdog: w83627hf_wdt: Use private driver data structure
Paul Louvel <[email protected]> Sat, 25 Jul 2026 12:29:30 +0200
| Newsgroups | org.kernel.vger.linux-watchdog,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <[email protected]> |
Allocating a per-device data structure is a common practice in the Linux driver model. Add one that will be used to store chip-specific register offsets, and configuration. Signed-off-by: Paul Louvel <[email protected]> --- drivers/watchdog/w83627hf_wdt.c | 49 ++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/drivers/watchdog/w83627hf_wdt.c b/drivers/watchdog/w83627hf_wdt.c index 993e65ce4447..72e167f37885 100644 --- a/drivers/watchdog/w83627hf_wdt.c +++ b/drivers/watchdog/w83627hf_wdt.c @@ -132,6 +132,11 @@ MODULE_PARM_DESC(early_disable, "Disable watchdog at boot time (default=0)"); struct wdt_pdata {}; +struct w83627hf_data { + struct watchdog_device wdd; + struct watchdog_info info; +}; + static void superio_outb(int reg, int val) { outb(reg, WDT_EFER); @@ -331,10 +336,6 @@ static unsigned int wdt_get_time(struct watchdog_device *wdog) * Kernel Interfaces */ -static struct watchdog_info wdt_info = { - .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE, -}; - static const struct watchdog_ops wdt_ops = { .owner = THIS_MODULE, .start = wdt_start, @@ -343,14 +344,6 @@ static const struct watchdog_ops wdt_ops = { .get_timeleft = wdt_get_time, }; -static struct watchdog_device wdt_dev = { - .info = &wdt_info, - .ops = &wdt_ops, - .timeout = WATCHDOG_TIMEOUT, - .min_timeout = 1, - .max_timeout = 255, -}; - /* * The WDT needs to learn about soft shutdowns in order to * turn the timebomb registers off. @@ -471,28 +464,44 @@ static int wdt_probe(struct platform_device *pdev) { const struct platform_device_id *id = platform_get_device_id(pdev); enum chips chip = id->driver_data; + struct watchdog_device *wdd; + struct w83627hf_data *data; int ret; pr_info("WDT driver for %s Super I/O chip initialising\n", id->name); - snprintf(wdt_info.identity, sizeof(wdt_info.identity), "%s Watchdog", - id->name); + data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + if (!data) + return -ENOMEM; + + data->info.options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE; + snprintf(data->info.identity, sizeof(data->info.identity), + "%s Watchdog", id->name); + + wdd = &data->wdd; + + wdd->info = &data->info; + wdd->ops = &wdt_ops; + wdd->timeout = WATCHDOG_TIMEOUT; + wdd->min_timeout = 1; + wdd->max_timeout = 255; - watchdog_init_timeout(&wdt_dev, timeout, NULL); - watchdog_set_nowayout(&wdt_dev, nowayout); - watchdog_stop_on_reboot(&wdt_dev); + watchdog_set_drvdata(wdd, data); + watchdog_init_timeout(wdd, timeout, NULL); + watchdog_set_nowayout(wdd, nowayout); + watchdog_stop_on_reboot(wdd); - ret = w83627hf_init(&wdt_dev, chip); + ret = w83627hf_init(wdd, chip); if (ret) { pr_err("failed to initialize watchdog (err=%d)\n", ret); return ret; } - ret = devm_watchdog_register_device(&pdev->dev, &wdt_dev); + ret = devm_watchdog_register_device(&pdev->dev, wdd); if (ret) return ret; - pr_info("initialized. timeout=%d sec (nowayout=%d)\n", wdt_dev.timeout, + pr_info("initialized. timeout=%d sec (nowayout=%d)\n", wdd->timeout, nowayout); return ret; -- 2.55.0