diff options
author | Takashi Iwai <tiwai@suse.de> | 2008-07-30 09:01:44 -0400 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2008-10-12 20:42:59 -0400 |
commit | 603c40199252f0c3b91fca02fd3283c4f8e55179 (patch) | |
tree | dbd8643b288a1d3088d6f5af30e58d699e2761b4 /sound/pci/hda/hda_codec.c | |
parent | b2e1859745b783922533d29e3b03af29378a23f0 (diff) |
ALSA: hda - Use generic array helpers
Use generic array helpers to simplify array handling in snd-hda-intel.
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/pci/hda/hda_codec.c')
-rw-r--r-- | sound/pci/hda/hda_codec.c | 38 |
1 files changed, 9 insertions, 29 deletions
diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c index e70303183c3c..39a49d4a864a 100644 --- a/sound/pci/hda/hda_codec.c +++ b/sound/pci/hda/hda_codec.c | |||
@@ -756,12 +756,12 @@ static void __devinit init_hda_cache(struct hda_cache_rec *cache, | |||
756 | { | 756 | { |
757 | memset(cache, 0, sizeof(*cache)); | 757 | memset(cache, 0, sizeof(*cache)); |
758 | memset(cache->hash, 0xff, sizeof(cache->hash)); | 758 | memset(cache->hash, 0xff, sizeof(cache->hash)); |
759 | cache->record_size = record_size; | 759 | snd_array_init(&cache->buf, record_size, 64); |
760 | } | 760 | } |
761 | 761 | ||
762 | static void free_hda_cache(struct hda_cache_rec *cache) | 762 | static void free_hda_cache(struct hda_cache_rec *cache) |
763 | { | 763 | { |
764 | kfree(cache->buffer); | 764 | snd_array_free(&cache->buf); |
765 | } | 765 | } |
766 | 766 | ||
767 | /* query the hash. allocate an entry if not found. */ | 767 | /* query the hash. allocate an entry if not found. */ |
@@ -770,38 +770,18 @@ static struct hda_cache_head *get_alloc_hash(struct hda_cache_rec *cache, | |||
770 | { | 770 | { |
771 | u16 idx = key % (u16)ARRAY_SIZE(cache->hash); | 771 | u16 idx = key % (u16)ARRAY_SIZE(cache->hash); |
772 | u16 cur = cache->hash[idx]; | 772 | u16 cur = cache->hash[idx]; |
773 | struct hda_cache_head *info_head = cache->buf.list; | ||
773 | struct hda_cache_head *info; | 774 | struct hda_cache_head *info; |
774 | 775 | ||
775 | while (cur != 0xffff) { | 776 | while (cur != 0xffff) { |
776 | info = (struct hda_cache_head *)(cache->buffer + | 777 | info = &info_head[cur]; |
777 | cur * cache->record_size); | ||
778 | if (info->key == key) | 778 | if (info->key == key) |
779 | return info; | 779 | return info; |
780 | cur = info->next; | 780 | cur = info->next; |
781 | } | 781 | } |
782 | 782 | ||
783 | /* add a new hash entry */ | 783 | /* add a new hash entry */ |
784 | if (cache->num_entries >= cache->size) { | 784 | info = snd_array_new(&cache->buf); |
785 | /* reallocate the array */ | ||
786 | unsigned int new_size = cache->size + 64; | ||
787 | void *new_buffer; | ||
788 | new_buffer = kcalloc(new_size, cache->record_size, GFP_KERNEL); | ||
789 | if (!new_buffer) { | ||
790 | snd_printk(KERN_ERR "hda_codec: " | ||
791 | "can't malloc amp_info\n"); | ||
792 | return NULL; | ||
793 | } | ||
794 | if (cache->buffer) { | ||
795 | memcpy(new_buffer, cache->buffer, | ||
796 | cache->size * cache->record_size); | ||
797 | kfree(cache->buffer); | ||
798 | } | ||
799 | cache->size = new_size; | ||
800 | cache->buffer = new_buffer; | ||
801 | } | ||
802 | cur = cache->num_entries++; | ||
803 | info = (struct hda_cache_head *)(cache->buffer + | ||
804 | cur * cache->record_size); | ||
805 | info->key = key; | 785 | info->key = key; |
806 | info->val = 0; | 786 | info->val = 0; |
807 | info->next = cache->hash[idx]; | 787 | info->next = cache->hash[idx]; |
@@ -942,10 +922,10 @@ int snd_hda_codec_amp_stereo(struct hda_codec *codec, hda_nid_t nid, | |||
942 | /* resume the all amp commands from the cache */ | 922 | /* resume the all amp commands from the cache */ |
943 | void snd_hda_codec_resume_amp(struct hda_codec *codec) | 923 | void snd_hda_codec_resume_amp(struct hda_codec *codec) |
944 | { | 924 | { |
945 | struct hda_amp_info *buffer = codec->amp_cache.buffer; | 925 | struct hda_amp_info *buffer = codec->amp_cache.buf.list; |
946 | int i; | 926 | int i; |
947 | 927 | ||
948 | for (i = 0; i < codec->amp_cache.size; i++, buffer++) { | 928 | for (i = 0; i < codec->amp_cache.buf.used; i++, buffer++) { |
949 | u32 key = buffer->head.key; | 929 | u32 key = buffer->head.key; |
950 | hda_nid_t nid; | 930 | hda_nid_t nid; |
951 | unsigned int idx, dir, ch; | 931 | unsigned int idx, dir, ch; |
@@ -1779,10 +1759,10 @@ int snd_hda_codec_write_cache(struct hda_codec *codec, hda_nid_t nid, | |||
1779 | /* resume the all commands from the cache */ | 1759 | /* resume the all commands from the cache */ |
1780 | void snd_hda_codec_resume_cache(struct hda_codec *codec) | 1760 | void snd_hda_codec_resume_cache(struct hda_codec *codec) |
1781 | { | 1761 | { |
1782 | struct hda_cache_head *buffer = codec->cmd_cache.buffer; | 1762 | struct hda_cache_head *buffer = codec->cmd_cache.buf.list; |
1783 | int i; | 1763 | int i; |
1784 | 1764 | ||
1785 | for (i = 0; i < codec->cmd_cache.size; i++, buffer++) { | 1765 | for (i = 0; i < codec->cmd_cache.buf.used; i++, buffer++) { |
1786 | u32 key = buffer->key; | 1766 | u32 key = buffer->key; |
1787 | if (!key) | 1767 | if (!key) |
1788 | continue; | 1768 | continue; |