Skip to content

Commit bf58219

Browse files
joehattorimiquelraynal
authored andcommitted
mtd: hyperbus: hbmc-am654: fix an OF node reference leak
In am654_hbmc_platform_driver, .remove() and the error path of .probe() do not decrement the refcount of an OF node obtained by of_get_next_child(). Fix this by adding of_node_put() calls. Fixes: aca31ce ("mtd: hyperbus: hbmc-am654: Fix direct mapping setup flash access") Signed-off-by: Joe Hattori <[email protected]> Signed-off-by: Miquel Raynal <[email protected]>
1 parent 02ba194 commit bf58219

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

drivers/mtd/hyperbus/hbmc-am654.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,26 +174,30 @@ static int am654_hbmc_probe(struct platform_device *pdev)
174174
priv->hbdev.np = of_get_next_child(np, NULL);
175175
ret = of_address_to_resource(priv->hbdev.np, 0, &res);
176176
if (ret)
177-
return ret;
177+
goto put_node;
178178

179179
if (of_property_read_bool(dev->of_node, "mux-controls")) {
180180
struct mux_control *control = devm_mux_control_get(dev, NULL);
181181

182-
if (IS_ERR(control))
183-
return PTR_ERR(control);
182+
if (IS_ERR(control)) {
183+
ret = PTR_ERR(control);
184+
goto put_node;
185+
}
184186

185187
ret = mux_control_select(control, 1);
186188
if (ret) {
187189
dev_err(dev, "Failed to select HBMC mux\n");
188-
return ret;
190+
goto put_node;
189191
}
190192
priv->mux_ctrl = control;
191193
}
192194

193195
priv->hbdev.map.size = resource_size(&res);
194196
priv->hbdev.map.virt = devm_ioremap_resource(dev, &res);
195-
if (IS_ERR(priv->hbdev.map.virt))
196-
return PTR_ERR(priv->hbdev.map.virt);
197+
if (IS_ERR(priv->hbdev.map.virt)) {
198+
ret = PTR_ERR(priv->hbdev.map.virt);
199+
goto disable_mux;
200+
}
197201

198202
priv->ctlr.dev = dev;
199203
priv->ctlr.ops = &am654_hbmc_ops;
@@ -226,6 +230,8 @@ static int am654_hbmc_probe(struct platform_device *pdev)
226230
disable_mux:
227231
if (priv->mux_ctrl)
228232
mux_control_deselect(priv->mux_ctrl);
233+
put_node:
234+
of_node_put(priv->hbdev.np);
229235
return ret;
230236
}
231237

@@ -241,6 +247,7 @@ static void am654_hbmc_remove(struct platform_device *pdev)
241247

242248
if (dev_priv->rx_chan)
243249
dma_release_channel(dev_priv->rx_chan);
250+
of_node_put(priv->hbdev.np);
244251
}
245252

246253
static const struct of_device_id am654_hbmc_dt_ids[] = {

0 commit comments

Comments
 (0)