[PATCH v5 1/4] uacce: fix cdev handling in register and remove paths

From: Chenghai Huang

Date: Tue Nov 11 2025 - 04:40:23 EST


From: Wenkai Lin <linwenkai6@xxxxxxxxxxxxx>

This patch addresses a potential issue in the uacce driver where the
cdev was not properly managed during error handling and cleanup paths.

Changes made:
1. In uacce_register(), store the return value of cdev_device_add()
and clear the cdev owner as a flag if registration fails.
2. In uacce_remove(), add additional check for cdev owner before
calling cdev_device_del() to prevent potential issues.

Fixes: 015d239ac014 ("uacce: add uacce driver")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Wenkai Lin <linwenkai6@xxxxxxxxxxxxx>
Signed-off-by: Chenghai Huang <huangchenghai2@xxxxxxxxxx>
---
drivers/misc/uacce/uacce.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/misc/uacce/uacce.c b/drivers/misc/uacce/uacce.c
index 42e7d2a2a90c..688050c35d88 100644
--- a/drivers/misc/uacce/uacce.c
+++ b/drivers/misc/uacce/uacce.c
@@ -519,6 +519,8 @@ EXPORT_SYMBOL_GPL(uacce_alloc);
*/
int uacce_register(struct uacce_device *uacce)
{
+ int ret;
+
if (!uacce)
return -ENODEV;

@@ -529,7 +531,11 @@ int uacce_register(struct uacce_device *uacce)
uacce->cdev->ops = &uacce_fops;
uacce->cdev->owner = THIS_MODULE;

- return cdev_device_add(uacce->cdev, &uacce->dev);
+ ret = cdev_device_add(uacce->cdev, &uacce->dev);
+ if (ret)
+ uacce->cdev->owner = NULL;
+
+ return ret;
}
EXPORT_SYMBOL_GPL(uacce_register);

@@ -568,7 +574,7 @@ void uacce_remove(struct uacce_device *uacce)
unmap_mapping_range(q->mapping, 0, 0, 1);
}

- if (uacce->cdev)
+ if (uacce->cdev && uacce->cdev->owner)
cdev_device_del(uacce->cdev, &uacce->dev);
xa_erase(&uacce_xa, uacce->dev_id);
/*
--
2.33.0