* [PATCH] MIPS: ralink: Fix refcount leak in ill_acc_of_setup()
@ 2025-04-07 8:27 Thorsten Blum
2025-04-09 12:57 ` Jonas Gorski
0 siblings, 1 reply; 3+ messages in thread
From: Thorsten Blum @ 2025-04-07 8:27 UTC (permalink / raw)
To: John Crispin, Sergio Paracuellos, Thomas Bogendoerfer
Cc: Thorsten Blum, stable, linux-mips, linux-kernel
The of_find_device_by_node() function increments the reference count of
the embedded device, which should be released with put_device() when it
is no longer needed.
In ill_acc_of_setup(), put_device() is only called on error paths, but
not on the success path. Fix this by calling put_device() before
returning successfully.
Compile-tested only.
Cc: stable@vger.kernel.org
Fixes: 5433acd81e873 ("MIPS: ralink: add illegal access driver")
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
arch/mips/ralink/ill_acc.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/arch/mips/ralink/ill_acc.c b/arch/mips/ralink/ill_acc.c
index 25341b2319d0..6d1d829854b6 100644
--- a/arch/mips/ralink/ill_acc.c
+++ b/arch/mips/ralink/ill_acc.c
@@ -84,6 +84,7 @@ static int __init ill_acc_of_setup(void)
rt_memc_w32(ILL_INT_STATUS, REG_ILL_ACC_TYPE);
dev_info(&pdev->dev, "irq registered\n");
+ put_device(&pdev->dev);
return 0;
}
--
2.49.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] MIPS: ralink: Fix refcount leak in ill_acc_of_setup()
2025-04-07 8:27 [PATCH] MIPS: ralink: Fix refcount leak in ill_acc_of_setup() Thorsten Blum
@ 2025-04-09 12:57 ` Jonas Gorski
2025-04-09 14:16 ` Thorsten Blum
0 siblings, 1 reply; 3+ messages in thread
From: Jonas Gorski @ 2025-04-09 12:57 UTC (permalink / raw)
To: Thorsten Blum
Cc: John Crispin, Sergio Paracuellos, Thomas Bogendoerfer, stable,
linux-mips, linux-kernel
Hi,
On Mon, Apr 7, 2025 at 10:32 AM Thorsten Blum <thorsten.blum@linux.dev> wrote:
>
> The of_find_device_by_node() function increments the reference count of
> the embedded device, which should be released with put_device() when it
> is no longer needed.
>
> In ill_acc_of_setup(), put_device() is only called on error paths, but
> not on the success path. Fix this by calling put_device() before
> returning successfully.
I would think this is very much deliberate as the device is used as
the priv argument of the registered IRQ handler. AFAIU as long as that
one is live the reference of the device needs to be kept.
Dropping the reference of the device should only be done after
freeing/unregistering the IRQ again, which currently never happens.
Best regards,
Jonas
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] MIPS: ralink: Fix refcount leak in ill_acc_of_setup()
2025-04-09 12:57 ` Jonas Gorski
@ 2025-04-09 14:16 ` Thorsten Blum
0 siblings, 0 replies; 3+ messages in thread
From: Thorsten Blum @ 2025-04-09 14:16 UTC (permalink / raw)
To: Jonas Gorski
Cc: John Crispin, Sergio Paracuellos, Thomas Bogendoerfer, stable,
linux-mips, linux-kernel
On 9. Apr 2025, at 14:57, Jonas Gorski wrote:
> On Mon, Apr 7, 2025 at 10:32 AM Thorsten Blum wrote:
>>
>> The of_find_device_by_node() function increments the reference count of
>> the embedded device, which should be released with put_device() when it
>> is no longer needed.
>>
>> In ill_acc_of_setup(), put_device() is only called on error paths, but
>> not on the success path. Fix this by calling put_device() before
>> returning successfully.
>
> I would think this is very much deliberate as the device is used as
> the priv argument of the registered IRQ handler. AFAIU as long as that
> one is live the reference of the device needs to be kept.
>
> Dropping the reference of the device should only be done after
> freeing/unregistering the IRQ again, which currently never happens.
Thanks for the explanation. I assumed request_irq() would increment the
refcount, but that's apparently not the case because it's just a cookie.
Thanks,
Thorsten
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-04-09 14:17 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-07 8:27 [PATCH] MIPS: ralink: Fix refcount leak in ill_acc_of_setup() Thorsten Blum
2025-04-09 12:57 ` Jonas Gorski
2025-04-09 14:16 ` Thorsten Blum
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).