memory: emif: fix device_node reference leak on np_ddr
PATCH 1/1 memory: emif: fix device_node reference leak on np_ddr
of_get_memory_device_details() takes a reference on the DDR device node via of_parse_phandle() and stores it in emif->np_ddr for later use, but drops that reference without calling of_node_put() on two error paths: the devm_kzalloc() allocation-failure check and the is_dev_data_valid() check. Both return NULL immediately, leaking the node reference each time either failure triggers.
The same reference is also never released on the success path: it is kept for the life of the bound device (compared against a later instance's np_ddr in the duplicate-DDR-geometry check) but emif_remove() never calls of_node_put() on it, leaking it every time an EMIF device unbinds. of_node_put() on a NULL pointer is a no-op, so this is also safe for the non-DT get_device_details() path, where np_ddr is left NULL by devm_kzalloc().
--- drivers/memory/emif.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/memory/emif.c +3 -0
@@ -922,6 +922,7 @@ static struct emif_data *of_get_memory_device_details(if (!emif || !pd || !dev_info) {dev_err (dev,"%s: Out of memory!!\n" , __func__); +of_node_put (np_ddr); goto error; }
@@ -946,6 +947,7 @@ static struct emif_data *of_get_memory_device_details( pd->device_info->io_width, pd->phy_type, pd->ip_rev, emif->dev)) {dev_err (dev,"%s: invalid device data!!\n" , __func__); +of_node_put (np_ddr); goto error; }/*
@@ -1140,6 +1142,7 @@ static void emif_remove(struct platform_device *pdev)struct emif_data *emif =platform_get_drvdata (pdev);emif_debugfs_exit (emif); +of_node_put (emif->np_ddr); }static void emif_shutdown (struct platform_device *pdev)
---
base-commit: 50d05c7c76c96b90462f24debacca971d2e86713
change-id: 20260909-master-1313e6bbb1fc
Best regards,
Signature · 1 line
Miles Krause <[email protected]>
Quoted 8 lines · Miles Krause
of_get_memory_device_details()takes a reference on the DDR device node viaof_parse_phandle()and stores it inemif->np_ddrfor later use, but drops that reference without callingof_node_put()on two error paths: thedevm_kzalloc()allocation-failure check and theis_dev_data_valid()check. Both return NULL immediately, leaking the node reference each time either failure triggers.[...]
Applied, thanks!
[1/1] memory: emif: fix device_node reference leak on np_ddr
https://git.kernel.org/krzk/linux-mem-ctrl/c/314ef67d673284d4c070455bd62d332f6d0f8634
Best regards,
Signature · 1 line
Krzysztof Kozlowski <[email protected]>