Skip to content

Commit 4b440be

Browse files
committed
ALSA: Add a helper to initialize device
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>
1 parent 23c18d4 commit 4b440be

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

‎include/sound/core.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ extern struct class *sound_class;
207207

208208
void snd_request_card(int card);
209209

210+
void snd_device_initialize(struct device *dev, struct snd_card *card);
211+
210212
int snd_register_device_for_dev(int type, struct snd_card *card, int dev,
211213
const struct file_operations *f_ops,
212214
void *private_data, struct device *device,

‎sound/core/init.c‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,29 @@ static int get_slot_from_bitmask(int mask, int (*check)(struct module *, int),
157157
return mask; /* unchanged */
158158
}
159159

160+
/* the default release callback set in snd_device_initialize() below;
161+
* this is just NOP for now, as almost all jobs are already done in
162+
* dev_free callback of snd_device chain instead.
163+
*/
164+
static void default_release(struct device *dev)
165+
{
166+
}
167+
168+
/**
169+
* snd_device_initialize - Initialize struct device for sound devices
170+
* @dev: device to initialize
171+
* @card: card to assign, optional
172+
*/
173+
void snd_device_initialize(struct device *dev, struct snd_card *card)
174+
{
175+
device_initialize(dev);
176+
if (card)
177+
dev->parent = &card->card_dev;
178+
dev->class = sound_class;
179+
dev->release = default_release;
180+
}
181+
EXPORT_SYMBOL_GPL(snd_device_initialize);
182+
160183
static int snd_card_do_free(struct snd_card *card);
161184
static const struct attribute_group *card_dev_attr_groups[];
162185

0 commit comments

Comments
 (0)