From a3e2432858c990d9e166a41f8ebcd375d31c541c Mon Sep 17 00:00:00 2001 From: Warner Losh Date: Tue, 12 Apr 2005 04:30:35 +0000 Subject: Use return value of resource_list_add to avoid a second resource_list_find. Check to make sure that rle is not NULL and panic if it is (but it appears that resource_list_add already panics, so I'm not entirely sure it is necessary now). Add a test to make sure we have a interrupt resource when we're disabling it. This is also a cannot happen, but the extra care shoudln't hurt. Found by: Coventry tool via sam@ --- sys/dev/pccard/pccard.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'sys/dev') diff --git a/sys/dev/pccard/pccard.c b/sys/dev/pccard/pccard.c index 716a2608d79dc..22cde46777100 100644 --- a/sys/dev/pccard/pccard.c +++ b/sys/dev/pccard/pccard.c @@ -453,11 +453,12 @@ pccard_function_init(struct pccard_function *pf) rman_make_alignment_flags(cfe->iospace[i].length)); if (cfe->iores[i] == NULL) goto not_this_one; - resource_list_add(rl, SYS_RES_IOPORT, cfe->iorid[i], - rman_get_start(r), rman_get_end(r), + rle = resource_list_add(rl, SYS_RES_IOPORT, + cfe->iorid[i], rman_get_start(r), rman_get_end(r), cfe->iospace[i].length); - rle = resource_list_find(rl, SYS_RES_IOPORT, - cfe->iorid[i]); + if (rle == NULL) + panic("Cannot add resource rid %d IOPORT", + cfe->iorid[i]); rle->res = r; spaces++; } @@ -477,10 +478,11 @@ pccard_function_init(struct pccard_function *pf) SYS_RES_IRQ, &cfe->irqrid, 0); if (cfe->irqres == NULL) goto not_this_one; - resource_list_add(rl, SYS_RES_IRQ, cfe->irqrid, + rle = resource_list_add(rl, SYS_RES_IRQ, cfe->irqrid, rman_get_start(r), rman_get_end(r), 1); - rle = resource_list_find(rl, SYS_RES_IRQ, - cfe->irqrid); + if (rle == NULL) + panic("Cannot add resource rid %d IRQ", + cfe->irqrid); rle->res = r; } /* If we get to here, we've allocated all we need */ @@ -733,6 +735,8 @@ pccard_function_disable(struct pccard_function *pf) struct pccard_ivar *devi = PCCARD_IVAR(pf->dev); struct resource_list_entry *rle = resource_list_find(&devi->resources, SYS_RES_IRQ, 0); + if (rle == NULL) + panic("Can't disable an interrupt with no IRQ res\n"); BUS_TEARDOWN_INTR(dev, pf->dev, rle->res, pf->intr_handler_cookie); } -- cgit v1.3