All of lore.kernel.org
 help / color / mirror / Atom feed
* [RESEND PATCH] sparc64: Fix leaked platform_device reference in schizo_register_error_handlers()
@ 2026-12-02  8:38 Ma Ke
  2026-12-02  8:47 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Ma Ke @ 2026-12-02  8:38 UTC (permalink / raw)
  To: davem, andreas, make_ruc2021; +Cc: sparclinux, akpm, stable

of_find_device_by_node() is documented in drivers/of/platform.c:

 * Takes a reference to the embedded struct device which needs to be
 * dropped after use.

schizo_register_error_handlers() looks up the platform device backing
the PBM and never drops that reference.
tomatillo_register_error_handlers() in the same file has the leak.

Release the reference once the error interrupts have been registered.

Found by code review.

Fixes: 22fecbae4446 ("sparc64: Record OF device instead of device node pointer in pci_pbm_info.")
Cc: stable@vger.kernel.org
Signed-off-by: Ma Ke <make_ruc2021@163.com>
---
 arch/sparc/kernel/pci_schizo.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/sparc/kernel/pci_schizo.c b/arch/sparc/kernel/pci_schizo.c
index 4348ca2c4a3f..a8db997675cc 100644
--- a/arch/sparc/kernel/pci_schizo.c
+++ b/arch/sparc/kernel/pci_schizo.c
@@ -1050,6 +1050,8 @@ static void schizo_register_error_handlers(struct pci_pbm_info *pbm)
 
 	upa_writeq((SCHIZO_SAFERRCTRL_EN | err_mask),
 		   pbm->controller_regs + SCHIZO_SAFARI_ERRCTRL);
+
+	platform_device_put(op);
 }
 
 static void pbm_config_busmastering(struct pci_pbm_info *pbm)
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [RESEND PATCH] sparc64: Fix leaked platform_device reference in schizo_register_error_handlers()
  2026-12-02  8:38 [RESEND PATCH] sparc64: Fix leaked platform_device reference in schizo_register_error_handlers() Ma Ke
@ 2026-12-02  8:47 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-12-02  8:47 UTC (permalink / raw)
  To: Ma Ke; +Cc: sparclinux

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] sparc64: unfixed platform_device leak in
  tomatillo_register_error_handlers()
- [Low] sparc64: redundant of_find_device_by_node() in
  schizo_register_error_handlers()
- [Low] sparc64: inaccurate Fixes tag in
  schizo_register_error_handlers() leak fix
It also noticed 1 related pre-existing issue this patch does not
introduce:
- [High] sparc: null pointer dereferences after of_find_device_by_node()
  [1]
--

commit 107e100efab4d240d72ab8b5634d12dbba9daf53
Author: Ma Ke <make_ruc2021@163.com>

> sparc64: Fix leaked platform_device reference in schizo_register_error_handlers()
>
> of_find_device_by_node() is documented in drivers/of/platform.c:
>
>  * Takes a reference to the embedded struct device which needs to be
>  * dropped after use.
>
> schizo_register_error_handlers() looks up the platform device backing
> the PBM and never drops that reference.
> tomatillo_register_error_handlers() in the same file has the leak.
>
> Release the reference once the error interrupts have been registered.
>
> Found by code review.
>
> Fixes: 22fecbae4446 ("sparc64: Record OF device instead of device node pointer in pci_pbm_info.")
> Cc: stable@vger.kernel.org
> Signed-off-by: Ma Ke <make_ruc2021@163.com>

[Severity: Low]
Does the Fixes tag point to the commit that introduced the leak?  Commit
22fecbae4446 ("sparc64: Record OF device instead of device node pointer in
pci_pbm_info.") only changed the argument of of_find_device_by_node() from
pbm->prom_node to pbm->op->node, whereas the unreleased
of_find_device_by_node() calls were introduced in 2b1e59787198
("[SPARC64]: of_device layer IRQ resolution") and consolidated at function
entry in 34768bc83291 ("[SPARC64] PCI: Use root list of pbm's instead of
pci_controller_info's").

> diff --git a/arch/sparc/kernel/pci_schizo.c b/arch/sparc/kernel/pci_schizo.c
> index 421aba00e6b0a..aa0ed8f1eac6c 100644
> --- a/arch/sparc/kernel/pci_schizo.c
> +++ b/arch/sparc/kernel/pci_schizo.c
> @@ -1047,6 +1047,8 @@ static void schizo_register_error_handlers(struct pci_pbm_info *pbm)
>  
>  	upa_writeq((SCHIZO_SAFERRCTRL_EN | err_mask),
>  		   pbm->controller_regs + SCHIZO_SAFARI_ERRCTRL);
> +
> +	platform_device_put(op);
>  }
>  
>  static void pbm_config_busmastering(struct pci_pbm_info *pbm)

[Severity: Medium]
Should tomatillo_register_error_handlers() also be fixed here?  The commit
message notes that tomatillo_register_error_handlers() has the same
of_find_device_by_node(pbm->op->dev.of_node) reference leak, and
schizo_scan_bus() calls tomatillo_register_error_handlers() instead of
schizo_register_error_handlers() when pbm->chip_type is
PBM_CHIP_TYPE_TOMATILLO.

[Severity: Low]
Is of_find_device_by_node(pbm->op->dev.of_node) needed at all in
schizo_register_error_handlers() and tomatillo_register_error_handlers()?
schizo_pbm_init() already sets pbm->op to the PBM's struct platform_device
before calling schizo_scan_bus(), so both functions could use pbm->op
directly instead of looking it up via pbm->op->dev.of_node and dropping the
extra reference.

[Severity: High]
This problem wasn't introduced by this patch, but can
of_find_device_by_node() return NULL and cause a NULL pointer dereference in
schizo_register_error_handlers() and of_propagate_archdata() [1]?  If
a device tree node has no registered platform device, both functions
immediately dereference op (via op->archdata.irqs[] or
op->dev.archdata.iommu) without checking for NULL, panicking the kernel
during boot.

[1] https://sashiko.dev/#/bug/linux-a3f0b479-43e6-4cf9-a532-2a1e33c98936

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261202083827.1817564-1-make_ruc2021@163.com?part=1

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-12-02  8:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02  8:38 [RESEND PATCH] sparc64: Fix leaked platform_device reference in schizo_register_error_handlers() Ma Ke
2026-12-02  8:47 ` sashiko-bot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.