From: Sreeraj S Kurup <sreekuttan2156239@gmail.com>
To: perex@perex.cz, tiwai@suse.de
Cc: linux-kernel@vger.kernel.org, linux-sound@vger.kernel.org,
Sreeraj S Kurup <sreekuttan2156239@gmail.com>
Subject: [PATCH] sound: core: Check return value of device_create()
Date: Mon, 23 Nov 2026 10:05:35 +0000 [thread overview]
Message-ID: <20261123100535.3025-1-sreekuttan2156239@gmail.com> (raw)
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
reply other threads:[~2026-11-23 10:06 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261123100535.3025-1-sreekuttan2156239@gmail.com \
--to=sreekuttan2156239@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=perex@perex.cz \
--cc=tiwai@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®