Skip to content

Commit

Permalink
ALSA: hda - Fix another cache list management
Browse files Browse the repository at this point in the history
Fix another silly bug in the amp cache list management.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
  • Loading branch information
Takashi Iwai committed Nov 10, 2008
1 parent 0edb945 commit f43aa02
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
7 changes: 3 additions & 4 deletions sound/pci/hda/hda_codec.c
Original file line number Diff line number Diff line change
Expand Up @@ -887,11 +887,10 @@ static struct hda_cache_head *get_alloc_hash(struct hda_cache_rec *cache,
{
u16 idx = key % (u16)ARRAY_SIZE(cache->hash);
u16 cur = cache->hash[idx];
struct hda_cache_head *info_head = cache->buf.list;
struct hda_cache_head *info;

while (cur != 0xffff) {
info = &info_head[cur];
info = snd_array_elem(&cache->buf, cur);
if (info->key == key)
return info;
cur = info->next;
Expand All @@ -901,7 +900,7 @@ static struct hda_cache_head *get_alloc_hash(struct hda_cache_rec *cache,
info = snd_array_new(&cache->buf);
if (!info)
return NULL;
cur = cache->buf.used - 1; /* the last entry */
cur = snd_array_index(&cache->buf, info);
info->key = key;
info->val = 0;
info->next = cache->hash[idx];
Expand Down Expand Up @@ -3414,7 +3413,7 @@ void *snd_array_new(struct snd_array *array)
array->list = nlist;
array->alloced = num;
}
return array->list + (array->used++ * array->elem_size);
return snd_array_elem(array, array->used++);
}

/* free the given array elements */
Expand Down
10 changes: 10 additions & 0 deletions sound/pci/hda/hda_codec.h
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,16 @@ static inline void snd_array_init(struct snd_array *array, unsigned int size,
array->alloc_align = align;
}

static inline void *snd_array_elem(struct snd_array *array, unsigned int idx)
{
return array->list + idx * array->elem_size;
}

static inline unsigned int snd_array_index(struct snd_array *array, void *ptr)
{
return (unsigned long)(ptr - array->list) / array->elem_size;
}

/*
* Structures
*/
Expand Down

0 comments on commit f43aa02

Please sign in to comment.