* [PATCH v2] sunvdc: Balance device refcount in vdc_port_mpgroup_check
@ 2025-07-19 7:58 Ma Ke
2025-07-22 16:02 ` Jens Axboe
0 siblings, 1 reply; 2+ messages in thread
From: Ma Ke @ 2025-07-19 7:58 UTC (permalink / raw)
To: axboe, Jim.Quigley, davem, sln, alexandre.chartre, aaron.young
Cc: akpm, linux-block, linux-kernel, Ma Ke, stable
Using device_find_child() to locate a probed virtual-device-port node
causes a device refcount imbalance, as device_find_child() internally
calls get_device() to increment the device’s reference count before
returning its pointer. vdc_port_mpgroup_check() directly returns true
upon finding a matching device without releasing the reference via
put_device(). We should call put_device() to decrement refcount.
As comment of device_find_child() says, 'NOTE: you will need to drop
the reference with put_device() after use'.
Found by code review.
Cc: stable@vger.kernel.org
Fixes: 3ee70591d6c4 ("sunvdc: prevent sunvdc panic when mpgroup disk added to guest domain")
Signed-off-by: Ma Ke <make24@iscas.ac.cn>
---
Changes in v2:
- keep the change style simple as suggestions.
---
drivers/block/sunvdc.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/block/sunvdc.c b/drivers/block/sunvdc.c
index b5727dea15bd..7af21fe67671 100644
--- a/drivers/block/sunvdc.c
+++ b/drivers/block/sunvdc.c
@@ -957,8 +957,10 @@ static bool vdc_port_mpgroup_check(struct vio_dev *vdev)
dev = device_find_child(vdev->dev.parent, &port_data,
vdc_device_probed);
- if (dev)
+ if (dev) {
+ put_device(dev);
return true;
+ }
return false;
}
--
2.25.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] sunvdc: Balance device refcount in vdc_port_mpgroup_check
2025-07-19 7:58 [PATCH v2] sunvdc: Balance device refcount in vdc_port_mpgroup_check Ma Ke
@ 2025-07-22 16:02 ` Jens Axboe
0 siblings, 0 replies; 2+ messages in thread
From: Jens Axboe @ 2025-07-22 16:02 UTC (permalink / raw)
To: Jim.Quigley, davem, sln, alexandre.chartre, aaron.young, Ma Ke
Cc: akpm, linux-block, linux-kernel, stable
On Sat, 19 Jul 2025 15:58:56 +0800, Ma Ke wrote:
> Using device_find_child() to locate a probed virtual-device-port node
> causes a device refcount imbalance, as device_find_child() internally
> calls get_device() to increment the device’s reference count before
> returning its pointer. vdc_port_mpgroup_check() directly returns true
> upon finding a matching device without releasing the reference via
> put_device(). We should call put_device() to decrement refcount.
>
> [...]
Applied, thanks!
[1/1] sunvdc: Balance device refcount in vdc_port_mpgroup_check
commit: 63ce53724637e2e7ba51fe3a4f78351715049905
Best regards,
--
Jens Axboe
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-07-22 16:02 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-19 7:58 [PATCH v2] sunvdc: Balance device refcount in vdc_port_mpgroup_check Ma Ke
2025-07-22 16:02 ` Jens Axboe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox