If the cdev_device_add fails, cdev should be free before return.
driver inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I9NUTY CVE: NA
----------------------------------------------------------------------
Fixes: 015d239ac014 ("uacce: add uacce driver") Signed-off-by: Wenkai Lin linwenkai6@hisilicon.com Signed-off-by: JiangShui Yang yangjiangshui@h-partners.com --- drivers/misc/uacce/uacce.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/drivers/misc/uacce/uacce.c b/drivers/misc/uacce/uacce.c index 2fe444990754..6d74765a6d45 100644 --- a/drivers/misc/uacce/uacce.c +++ b/drivers/misc/uacce/uacce.c @@ -984,6 +984,8 @@ EXPORT_SYMBOL_GPL(uacce_alloc); */ int uacce_register(struct uacce_device *uacce) { + int ret; + if (!uacce) return -ENODEV;
@@ -994,7 +996,14 @@ 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) { + cdev_del(uacce->cdev); + uacce->cdev = NULL; + return ret; + } + + return 0; } EXPORT_SYMBOL_GPL(uacce_register);