summaryrefslogtreecommitdiff
path: root/sound/pci/hda/hda_codec.h
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2015-02-27 19:43:19 +0300
committerTakashi Iwai <tiwai@suse.de>2015-03-03 13:26:24 +0300
commitbbbc7e8502c95237dbd86cc4d0a12ca9a6b18c8f (patch)
tree71d5973b321c194ca5b9fd76592844eb37c4c9ed /sound/pci/hda/hda_codec.h
parentf4de8fe6cffb449a779dff61f071bd1af9e18e0f (diff)
downloadlinux-bbbc7e8502c95237dbd86cc4d0a12ca9a6b18c8f.tar.xz
ALSA: hda - Allocate hda_pcm objects dynamically
So far, the hda_codec object kept the hda_pcm list in an array, and the codec driver was expected to assign the array. However, this makes the object life cycle management harder, because the assigned array is freed at the codec driver detach while it might be still accessed by the opened streams. In this patch, we allocate each hda_pcm object dynamically and manage it as a linked list. Each object has a kref refcount, and both the codec driver binder and the PCM open/close touches it, so that the object won't be freed while in use. Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/pci/hda/hda_codec.h')
-rw-r--r--sound/pci/hda/hda_codec.h18
1 files changed, 16 insertions, 2 deletions
diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h
index 8908a0768736..2ccd6f9a91fe 100644
--- a/sound/pci/hda/hda_codec.h
+++ b/sound/pci/hda/hda_codec.h
@@ -21,6 +21,7 @@
#ifndef __SOUND_HDA_CODEC_H
#define __SOUND_HDA_CODEC_H
+#include <linux/kref.h>
#include <sound/info.h>
#include <sound/control.h>
#include <sound/pcm.h>
@@ -268,6 +269,10 @@ struct hda_pcm {
int device; /* device number to assign */
struct snd_pcm *pcm; /* assigned PCM instance */
bool own_chmap; /* codec driver provides own channel maps */
+ /* private: */
+ struct hda_codec *codec;
+ struct kref kref;
+ struct list_head list;
};
/* codec information */
@@ -301,8 +306,7 @@ struct hda_codec {
struct hda_codec_ops patch_ops;
/* PCM to create, set by patch_ops.build_pcms callback */
- unsigned int num_pcms;
- struct hda_pcm *pcm_info;
+ struct list_head pcm_list_head;
/* codec specific info */
void *spec;
@@ -521,6 +525,16 @@ int snd_hda_build_pcms(struct hda_bus *bus);
int snd_hda_codec_parse_pcms(struct hda_codec *codec);
int snd_hda_codec_build_pcms(struct hda_codec *codec);
+__printf(2, 3)
+struct hda_pcm *snd_hda_codec_pcm_new(struct hda_codec *codec,
+ const char *fmt, ...);
+
+static inline void snd_hda_codec_pcm_get(struct hda_pcm *pcm)
+{
+ kref_get(&pcm->kref);
+}
+void snd_hda_codec_pcm_put(struct hda_pcm *pcm);
+
int snd_hda_codec_prepare(struct hda_codec *codec,
struct hda_pcm_stream *hinfo,
unsigned int stream,