[PATCH 1/1] char: xillybus: check return value

From: Pan Bian
Date: Sun Apr 23 2017 - 06:11:22 EST


From: Pan Bian <bianpan2016@xxxxxxx>

Function of_address_to_resource() tries to translate device tree address
and return as resource. If the translation fails, it will return a
negative errno. However, function xilly_drv_probe() does not validate
its return value, which may result in a bad memory access bug. This
patch fixes the bug.

Signed-off-by: Pan Bian <bianpan2016@xxxxxxx>
---
drivers/char/xillybus/xillybus_of.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/drivers/char/xillybus/xillybus_of.c b/drivers/char/xillybus/xillybus_of.c
index 78a492f..57b295a 100644
--- a/drivers/char/xillybus/xillybus_of.c
+++ b/drivers/char/xillybus/xillybus_of.c
@@ -137,6 +137,8 @@ static int xilly_drv_probe(struct platform_device *op)
dev_set_drvdata(dev, endpoint);

rc = of_address_to_resource(dev->of_node, 0, &res);
+ if (rc < 0)
+ return rc;
endpoint->registers = devm_ioremap_resource(dev, &res);

if (IS_ERR(endpoint->registers))
--
1.9.1