This driver has faced several issues due to the wrong or missing usage of of_node_put() to release device nodes after they are no longer required.
The first implementation was missing the of_node_put() for 'layers_node', and it put 'layer_node' twice. Then commit 'd3a453416270 ("drm: fix device_node_continue.cocci warnings")' removed the extra of_node_put(layer_node), which would have been ok if it had stayed only in the error path. Later, commit 'e9fcc60ddd29 ("drm/logicvc: add missing of_node_put() in logicvc_layers_init()")' added the missing of_node_put(layers_node), but not the one for the child node.
It should be clear how easy someone can mess up with this pattern, especially with variables that have similar names.
To fix the bug for stable kernels, and provide a more robust solution that accounts for new error paths, this series provides a first patch with the classical approach of adding the missing of_node_put(), and two more patches to use the cleanup attribute and avoid issues with device nodes again.
Signed-off-by: Javier Carrasco javier.carrasco.cruz@gmail.com --- Javier Carrasco (3): drm: logicvc: fix missing of_node_put() in for_each_child_of_node() drm: logicvc: switch to for_each_child_of_node_scoped() drm: logicvc: use automatic cleanup facility for layers_node
drivers/gpu/drm/logicvc/logicvc_layer.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) --- base-commit: 0cca97bf23640ff68a6e8a74e9b6659fdc27f48c change-id: 20241010-logicvc_layer_of_node_put-bc4cb207280b
Best regards,
Early exits from the for_each_child_of_node() loop require explicit calls to of_node_put() for the child node.
Add the missing 'of_node_put(layer_node)' in the only error path.
Cc: stable@vger.kernel.org Fixes: efeeaefe9be5 ("drm: Add support for the LogiCVC display controller") Signed-off-by: Javier Carrasco javier.carrasco.cruz@gmail.com --- drivers/gpu/drm/logicvc/logicvc_layer.c | 1 + 1 file changed, 1 insertion(+)
diff --git a/drivers/gpu/drm/logicvc/logicvc_layer.c b/drivers/gpu/drm/logicvc/logicvc_layer.c index 464000aea765..52dabacd42ee 100644 --- a/drivers/gpu/drm/logicvc/logicvc_layer.c +++ b/drivers/gpu/drm/logicvc/logicvc_layer.c @@ -613,6 +613,7 @@ int logicvc_layers_init(struct logicvc_drm *logicvc)
ret = logicvc_layer_init(logicvc, layer_node, index); if (ret) { + of_node_put(layer_node); of_node_put(layers_node); goto error; }
On 11/10/24 - 01:11, Javier Carrasco wrote:
Early exits from the for_each_child_of_node() loop require explicit calls to of_node_put() for the child node.
Add the missing 'of_node_put(layer_node)' in the only error path.
Cc: stable@vger.kernel.org Fixes: efeeaefe9be5 ("drm: Add support for the LogiCVC display controller") Signed-off-by: Javier Carrasco javier.carrasco.cruz@gmail.com
Reviewed-By: Louis Chauvet louis.chauvet@bootlin.com
drivers/gpu/drm/logicvc/logicvc_layer.c | 1 + 1 file changed, 1 insertion(+)
diff --git a/drivers/gpu/drm/logicvc/logicvc_layer.c b/drivers/gpu/drm/logicvc/logicvc_layer.c index 464000aea765..52dabacd42ee 100644 --- a/drivers/gpu/drm/logicvc/logicvc_layer.c +++ b/drivers/gpu/drm/logicvc/logicvc_layer.c @@ -613,6 +613,7 @@ int logicvc_layers_init(struct logicvc_drm *logicvc) ret = logicvc_layer_init(logicvc, layer_node, index); if (ret) {
}of_node_put(layer_node); of_node_put(layers_node); goto error;
-- 2.43.0
linux-stable-mirror@lists.linaro.org