* [PATCH] watchdog: gpio-wdt: be more strict about hw_algo matching
@ 2015-07-30 9:32 Uwe Kleine-König
2015-07-30 14:40 ` Guenter Roeck
0 siblings, 1 reply; 2+ messages in thread
From: Uwe Kleine-König @ 2015-07-30 9:32 UTC (permalink / raw)
To: Wim Van Sebroeck, linux-watchdog; +Cc: Guenter Roeck, kernel
strncmp(algo, "toggle", 6) doesn't compare the trailing '\0' byte, so
using
hw_algo = "toggleboggle"
is recognized the same way as
hw_algo = "toggle"
. While this doesn't introduce any problems for a device tree that
sticks to the documented settings it's still ugly.
Fix this by using strcmp to only match on "toggle" and "level".
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
drivers/watchdog/gpio_wdt.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/watchdog/gpio_wdt.c b/drivers/watchdog/gpio_wdt.c
index 1687cc2d7122..57d30f1f55ab 100644
--- a/drivers/watchdog/gpio_wdt.c
+++ b/drivers/watchdog/gpio_wdt.c
@@ -182,10 +182,10 @@ static int gpio_wdt_probe(struct platform_device *pdev)
ret = of_property_read_string(pdev->dev.of_node, "hw_algo", &algo);
if (ret)
return ret;
- if (!strncmp(algo, "toggle", 6)) {
+ if (!strcmp(algo, "toggle")) {
priv->hw_algo = HW_ALGO_TOGGLE;
f = GPIOF_IN;
- } else if (!strncmp(algo, "level", 5)) {
+ } else if (!strcmp(algo, "level")) {
priv->hw_algo = HW_ALGO_LEVEL;
f = priv->active_low ? GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW;
} else {
--
2.1.4
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] watchdog: gpio-wdt: be more strict about hw_algo matching
2015-07-30 9:32 [PATCH] watchdog: gpio-wdt: be more strict about hw_algo matching Uwe Kleine-König
@ 2015-07-30 14:40 ` Guenter Roeck
0 siblings, 0 replies; 2+ messages in thread
From: Guenter Roeck @ 2015-07-30 14:40 UTC (permalink / raw)
To: Uwe Kleine-König, Wim Van Sebroeck, linux-watchdog; +Cc: kernel
On 07/30/2015 02:32 AM, Uwe Kleine-König wrote:
> strncmp(algo, "toggle", 6) doesn't compare the trailing '\0' byte, so
> using
>
> hw_algo = "toggleboggle"
>
> is recognized the same way as
>
> hw_algo = "toggle"
>
> . While this doesn't introduce any problems for a device tree that
> sticks to the documented settings it's still ugly.
>
> Fix this by using strcmp to only match on "toggle" and "level".
>
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-07-30 14:40 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-07-30 9:32 [PATCH] watchdog: gpio-wdt: be more strict about hw_algo matching Uwe Kleine-König
2015-07-30 14:40 ` Guenter Roeck
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox