* [PATCH] sound: core: Check return value of device_create()
@ 2026-11-23 10:05 Sreeraj S Kurup
0 siblings, 0 replies; only message in thread
From: Sreeraj S Kurup @ 2026-11-23 10:05 UTC (permalink / raw)
To: perex, tiwai; +Cc: linux-kernel, linux-sound, Sreeraj S Kurup
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 <sreekuttan2156239@gmail.com>
---
sound/sound_core.c | 29 +++++++++++++++++++++++++++--
1 file changed, 27 insertions(+), 2 deletions(-)
diff --git a/sound/sound_core.c b/sound/sound_core.c
index 10db8c699630..90d59b14245d 100644
--- a/sound/sound_core.c
+++ b/sound/sound_core.c
@@ -231,6 +231,21 @@ static struct sound_unit *__sound_remove_unit(struct sound_unit **list, int unit
static 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;
--
2.55.0
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-23 10:06 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-23 10:05 [PATCH] sound: core: Check return value of device_create() Sreeraj S Kurup
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®