* Proper error-handling of cdev_add() after cdev_alloc() ?
@ 2026-05-12 8:20 Philipp Matthias Hahn
0 siblings, 0 replies; only message in thread
From: Philipp Matthias Hahn @ 2026-05-12 8:20 UTC (permalink / raw)
To: Kernel Mailing List
Hello,
How should errors of `cdev_add()` after `cdev_alloc()` be handled?
The basic schema seems to be like this:
cdev = cdev_alloc();
if (!cdev)
return -ENOMEM;
...
ret = cdev_add(cdev, ...);
if (ret < 0) {
/* WHAT HERE ??? */
return ret;
}
...
return 0; // success
I found 5 case of how errors are handled:
1. kfree(cdev);
drivers/media/v4l2-core/v4l2-dev.c:1060
2. kobject_put(&cdev->kobj);
drivers/char/xillybus/xillybus_class.c:107
fs/char_dev.c:293
drivers/s390/char/vmlogrdr.c:780
drivers/tty/tty_io.c:3171
drivers/uio/uio.c:925
3. cdev_del(cdev);
drivers/char/virtio_console.c:1435
fs/fuse/cuse.c:419
drivers/misc/mei/main.c:1318
drivers/s390/char/tape_class.c:92
drivers/s390/char/vmur.c:928
drivers/scsi/sg.c:1560
drivers/scsi/st.c:4307
drivers/staging/vme_user/vme_user.c:694
4. No error handling at all.
arch/sh/boards/mach-landisk/gio.c:145
5. panic()
Currently I'm unsure of what's the correct way.
My current understanding is, that `cdev_del()` should only be called if
`cdev_add()` succeeded, so those 8 findings above should be fixed. But
to what?
Thank you in advance
Philipp
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-05-12 8:28 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-12 8:20 Proper error-handling of cdev_add() after cdev_alloc() ? Philipp Matthias Hahn
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox