]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - releases/4.14.108/drm-imx-imx-ldb-add-missing-of_node_puts.patch
Linux 4.14.108
[thirdparty/kernel/stable-queue.git] / releases / 4.14.108 / drm-imx-imx-ldb-add-missing-of_node_puts.patch
CommitLineData
ecf3b270
SL
1From 7aded8716f0ec10dd01f44b0dff5b216f3333189 Mon Sep 17 00:00:00 2001
2From: Julia Lawall <Julia.Lawall@lip6.fr>
3Date: Sun, 13 Jan 2019 09:47:42 +0100
4Subject: drm/imx: imx-ldb: add missing of_node_puts
5
6[ Upstream commit aa3312012f103f91f123600bbf768b11c8f431bc ]
7
8The device node iterators perform an of_node_get on each
9iteration, so a jump out of the loop requires an of_node_put.
10
11Move the initialization channel->child = child; down to just
12before the call to imx_ldb_register so that intervening failures
13don't need to clear it. Add a label at the end of the function to
14do all the of_node_puts.
15
16The semantic patch that finds part of this problem is as follows
17(http://coccinelle.lip6.fr):
18
19// <smpl>
20@@
21expression root,e;
22local idexpression child;
23iterator name for_each_child_of_node;
24@@
25
26 for_each_child_of_node(root, child) {
27 ... when != of_node_put(child)
28 when != e = child
29(
30 return child;
31|
32* return ...;
33)
34 ...
35 }
36// </smpl>
37
38Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
39Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
40Signed-off-by: Sasha Levin <sashal@kernel.org>
41---
42 drivers/gpu/drm/imx/imx-ldb.c | 25 +++++++++++++++++--------
43 1 file changed, 17 insertions(+), 8 deletions(-)
44
45diff --git a/drivers/gpu/drm/imx/imx-ldb.c b/drivers/gpu/drm/imx/imx-ldb.c
46index dd5312b02a8d..4f2e6c7e04c1 100644
47--- a/drivers/gpu/drm/imx/imx-ldb.c
48+++ b/drivers/gpu/drm/imx/imx-ldb.c
49@@ -652,8 +652,10 @@ static int imx_ldb_bind(struct device *dev, struct device *master, void *data)
50 int bus_format;
51
52 ret = of_property_read_u32(child, "reg", &i);
53- if (ret || i < 0 || i > 1)
54- return -EINVAL;
55+ if (ret || i < 0 || i > 1) {
56+ ret = -EINVAL;
57+ goto free_child;
58+ }
59
60 if (!of_device_is_available(child))
61 continue;
62@@ -666,7 +668,6 @@ static int imx_ldb_bind(struct device *dev, struct device *master, void *data)
63 channel = &imx_ldb->channel[i];
64 channel->ldb = imx_ldb;
65 channel->chno = i;
66- channel->child = child;
67
68 /*
69 * The output port is port@4 with an external 4-port mux or
70@@ -676,13 +677,13 @@ static int imx_ldb_bind(struct device *dev, struct device *master, void *data)
71 imx_ldb->lvds_mux ? 4 : 2, 0,
72 &channel->panel, &channel->bridge);
73 if (ret && ret != -ENODEV)
74- return ret;
75+ goto free_child;
76
77 /* panel ddc only if there is no bridge */
78 if (!channel->bridge) {
79 ret = imx_ldb_panel_ddc(dev, channel, child);
80 if (ret)
81- return ret;
82+ goto free_child;
83 }
84
85 bus_format = of_get_bus_format(dev, child);
86@@ -698,18 +699,26 @@ static int imx_ldb_bind(struct device *dev, struct device *master, void *data)
87 if (bus_format < 0) {
88 dev_err(dev, "could not determine data mapping: %d\n",
89 bus_format);
90- return bus_format;
91+ ret = bus_format;
92+ goto free_child;
93 }
94 channel->bus_format = bus_format;
95+ channel->child = child;
96
97 ret = imx_ldb_register(drm, channel);
98- if (ret)
99- return ret;
100+ if (ret) {
101+ channel->child = NULL;
102+ goto free_child;
103+ }
104 }
105
106 dev_set_drvdata(dev, imx_ldb);
107
108 return 0;
109+
110+free_child:
111+ of_node_put(child);
112+ return ret;
113 }
114
115 static void imx_ldb_unbind(struct device *dev, struct device *master,
116--
1172.19.1
118