* [PATCH 0/2] virt: fsl: fix missing of_node_put() on early exit from for_each_compatible_node()
@ 2024-10-28 17:05 Javier Carrasco
2024-10-28 17:05 ` [PATCH 1/2] " Javier Carrasco
2024-10-28 17:05 ` [PATCH 2/2] virt: fsl: refactor out_of_memory label Javier Carrasco
0 siblings, 2 replies; 3+ messages in thread
From: Javier Carrasco @ 2024-10-28 17:05 UTC (permalink / raw)
To: Arnd Bergmann, Timur Tabi, Kumar Gala
Cc: linux-kernel, Javier Carrasco, stable
This short series fixes an old bug that only happens if a memory
allocation fails, which might be the reason why it was never found. When
at it an unnecessary jump to a label has been removed to simplify the
error path and avoid jumps out of the loop, which might have hidden the
bug while reading the code.
Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
---
Javier Carrasco (2):
virt: fsl: fix missing of_node_put() on early exit from for_each_compatible_node()
virt: fsl: refactor out_of_memory label
drivers/virt/fsl_hypervisor.c | 23 ++++++++++-------------
1 file changed, 10 insertions(+), 13 deletions(-)
---
base-commit: dec9255a128e19c5fcc3bdb18175d78094cc624d
change-id: 20241028-fsl_hypervisor-of_node_put-5051e664f038
Best regards,
--
Javier Carrasco <javier.carrasco.cruz@gmail.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 1/2] virt: fsl: fix missing of_node_put() on early exit from for_each_compatible_node()
2024-10-28 17:05 [PATCH 0/2] virt: fsl: fix missing of_node_put() on early exit from for_each_compatible_node() Javier Carrasco
@ 2024-10-28 17:05 ` Javier Carrasco
2024-10-28 17:05 ` [PATCH 2/2] virt: fsl: refactor out_of_memory label Javier Carrasco
1 sibling, 0 replies; 3+ messages in thread
From: Javier Carrasco @ 2024-10-28 17:05 UTC (permalink / raw)
To: Arnd Bergmann, Timur Tabi, Kumar Gala
Cc: linux-kernel, Javier Carrasco, stable
Early exits from for_each_compatible_node() require explicit calls to
of_node_put() to release the node and avoid leaking the resource. Add
the missing call to of_node_put(np) before the 'goto' instruction that
jumps out of the loop.
Cc: stable@vger.kernel.org
Fixes: 6db7199407ca ("drivers/virt: introduce Freescale hypervisor management driver")
Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
---
drivers/virt/fsl_hypervisor.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/virt/fsl_hypervisor.c b/drivers/virt/fsl_hypervisor.c
index e92e2ceb12a4..7c7ec13761ba 100644
--- a/drivers/virt/fsl_hypervisor.c
+++ b/drivers/virt/fsl_hypervisor.c
@@ -846,8 +846,10 @@ static int __init fsl_hypervisor_init(void)
}
dbisr = kzalloc(sizeof(*dbisr), GFP_KERNEL);
- if (!dbisr)
+ if (!dbisr) {
+ of_node_put(np);
goto out_of_memory;
+ }
dbisr->irq = irq;
dbisr->doorbell = be32_to_cpup(handle);
--
2.43.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 2/2] virt: fsl: refactor out_of_memory label
2024-10-28 17:05 [PATCH 0/2] virt: fsl: fix missing of_node_put() on early exit from for_each_compatible_node() Javier Carrasco
2024-10-28 17:05 ` [PATCH 1/2] " Javier Carrasco
@ 2024-10-28 17:05 ` Javier Carrasco
1 sibling, 0 replies; 3+ messages in thread
From: Javier Carrasco @ 2024-10-28 17:05 UTC (permalink / raw)
To: Arnd Bergmann, Timur Tabi, Kumar Gala; +Cc: linux-kernel, Javier Carrasco
The 'out_of_memory' label is only accessible by means of a goto jump
that only happens once. Take the required actions right after the error
happens, and drop the need for a jump out of the loop.
Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
---
drivers/virt/fsl_hypervisor.c | 19 +++++++------------
1 file changed, 7 insertions(+), 12 deletions(-)
diff --git a/drivers/virt/fsl_hypervisor.c b/drivers/virt/fsl_hypervisor.c
index 7c7ec13761ba..bc5d7aa246df 100644
--- a/drivers/virt/fsl_hypervisor.c
+++ b/drivers/virt/fsl_hypervisor.c
@@ -848,7 +848,13 @@ static int __init fsl_hypervisor_init(void)
dbisr = kzalloc(sizeof(*dbisr), GFP_KERNEL);
if (!dbisr) {
of_node_put(np);
- goto out_of_memory;
+ list_for_each_entry_safe(dbisr, n, &isr_list, list) {
+ free_irq(dbisr->irq, dbisr);
+ list_del(&dbisr->list);
+ kfree(dbisr);
+ }
+ misc_deregister(&fsl_hv_misc_dev);
+ return -ENOMEM;
}
dbisr->irq = irq;
@@ -895,17 +901,6 @@ static int __init fsl_hypervisor_init(void)
}
return 0;
-
-out_of_memory:
- list_for_each_entry_safe(dbisr, n, &isr_list, list) {
- free_irq(dbisr->irq, dbisr);
- list_del(&dbisr->list);
- kfree(dbisr);
- }
-
- misc_deregister(&fsl_hv_misc_dev);
-
- return -ENOMEM;
}
/*
--
2.43.0
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-10-28 17:05 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-10-28 17:05 [PATCH 0/2] virt: fsl: fix missing of_node_put() on early exit from for_each_compatible_node() Javier Carrasco
2024-10-28 17:05 ` [PATCH 1/2] " Javier Carrasco
2024-10-28 17:05 ` [PATCH 2/2] virt: fsl: refactor out_of_memory label Javier Carrasco
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®