Skip to contentSkip to conversation

watchdog: core: Fix devres_alloc() allocation size

PATCH In review Guenter Roeck 2 participants 2 messages Aug 10, 2016 – Aug 11, 2016 Watchdog device drivers

lore
Share & tools
lore

Guenter Roeck

author maintainer
#0 lore raw

PATCH 1/1 watchdog: core: Fix devres_alloc() allocation size

Coverity reports:

Passing argument 152UL /* sizeof (*wdd) */ to function __devres_alloc_node and then casting the return value to struct watchdog_device ** is suspicious.

Allocation size needs to be sizeof(*rcwdd), not sizeof(*wdd).

Fixes 83fbae5a148c ("watchdog: Add a device managed API for ...")
Cc Neil Armstrong <[email protected]>
---
 drivers/watchdog/watchdog_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/watchdog/watchdog_core.c +1 -1
index 6abb83cd7681..74265b2f806c 100644
@@ -349,7 +349,7 @@ int devm_watchdog_register_device(struct device *dev,
 	struct watchdog_device **rcwdd;
 	int ret;
 
-	rcwdd = devres_alloc(devm_watchdog_unregister_device, sizeof(*wdd),
+	rcwdd = devres_alloc(devm_watchdog_unregister_device, sizeof(*rcwdd),
 			     GFP_KERNEL);
 	if (!rcwdd)
 		return -ENOMEM;
Signature · 1 line
2.5.0
Acked-by on v1 1/1
#1 lore raw
Quoted 21 lines · Guenter Roeck

Coverity reports:

Passing argument 152UL /* sizeof (*wdd) */ to function __devres_alloc_node and then casting the return value to struct watchdog_device ** is suspicious.

Allocation size needs to be sizeof(*rcwdd), not sizeof(*wdd).

Fixes 83fbae5a148c ("watchdog: Add a device managed API for ...")
Cc Neil Armstrong <[email protected]>
---
 drivers/watchdog/watchdog_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/watchdog/watchdog_core.c +0 -0
index 6abb83cd7681..74265b2f806c 100644

drivers/watchdog/watchdog_core.c int devm_watchdog_register_device(struct device *dev, · line 355

Quoted 8 lines
drivers/watchdog/watchdog_core.c +1 -1
@@ -349,7 +349,7 @@ int devm_watchdog_register_device(struct device *dev,
 	struct watchdog_device **rcwdd;
 	int ret;
 
-	rcwdd = devres_alloc(devm_watchdog_unregister_device, sizeof(*wdd),
+	rcwdd = devres_alloc(devm_watchdog_unregister_device, sizeof(*rcwdd),
 			     GFP_KERNEL);
 	if (!rcwdd)
 		return -ENOMEM;

My bad...