summaryrefslogtreecommitdiff
path: root/sys/dev/pci/azalia.c
diff options
context:
space:
mode:
authorJacob Meuser <jakemsr@cvs.openbsd.org>2009-10-11 06:45:47 +0000
committerJacob Meuser <jakemsr@cvs.openbsd.org>2009-10-11 06:45:47 +0000
commit0ac4ee24fd18d5a19768920e53edc59ed16988ee (patch)
treeff4d572e419e80906ae67f784bb816d190b24d07 /sys/dev/pci/azalia.c
parent06ea40a166dbf8a68f6d6ab5bd8627774729e6cd (diff)
* define a constant for the specification defined maximum number of
codecs a controller can support * dynamically allocate memory for the array of codec structures
Diffstat (limited to 'sys/dev/pci/azalia.c')
-rw-r--r--sys/dev/pci/azalia.c25
1 files changed, 20 insertions, 5 deletions
diff --git a/sys/dev/pci/azalia.c b/sys/dev/pci/azalia.c
index 76e5964eb95..749e15a0d9d 100644
--- a/sys/dev/pci/azalia.c
+++ b/sys/dev/pci/azalia.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: azalia.c,v 1.156 2009/10/11 00:59:37 jakemsr Exp $ */
+/* $OpenBSD: azalia.c,v 1.157 2009/10/11 06:45:46 jakemsr Exp $ */
/* $NetBSD: azalia.c,v 1.20 2006/05/07 08:31:44 kent Exp $ */
/*-
@@ -149,7 +149,7 @@ typedef struct azalia_t {
pcireg_t pciid;
uint32_t subid;
- codec_t codecs[15];
+ codec_t *codecs;
int ncodecs; /* number of codecs */
int codecno; /* index of the using codec */
@@ -545,6 +545,10 @@ azalia_pci_detach(struct device *self, int flags)
azalia_codec_delete(&az->codecs[i]);
}
az->ncodecs = 0;
+ if (az->codecs != NULL) {
+ free(az->codecs, M_DEVBUF);
+ az->codecs = NULL;
+ }
DPRINTF(("%s: delete CORB and RIRB\n", __func__));
azalia_delete_corb(az);
@@ -693,11 +697,10 @@ azalia_get_ctrlr_caps(azalia_t *az)
/* 4.3 Codec discovery */
statests = AZ_READ_2(az, STATESTS);
- for (i = 0, n = 0; i < 15; i++) {
+ for (i = 0, n = 0; i < HDA_MAX_CODECS; i++) {
if ((statests >> i) & 1) {
DPRINTF(("%s: found a codec at #%d\n", XNAME(az), i));
- az->codecs[n].address = i;
- az->codecs[n++].az = az;
+ n++;
}
}
az->ncodecs = n;
@@ -705,6 +708,18 @@ azalia_get_ctrlr_caps(azalia_t *az)
printf("%s: no HD-Audio codecs\n", XNAME(az));
return -1;
}
+ az->codecs = malloc(sizeof(codec_t) * az->ncodecs, M_DEVBUF,
+ M_NOWAIT | M_ZERO);
+ if (az->codecs == NULL) {
+ printf("%s: can't allocate memory for codecs\n", XNAME(az));
+ return ENOMEM;
+ }
+ for (i = 0, n = 0; n < az->ncodecs; i++) {
+ if ((statests >> i) & 1) {
+ az->codecs[n].address = i;
+ az->codecs[n++].az = az;
+ }
+ }
/* determine CORB size */
az->corbsize = AZ_READ_1(az, CORBSIZE);