summaryrefslogtreecommitdiff
path: root/sound/core
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2023-08-16 18:02:44 +0200
committerTakashi Iwai <tiwai@suse.de>2023-08-17 09:21:40 +0200
commit7f018db19bf7cb5ba3e39ed9e51c8c5f2488dfb0 (patch)
tree6f83f35d239d1d79cd52e736ad77e317d6725b9e /sound/core
parent2e6f979037d5ae35c0ed38e2b63e9876eb7bc65f (diff)
ALSA: core: Introduce snd_device_alloc()
Introduce a new helper, snd_device_alloc(), for allocating a struct device that is bound with the sound class. It's a replacement of snd_device_initialize(). Reviewed-by: Jaroslav Kysela <perex@perex.cz> Signed-off-by: Curtis Malainey <cujomalainey@chromium.org> Tested-by: Curtis Malainey <cujomalainey@chromium.org> Link: https://lore.kernel.org/r/20230816160252.23396-2-tiwai@suse.de Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/core')
-rw-r--r--sound/core/init.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/sound/core/init.c b/sound/core/init.c
index baef2688d0cf..a4de9f00d90f 100644
--- a/sound/core/init.c
+++ b/sound/core/init.c
@@ -134,6 +134,37 @@ void snd_device_initialize(struct device *dev, struct snd_card *card)
}
EXPORT_SYMBOL_GPL(snd_device_initialize);
+/* the default release callback set in snd_device_alloc() */
+static void default_release_alloc(struct device *dev)
+{
+ kfree(dev);
+}
+
+/**
+ * snd_device_alloc - Allocate and initialize struct device for sound devices
+ * @dev_p: pointer to store the allocated device
+ * @card: card to assign, optional
+ *
+ * For releasing the allocated device, call put_device().
+ */
+int snd_device_alloc(struct device **dev_p, struct snd_card *card)
+{
+ struct device *dev;
+
+ *dev_p = NULL;
+ dev = kzalloc(sizeof(*dev), GFP_KERNEL);
+ if (!dev)
+ return -ENOMEM;
+ device_initialize(dev);
+ if (card)
+ dev->parent = &card->card_dev;
+ dev->class = &sound_class;
+ dev->release = default_release_alloc;
+ *dev_p = dev;
+ return 0;
+}
+EXPORT_SYMBOL_GPL(snd_device_alloc);
+
static int snd_card_init(struct snd_card *card, struct device *parent,
int idx, const char *xid, struct module *module,
size_t extra_size);