[PATCH v2 3/8] watchdog: w83627hf_wdt: Use private driver data structure
Paul Louvel <[email protected]> Sun, 26 Jul 2026 20:44: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 206ab91fdb2a..38cbc6d14f4c 100644 --- a/drivers/watchdog/w83627hf_wdt.c +++ b/drivers/watchdog/w83627hf_wdt.c @@ -130,6 +130,11 @@ MODULE_PARM_DESC(early_disable, "Disable watchdog at boot time (default=0)"); #define WDT_CTRL_RISING_EDGE_KBD_RESET BIT(2) #define WDT_CTRL_MINUTE_MODE BIT(3) +struct w83627hf_data { + struct watchdog_device wdd; + struct watchdog_info info; +}; + static void superio_outb(int reg, int val) { outb(reg, WDT_EFER); @@ -329,10 +334,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, @@ -341,14 +342,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. @@ -470,27 +463,43 @@ 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 device *dev = &pdev->dev; + struct watchdog_device *wdd; + struct w83627hf_data *data; int ret; dev_info(dev, "WDT driver initialising\n"); - 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) return dev_err_probe(dev, ret, "failed to initialize watchdog\n"); - ret = devm_watchdog_register_device(&pdev->dev, &wdt_dev); + ret = devm_watchdog_register_device(&pdev->dev, wdd); if (ret) return ret; dev_info(dev, "initialized. timeout=%d sec (nowayout=%d)\n", - wdt_dev.timeout, nowayout); + wdd->timeout, nowayout); return ret; } -- 2.55.0