[alsa-devel] [PATCH 03/14] ALSA: Add a helper to initialize device

Takashi Iwai tiwai at suse.de
Mon Feb 2 11:24:27 CET 2015


Introduce a new helper function snd_device_initialize() to initialize
the device object for sound devices.

Signed-off-by: Takashi Iwai <tiwai at suse.de>
---
 include/sound/core.h |  2 ++
 sound/core/init.c    | 19 +++++++++++++++++++
 2 files changed, 21 insertions(+)

diff --git a/include/sound/core.h b/include/sound/core.h
index 39d14234961d..de7a878217d7 100644
--- a/include/sound/core.h
+++ b/include/sound/core.h
@@ -207,6 +207,8 @@ extern struct class *sound_class;
 
 void snd_request_card(int card);
 
+void snd_device_initialize(struct device *dev, struct snd_card *card);
+
 int snd_register_device_for_dev(int type, struct snd_card *card, int dev,
 				const struct file_operations *f_ops,
 				void *private_data, struct device *device,
diff --git a/sound/core/init.c b/sound/core/init.c
index 074875d68c15..2f730efe97b6 100644
--- a/sound/core/init.c
+++ b/sound/core/init.c
@@ -157,6 +157,25 @@ static int get_slot_from_bitmask(int mask, int (*check)(struct module *, int),
 	return mask; /* unchanged */
 }
 
+static void default_release(struct device *dev)
+{
+}
+
+/**
+ * snd_device_initialize - Initialize struct device for sound devices
+ * @dev: device to initialize
+ * @card: card to assign, optional
+ */
+void snd_device_initialize(struct device *dev, struct snd_card *card)
+{
+	device_initialize(dev);
+	if (card)
+		dev->parent = &card->card_dev;
+	dev->class = sound_class;
+	dev->release = default_release;
+}
+EXPORT_SYMBOL_GPL(snd_device_initialize);
+
 static int snd_card_do_free(struct snd_card *card);
 static const struct attribute_group *card_dev_attr_groups[];
 
-- 
2.2.2



More information about the Alsa-devel mailing list