Skip to content

Commit 87b2265

Browse files
morbidrsaWim Van Sebroeck
authored andcommitted
watchdog: menz069_wdt: fix watchdog initialisation
Doing a 'cat /dev/watchdog0' with menz069_wdt as watchdog0 will result in a NULL pointer dereference. This happens because we're passing the wrong pointer to watchdog_register_device(). Fix this by getting rid of the static watchdog_device structure and use the one embedded into the driver's per-instance private data. Signed-off-by: Johannes Thumshirn <jth@kernel.org> Reviewed-by: Guenter Roeck <linux@roeck-us.net> Link: https://lore.kernel.org/r/20230418172531.177349-2-jth@kernel.org Signed-off-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Wim Van Sebroeck <wim@linux-watchdog.org>
1 parent a23c83a commit 87b2265

1 file changed

Lines changed: 6 additions & 10 deletions

File tree

drivers/watchdog/menz69_wdt.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,6 @@ static const struct watchdog_ops men_z069_ops = {
9898
.set_timeout = men_z069_wdt_set_timeout,
9999
};
100100

101-
static struct watchdog_device men_z069_wdt = {
102-
.info = &men_z069_info,
103-
.ops = &men_z069_ops,
104-
.timeout = MEN_Z069_DEFAULT_TIMEOUT,
105-
.min_timeout = 1,
106-
.max_timeout = MEN_Z069_WDT_COUNTER_MAX / MEN_Z069_TIMER_FREQ,
107-
};
108-
109101
static int men_z069_probe(struct mcb_device *dev,
110102
const struct mcb_device_id *id)
111103
{
@@ -125,15 +117,19 @@ static int men_z069_probe(struct mcb_device *dev,
125117
goto release_mem;
126118

127119
drv->mem = mem;
120+
drv->wdt.info = &men_z069_info;
121+
drv->wdt.ops = &men_z069_ops;
122+
drv->wdt.timeout = MEN_Z069_DEFAULT_TIMEOUT;
123+
drv->wdt.min_timeout = 1;
124+
drv->wdt.max_timeout = MEN_Z069_WDT_COUNTER_MAX / MEN_Z069_TIMER_FREQ;
128125

129-
drv->wdt = men_z069_wdt;
130126
watchdog_init_timeout(&drv->wdt, 0, &dev->dev);
131127
watchdog_set_nowayout(&drv->wdt, nowayout);
132128
watchdog_set_drvdata(&drv->wdt, drv);
133129
drv->wdt.parent = &dev->dev;
134130
mcb_set_drvdata(dev, drv);
135131

136-
return watchdog_register_device(&men_z069_wdt);
132+
return watchdog_register_device(&drv->wdt);
137133

138134
release_mem:
139135
mcb_release_mem(mem);

0 commit comments

Comments
 (0)