[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250719075856.3447953-1-make24@iscas.ac.cn>
Date: Sat, 19 Jul 2025 15:58:56 +0800
From: Ma Ke <make24@...as.ac.cn>
To: axboe@...nel.dk,
	Jim.Quigley@...cle.com,
	davem@...emloft.net,
	sln@...main.com,
	alexandre.chartre@...cle.com,
	aaron.young@...cle.com
Cc: akpm@...ux-foundation.org,
	linux-block@...r.kernel.org,
	linux-kernel@...r.kernel.org,
	Ma Ke <make24@...as.ac.cn>,
	stable@...r.kernel.org
Subject: [PATCH v2] sunvdc: Balance device refcount in vdc_port_mpgroup_check
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@...r.kernel.org
Fixes: 3ee70591d6c4 ("sunvdc: prevent sunvdc panic when mpgroup disk added to guest domain")
Signed-off-by: Ma Ke <make24@...as.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
Powered by blists - more mailing lists