sound: core: Check return value of device_create()
PATCH 1/1 sound: core: Check return value of device_create()
The sound_insert_unit() function ignores the return value of device_create(). If device creation fails, the function still returns the allocated minor number as if registration succeeded.
Add a helper function, sound_device_create(), to create the sound device and check the return value using PTR_ERR_OR_ZERO().
If device creation fails, remove the allocated sound unit from the sound loader list, unregister the character device when preclaim_oss is disabled, and free the allocated memory.
Return the original error code to the caller instead of reporting successful registration.
Signed-off-by Sreeraj S Kurup <[email protected]>
--- sound/sound_core.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-)
sound/sound_core.c +27 -2
@@ -231,6 +231,21 @@ static struct sound_unit *__sound_remove_unit(struct sound_unit **list, int unitstatic DEFINE_SPINLOCK (sound_loader_lock); +/* +* Create the sound device and return an error if device creation fails. +*/ + +static int sound_device_create (struct sound_unit *s,struct device *dev) +{ +struct device *device; + + device =device_create (&sound_class, dev, +MKDEV (SOUND_MAJOR , s->unit_minor), +NULL ,"%s" , s->name +6 ); + +return PTR_ERR_OR_ZERO (device); +} +/* * Allocate the controlling structure and add it to the sound driver * list. Acquires locks as needed
@@ -277,10 +292,20 @@ static int sound_insert_unit(struct sound_unit **list, const struct file_operati } } -device_create (&sound_class, dev,MKDEV (SOUND_MAJOR , s->unit_minor), -NULL ,"%s" , s->name+6 ); + r =sound_device_create (s, dev); +if (r) + goto err_remove_unit; +return s->unit_minor; +err_remove_unit: +if (!preclaim_oss) +__unregister_chrdev (SOUND_MAJOR , s->unit_minor,1 , s->name); + +spin_lock (&sound_loader_lock); +__sound_remove_unit (list, s->unit_minor); +spin_unlock (&sound_loader_lock); + fail:kfree (s);return r;
Signature · 1 line
2.55.0