ALSA: Add a helper to initialize device
authorTakashi Iwai <tiwai@suse.de>
Thu, 29 Jan 2015 20:32:47 +0000 (21:32 +0100)
committerTakashi Iwai <tiwai@suse.de>
Mon, 2 Feb 2015 13:42:33 +0000 (14:42 +0100)
Introduce a new helper function snd_device_initialize() to initialize
the device object for sound devices.

Reviewed-by: Jaroslav Kysela <perex@perex.cz>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
include/sound/core.h
sound/core/init.c

index 39d14234961d954df32bf347220d7ffd55975e02..de7a878217d7e9c2d3806478334293827b8398e0 100644 (file)
@@ -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,
index 074875d68c156745519987f24d22058ca4c398b4..96194599e82e70643424941b2bd5e7c60e2fc77e 100644 (file)
@@ -157,6 +157,29 @@ static int get_slot_from_bitmask(int mask, int (*check)(struct module *, int),
        return mask; /* unchanged */
 }
 
+/* the default release callback set in snd_device_initialize() below;
+ * this is just NOP for now, as almost all jobs are already done in
+ * dev_free callback of snd_device chain instead.
+ */
+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[];