* [PATCH] chardev: check return value of kobject_set_name() in __register_chrdev()
@ 2026-08-26 5:20 phucduc.bui
2026-08-26 16:24 ` Jan Kara
0 siblings, 1 reply; 3+ messages in thread
From: phucduc.bui @ 2026-08-26 5:20 UTC (permalink / raw)
To: Alexander Viro, Christian Brauner, Jan Kara
Cc: linux-fsdevel, linux-kernel, bui duc phuc
From: bui duc phuc <phucduc.bui@gmail.com>
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.
Signed-off-by: bui duc phuc <phucduc.bui@gmail.com>
---
fs/char_dev.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/fs/char_dev.c b/fs/char_dev.c
index 00229e25c10f..5ce5423f6c99 100644
--- a/fs/char_dev.c
+++ b/fs/char_dev.c
@@ -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)
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] chardev: check return value of kobject_set_name() in __register_chrdev()
2026-08-26 5:20 [PATCH] chardev: check return value of kobject_set_name() in __register_chrdev() phucduc.bui
@ 2026-08-26 16:24 ` Jan Kara
2026-08-27 4:41 ` Bui Duc Phuc
0 siblings, 1 reply; 3+ messages in thread
From: Jan Kara @ 2026-08-26 16:24 UTC (permalink / raw)
To: phucduc.bui
Cc: Alexander Viro, Christian Brauner, Jan Kara, linux-fsdevel,
linux-kernel
On Wed 26-08-26 12:20:55, phucduc.bui@gmail.com wrote:
> From: bui duc phuc <phucduc.bui@gmail.com>
>
> 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.
>
> Signed-off-by: bui duc phuc <phucduc.bui@gmail.com>
Looks good. Feel free to add:
Reviewed-by: Jan Kara <jack@suse.cz>
Honza
> ---
> fs/char_dev.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/fs/char_dev.c b/fs/char_dev.c
> index 00229e25c10f..5ce5423f6c99 100644
> --- a/fs/char_dev.c
> +++ b/fs/char_dev.c
> @@ -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)
> --
> 2.43.0
>
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] chardev: check return value of kobject_set_name() in __register_chrdev()
2026-08-26 16:24 ` Jan Kara
@ 2026-08-27 4:41 ` Bui Duc Phuc
0 siblings, 0 replies; 3+ messages in thread
From: Bui Duc Phuc @ 2026-08-27 4:41 UTC (permalink / raw)
To: Jan Kara; +Cc: Alexander Viro, Christian Brauner, linux-fsdevel, linux-kernel
Hi Jan,
Thank you for your review.
>
> Looks good. Feel free to add:
>
> Reviewed-by: Jan Kara <jack@suse.cz>
>
Best regards,
Phuc
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-08-27 4:41 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-26 5:20 [PATCH] chardev: check return value of kobject_set_name() in __register_chrdev() phucduc.bui
2026-08-26 16:24 ` Jan Kara
2026-08-27 4:41 ` Bui Duc Phuc
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox