mirror of
https://github.com/torvalds/linux.git
synced 2026-11-20 13:03:48 +00:00
chardev: check return value of kobject_set_name() in __register_chrdev()
The kobject_set_name() function can fail and return -ENOMEM if memory allocation fails. While all other functions called inside __register_chrdev() are properly checked for errors, kobject_set_name() was missing this check. Add the error check for kobject_set_name() and jump to the 'out' label on failure to maintain consistency and ensure proper error handling. Found by manual code inspection. Reviewed-by: Jan Kara <[email protected]> Signed-off-by: bui duc phuc <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Christian Brauner (Amutable) <[email protected]>
This commit is contained in:
+3
-1
@@ -280,7 +280,9 @@ int __register_chrdev(unsigned int major, unsigned int baseminor,
|
||||
|
||||
cdev->owner = fops->owner;
|
||||
cdev->ops = fops;
|
||||
kobject_set_name(&cdev->kobj, "%s", name);
|
||||
err = kobject_set_name(&cdev->kobj, "%s", name);
|
||||
if (err)
|
||||
goto out;
|
||||
|
||||
err = cdev_add(cdev, MKDEV(cd->major, baseminor), count);
|
||||
if (err)
|
||||
|
||||
Reference in New Issue
Block a user