Skip to contentSkip to conversation

watchdog: imgpdc: Runtime fixes

PATCH In review James Hogan 4 participants 10 messages Feb 20, 2015 – Mar 24, 2015 Watchdog device drivers

lore
Share & tools
lore
#0 lore raw

cover watchdog: imgpdc: Runtime fixes

A couple of basic runtime fixes for the IMG PDC watchdog driver. These were found by attempting to enable the driver for TZ1090 and running under Meta QEMU. Note that QEMU doesn't emulate the actual watchdog functionality beyond the soft reset register, so I cannot claim to have tested the driver's watchdog timer functionality yet.

James Hogan (2):
watchdog: imgpdc: Fix probe NULL pointer dereference
watchdog: imgpdc: Fix default heartbeat

 drivers/watchdog/imgpdc_wdt.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
Cc Wim Van Sebroeck <[email protected]>
Cc Ezequiel Garcia <[email protected]>
Cc Naidu Tellapati <[email protected]>
Cc Jude Abraham <[email protected]>
Signature · 1 line
2.0.5
#1 lore raw

PATCH 1/2 watchdog: imgpdc: Fix probe NULL pointer dereference

The IMG PDC watchdog probe function calls pdc_wdt_stop() prior to watchdog_set_drvdata(), causing a NULL pointer dereference when pdc_wdt_stop() retrieves the struct pdc_wdt_dev pointer using watchdog_get_drvdata() and reads the register base address through it.

Fix by moving the watchdog_set_drvdata() call earlier, to where various other pdc_wdt->wdt_dev fields are initialised.

Fixes 93937669e9b5 ("watchdog: ImgTec PDC Watchdog Timer Driver")
Cc Wim Van Sebroeck <[email protected]>
Cc Ezequiel Garcia <[email protected]>
Cc Naidu Tellapati <[email protected]>
Cc Jude Abraham <[email protected]>
---
 drivers/watchdog/imgpdc_wdt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/watchdog/imgpdc_wdt.c +1 -1
index c8def68..32c35eb 100644
@@ -191,6 +191,7 @@ static int pdc_wdt_probe(struct platform_device *pdev)
 	pdc_wdt->wdt_dev.ops = &pdc_wdt_ops;
 	pdc_wdt->wdt_dev.max_timeout = 1 << PDC_WDT_CONFIG_DELAY_MASK;
 	pdc_wdt->wdt_dev.parent = &pdev->dev;
+	watchdog_set_drvdata(&pdc_wdt->wdt_dev, pdc_wdt);
 
 	ret = watchdog_init_timeout(&pdc_wdt->wdt_dev, heartbeat, &pdev->dev);
 	if (ret < 0) {
@@ -232,7 +233,6 @@ static int pdc_wdt_probe(struct platform_device *pdev)
 	watchdog_set_nowayout(&pdc_wdt->wdt_dev, nowayout);
 
 	platform_set_drvdata(pdev, pdc_wdt);
-	watchdog_set_drvdata(&pdc_wdt->wdt_dev, pdc_wdt);
 
 	ret = watchdog_register_device(&pdc_wdt->wdt_dev);
 	if (ret)
Signature · 1 line
2.0.5
maintainer Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] watchdog: imgpdc: Fix probe NULL pointer dereference

Quoted 8 lines · James Hogan

The IMG PDC watchdog probe function calls pdc_wdt_stop() prior to watchdog_set_drvdata(), causing a NULL pointer dereference when pdc_wdt_stop() retrieves the struct pdc_wdt_dev pointer using watchdog_get_drvdata() and reads the register base address through it.

Fix by moving the watchdog_set_drvdata() call earlier, to where various other pdc_wdt->wdt_dev fields are initialised.

Quoted 7 lines
Fixes 93937669e9b5 ("watchdog: ImgTec PDC Watchdog Timer Driver")
Cc Wim Van Sebroeck <[email protected]>
Cc Ezequiel Garcia <[email protected]>
Cc Naidu Tellapati <[email protected]>
Cc Jude Abraham <[email protected]>
#3 lore raw

PATCH 2/2 watchdog: imgpdc: Fix default heartbeat

In reply to James Hogan

The IMG PDC watchdog driver heartbeat module parameter has no default so it is initialised to zero. This results in the following warning during probe:

imgpdc-wdt 2006000.wdt: Initial timeout out of range! setting max timeout

The module parameter description implies that the default value should be PDC_WDT_DEF_TIMEOUT, which isn't yet used, so initialise it to that.

Also tweak the heartbeat module parameter description for consistency.

Fixes 93937669e9b5 ("watchdog: ImgTec PDC Watchdog Timer Driver")
Cc Wim Van Sebroeck <[email protected]>
Cc Ezequiel Garcia <[email protected]>
Cc Naidu Tellapati <[email protected]>
Cc Jude Abraham <[email protected]>
---
 drivers/watchdog/imgpdc_wdt.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/watchdog/imgpdc_wdt.c +3 -3
index 32c35eb..0deaa4f 100644
@@ -42,10 +42,10 @@
 #define PDC_WDT_MIN_TIMEOUT		1
 #define PDC_WDT_DEF_TIMEOUT		64
 
-static int heartbeat;
+static int heartbeat = PDC_WDT_DEF_TIMEOUT;
 module_param(heartbeat, int, 0);
-MODULE_PARM_DESC(heartbeat, "Watchdog heartbeats in seconds. "
-	"(default = " __MODULE_STRING(PDC_WDT_DEF_TIMEOUT) ")");
+MODULE_PARM_DESC(heartbeat, "Watchdog heartbeats in seconds "
+	"(default=" __MODULE_STRING(PDC_WDT_DEF_TIMEOUT) ")");
 
 static bool nowayout = WATCHDOG_NOWAYOUT;
 module_param(nowayout, bool, 0);
Signature · 1 line
2.0.5
maintainer Reviewed-by on v1 2/2
#4 lore raw

Re: [PATCH 2/2] watchdog: imgpdc: Fix default heartbeat

Quoted 11 lines · James Hogan

The IMG PDC watchdog driver heartbeat module parameter has no default so it is initialised to zero. This results in the following warning during probe:

imgpdc-wdt 2006000.wdt: Initial timeout out of range! setting max timeout

The module parameter description implies that the default value should be PDC_WDT_DEF_TIMEOUT, which isn't yet used, so initialise it to that.

Also tweak the heartbeat module parameter description for consistency.

Quoted 7 lines
Fixes 93937669e9b5 ("watchdog: ImgTec PDC Watchdog Timer Driver")
Cc Wim Van Sebroeck <[email protected]>
Cc Ezequiel Garcia <[email protected]>
Cc Naidu Tellapati <[email protected]>
Cc Jude Abraham <[email protected]>
#5 lore raw
In reply to James Hogan

Hi,

Quoted 9 lines · James Hogan

A couple of basic runtime fixes for the IMG PDC watchdog driver. These were found by attempting to enable the driver for TZ1090 and running under Meta QEMU. Note that QEMU doesn't emulate the actual watchdog functionality beyond the soft reset register, so I cannot claim to have tested the driver's watchdog timer functionality yet.

James Hogan (2):
watchdog: imgpdc: Fix probe NULL pointer dereference
watchdog: imgpdc: Fix default heartbeat

Thanks Guenter for the reviews.

Any chance of these fixes getting merged in time for v4.0?

FWIW I've now tried the driver on real TZ1090 hardware (with these patches) and it appears to work as expected.

Cheers
James

Quoted 12 lines
 drivers/watchdog/imgpdc_wdt.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
Cc Wim Van Sebroeck <[email protected]>
Cc Ezequiel Garcia <[email protected]>
Cc Naidu Tellapati <[email protected]>
Cc Jude Abraham <[email protected]>
Signature · 1 line
2.0.5
maintainer
#6 lore raw
Quoted 9 lines · James Hogan

Hi,

Quoted 6 lines · James Hogan

A couple of basic runtime fixes for the IMG PDC watchdog driver. These were found by attempting to enable the driver for TZ1090 and running under Meta QEMU. Note that QEMU doesn't emulate the actual watchdog functionality beyond the soft reset register, so I cannot claim to have tested the driver's watchdog timer functionality yet.

Quoted 8 lines
Quoted 3 lines

James Hogan (2):
watchdog: imgpdc: Fix probe NULL pointer dereference
watchdog: imgpdc: Fix default heartbeat

Thanks Guenter for the reviews.

Any chance of these fixes getting merged in time for v4.0?

I agree that would be good. There is also 'watchdog: mtk_wdt:
signedness bug in mtk_wdt_start()' which should be in 4.0 as well.

Wim, if you are busy, want me to prepare and send a pull request to Linus ?

Thanks,
Guenter

#7 lore raw

Hi All,

Quoted 10 lines
Quoted 10 lines
Quoted 9 lines

A couple of basic runtime fixes for the IMG PDC watchdog driver. These were found by attempting to enable the driver for TZ1090 and running under Meta QEMU. Note that QEMU doesn't emulate the actual watchdog functionality beyond the soft reset register, so I cannot claim to have tested the driver's watchdog timer functionality yet.

James Hogan (2):
watchdog: imgpdc: Fix probe NULL pointer dereference
watchdog: imgpdc: Fix default heartbeat

Quoted 7 lines
Quoted 4 lines

Thanks Guenter for the reviews.

Any chance of these fixes getting merged in time for v4.0?

I agree that would be good. There is also 'watchdog: mtk_wdt:
signedness bug in mtk_wdt_start()' which should be in 4.0 as well.

Correct.

Quoted 1 line

Wim, if you are busy, want me to prepare and send a pull request to Linus ?

I'm preparing the 3 patches so that they can go upstream relatively soon.

Kind regards,
Wim.

#8 lore raw
In reply to James Hogan

Hi James,

Quoted 10 lines

A couple of basic runtime fixes for the IMG PDC watchdog driver. These were found by attempting to enable the driver for TZ1090 and running under Meta QEMU. Note that QEMU doesn't emulate the actual watchdog functionality beyond the soft reset register, so I cannot claim to have tested the driver's watchdog timer functionality yet.

James Hogan (2):
watchdog: imgpdc: Fix probe NULL pointer dereference
watchdog: imgpdc: Fix default heartbeat

Quoted 8 lines
 drivers/watchdog/imgpdc_wdt.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
Cc Wim Van Sebroeck <[email protected]>
Cc Ezequiel Garcia <[email protected]>
Cc Naidu Tellapati <[email protected]>
Cc Jude Abraham <[email protected]>

Both patches added to linux-watchdog-next. Will go upstream in 2 days.

Kind regards,
Wim.

#9 lore raw

Hi Wim & James,

Quoted 15 lines

Hi James,

Quoted 13 lines

A couple of basic runtime fixes for the IMG PDC watchdog driver. These were found by attempting to enable the driver for TZ1090 and running under Meta QEMU. Note that QEMU doesn't emulate the actual watchdog functionality beyond the soft reset register, so I cannot claim to have tested the driver's watchdog timer functionality yet.

James Hogan (2):
watchdog: imgpdc: Fix probe NULL pointer dereference
watchdog: imgpdc: Fix default heartbeat

 drivers/watchdog/imgpdc_wdt.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
Quoted 7 lines
Quoted 5 lines
Cc Wim Van Sebroeck <[email protected]>
Cc Ezequiel Garcia <[email protected]>
Cc Naidu Tellapati <[email protected]>
Cc Jude Abraham <[email protected]>

Both patches added to linux-watchdog-next. Will go upstream in 2 days.

Many thanks for your help in this regard.

Quoted 2 lines

Kind regards,
Wim.

Regards,
Naidu.