diff options
| author | enami <enami@NetBSD.org> | 2004-10-15 00:48:53 +0000 |
|---|---|---|
| committer | enami <enami@NetBSD.org> | 2004-10-15 00:48:53 +0000 |
| commit | d5e42fa312632b23bd2eb076635d7a3e5d61e739 (patch) | |
| tree | 91df0dd71bcf210500235082895ab257ad4a0f49 /sys/dev | |
| parent | d10ffa8c6e10c96203cac91cdd3042b2ad9a74d8 (diff) | |
- Don't change the matching logic.
- Prepare to describe a card which has NULL CIS string.
- Factor out common code.
- Deal with malloc return value.
Diffstat (limited to 'sys/dev')
| -rw-r--r-- | sys/dev/pcmcia/pcmcia_cis_quirks.c | 75 |
1 files changed, 44 insertions, 31 deletions
diff --git a/sys/dev/pcmcia/pcmcia_cis_quirks.c b/sys/dev/pcmcia/pcmcia_cis_quirks.c index 2ced452183a..fa7f3999efc 100644 --- a/sys/dev/pcmcia/pcmcia_cis_quirks.c +++ b/sys/dev/pcmcia/pcmcia_cis_quirks.c @@ -1,4 +1,4 @@ -/* $NetBSD: pcmcia_cis_quirks.c,v 1.22 2004/10/14 00:17:12 christos Exp $ */ +/* $NetBSD: pcmcia_cis_quirks.c,v 1.23 2004/10/15 00:48:53 enami Exp $ */ /* * Copyright (c) 1998 Marc Horowitz. All rights reserved. @@ -30,11 +30,12 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: pcmcia_cis_quirks.c,v 1.22 2004/10/14 00:17:12 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pcmcia_cis_quirks.c,v 1.23 2004/10/15 00:48:53 enami Exp $"); #include <sys/param.h> #include <sys/systm.h> #include <sys/device.h> +#include <sys/kernel.h> #include <sys/mbuf.h> #include <dev/pcmcia/pcmciadevs.h> @@ -247,7 +248,8 @@ static const struct pcmcia_cis_quirk pcmcia_cis_quirks[] = { static const int pcmcia_cis_nquirks = sizeof(pcmcia_cis_quirks) / sizeof(pcmcia_cis_quirks[0]); -void pcmcia_check_cis_quirks(sc) +void +pcmcia_check_cis_quirks(sc) struct pcmcia_softc *sc; { int wiped = 0; @@ -256,29 +258,32 @@ void pcmcia_check_cis_quirks(sc) const struct pcmcia_function *pf_last; struct pcmcia_config_entry *cfe; struct pcmcia_card *card = &sc->card; + const struct pcmcia_cis_quirk *quirk; pf = NULL; pf_last = NULL; for (i = 0; i < pcmcia_cis_nquirks; i++) { + quirk = &pcmcia_cis_quirks[i]; - if (card->manufacturer != pcmcia_cis_quirks[i].manufacturer && - card->manufacturer != PCMCIA_VENDOR_INVALID) - continue; - - if (card->product != pcmcia_cis_quirks[i].product && + if (card->manufacturer == quirk->manufacturer && + card->manufacturer != PCMCIA_VENDOR_INVALID && + card->product == quirk->product && card->product != PCMCIA_PRODUCT_INVALID) - continue; + goto match; for (j = 0; j < 2; j++) - if (card->cis1_info[j] == NULL || - pcmcia_cis_quirks[i].cis1_info[j] == NULL || - strcmp(card->cis1_info[j], - pcmcia_cis_quirks[i].cis1_info[j]) != 0) - break; - if (j != 2) - continue; + if (card->cis1_info[j] == NULL) { + if (quirk->cis1_info[j] != NULL) + goto nomatch; + } else { + if (quirk->cis1_info[j] == NULL || + strcmp(card->cis1_info[j], + quirk->cis1_info[j]) != 0) + goto nomatch; + } +match: if (!wiped) { if (pcmcia_verbose) { printf("%s: using CIS quirks for ", @@ -296,23 +301,31 @@ void pcmcia_check_cis_quirks(sc) wiped = 1; } - if (pf_last == pcmcia_cis_quirks[i].pf) { - cfe = malloc(sizeof(*cfe), M_DEVBUF, M_NOWAIT); - *cfe = *pcmcia_cis_quirks[i].cfe; - - SIMPLEQ_INSERT_TAIL(&pf->cfe_head, cfe, cfe_list); - } else { - pf = malloc(sizeof(*pf), M_DEVBUF, M_NOWAIT); - *pf = *pcmcia_cis_quirks[i].pf; + if (pf_last != quirk->pf) { + /* + * XXX: a driver which still calls pcmcia_card_attach + * very early attach stage should be fixed instead. + */ + pf = malloc(sizeof(*pf), M_DEVBUF, + cold ? M_NOWAIT : M_WAITOK); + if (pf == NULL) + panic("pcmcia_check_cis_quirks: malloc pf"); + *pf = *quirk->pf; SIMPLEQ_INIT(&pf->cfe_head); - - cfe = malloc(sizeof(*cfe), M_DEVBUF, M_NOWAIT); - *cfe = *pcmcia_cis_quirks[i].cfe; - - SIMPLEQ_INSERT_TAIL(&pf->cfe_head, cfe, cfe_list); SIMPLEQ_INSERT_TAIL(&card->pf_head, pf, pf_list); - - pf_last = pcmcia_cis_quirks[i].pf; + pf_last = quirk->pf; } + + /* + * XXX: see above. + */ + cfe = malloc(sizeof(*cfe), M_DEVBUF, + cold ? M_NOWAIT : M_WAITOK); + if (cfe == NULL) + panic("pcmcia_check_cis_quirks: malloc cfe"); + *cfe = *quirk->cfe; + SIMPLEQ_INSERT_TAIL(&pf->cfe_head, cfe, cfe_list); + +nomatch:; } } |
