[PATCH] gpu: host1x: Fix device reference leak in device_add() error path

From: Guangshuo Li

Date: Sun Apr 12 2026 - 08:19:03 EST


After device_initialize(), the embedded struct device in struct
host1x_device should be released through the device core with
put_device().

In host1x_device_add(), the empty-subdevice path calls
device_add(&device->dev), but if that fails it only logs the error and
continues without dropping the device reference. That leaks the
reference held on the embedded struct device.

Fix this by removing the device from host1x->devices and calling
put_device() when device_add() fails.

Fixes: fab823d82ee50 ("gpu: host1x: Allow loading tegra-drm without enabled engines")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Guangshuo Li <lgs201920130244@xxxxxxxxx>
---
drivers/gpu/host1x/bus.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/host1x/bus.c b/drivers/gpu/host1x/bus.c
index f97567e6ae87..e3ac85848aec 100644
--- a/drivers/gpu/host1x/bus.c
+++ b/drivers/gpu/host1x/bus.c
@@ -477,8 +477,12 @@ static int host1x_device_add(struct host1x *host1x,
*/
if (list_empty(&device->subdevs)) {
err = device_add(&device->dev);
- if (err < 0)
+ if (err < 0) {
dev_err(&device->dev, "failed to add device: %d\n", err);
+ list_del(&device->list);
+ put_device(&device->dev);
+ return err;
+ }
else
device->registered = true;
}
--
2.43.0