summaryrefslogtreecommitdiff
path: root/drivers/reset
diff options
context:
space:
mode:
authorGeert Uytterhoeven <geert+renesas@glider.be>2018-10-08 13:14:35 +0200
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2019-11-24 08:23:21 +0100
commit784505c2378a1d96a4c97d2ec055ececfdcf4914 (patch)
treeab1544c8aac9aba9b700b5f6fb2944a201c3f21c /drivers/reset
parente5379b2bc7e11c157a4a1d9e7fb81f52b79c66b1 (diff)
reset: Fix potential use-after-free in __of_reset_control_get()
[ Upstream commit b790c8ea5593d6dc3580adfad8e117eeb56af874 ] Calling of_node_put() decreases the reference count of a device tree object, and may free some data. However, the of_phandle_args structure embedding it is passed to reset_controller_dev.of_xlate() after that, so it may still be accessed. Move the call to of_node_put() down to fix this. Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be> [p.zabel@pengutronix.de: moved of_node_put after mutex_unlock] Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de> Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'drivers/reset')
-rw-r--r--drivers/reset/core.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/drivers/reset/core.c b/drivers/reset/core.c
index da4292e9de97..72b96b5c75a8 100644
--- a/drivers/reset/core.c
+++ b/drivers/reset/core.c
@@ -466,28 +466,29 @@ struct reset_control *__of_reset_control_get(struct device_node *node,
break;
}
}
- of_node_put(args.np);
if (!rcdev) {
- mutex_unlock(&reset_list_mutex);
- return ERR_PTR(-EPROBE_DEFER);
+ rstc = ERR_PTR(-EPROBE_DEFER);
+ goto out;
}
if (WARN_ON(args.args_count != rcdev->of_reset_n_cells)) {
- mutex_unlock(&reset_list_mutex);
- return ERR_PTR(-EINVAL);
+ rstc = ERR_PTR(-EINVAL);
+ goto out;
}
rstc_id = rcdev->of_xlate(rcdev, &args);
if (rstc_id < 0) {
- mutex_unlock(&reset_list_mutex);
- return ERR_PTR(rstc_id);
+ rstc = ERR_PTR(rstc_id);
+ goto out;
}
/* reset_list_mutex also protects the rcdev's reset_control list */
rstc = __reset_control_get_internal(rcdev, rstc_id, shared);
+out:
mutex_unlock(&reset_list_mutex);
+ of_node_put(args.np);
return rstc;
}