From: Matthew Wilcox <matthew@wil.cx>
To: linux-scsi@vger.kernel.org
Cc: Matthew Wilcox <matthew@wil.cx>
Subject: [PATCH 8/21] advansys: Rewrite resource management
Date: Thu, 26 Jul 2007 13:22:44 -0400 [thread overview]
Message-ID: <11854705773172-git-send-email-matthew@wil.cx> (raw)
In-Reply-To: 20070726171141.GE19275@parisc-linux.org
In-Reply-To: <20070726171141.GE19275@parisc-linux.org>
Make sure the resources are reserved and released by all the callers of
advansys_board_found(). This eliminates the check_region-style race.
It also allows us to use the pci_request_regions() API.
Signed-off-by: Matthew Wilcox <matthew@wil.cx>
---
drivers/scsi/advansys.c | 103 +++++++++++++++++++---------------------------
1 files changed, 43 insertions(+), 60 deletions(-)
diff --git a/drivers/scsi/advansys.c b/drivers/scsi/advansys.c
index 48dc28d..a4d3372 100644
--- a/drivers/scsi/advansys.c
+++ b/drivers/scsi/advansys.c
@@ -1935,7 +1935,6 @@ static int AscCompareString(uchar *, uchar *, int);
#ifdef CONFIG_ISA
static ushort AscGetEisaChipCfg(PortAddr);
static PortAddr AscSearchIOPortAddr11(PortAddr);
-static PortAddr AscSearchIOPortAddr(PortAddr, ushort);
static void AscSetISAPNPWaitForKey(void);
#endif /* CONFIG_ISA */
static uchar AscGetChipScsiCtrl(PortAddr);
@@ -8261,7 +8260,7 @@ static PortAddr _asc_def_iop_base[ASC_IOADR_TABLE_MAX_IX] __initdata = {
};
#ifdef CONFIG_ISA
-static uchar _isa_pnp_inited __initdata = 0;
+static unsigned char _isa_pnp_inited __initdata = 0;
static PortAddr __init AscSearchIOPortAddr(PortAddr iop_beg, ushort bus_type)
{
@@ -8269,12 +8268,11 @@ static PortAddr __init AscSearchIOPortAddr(PortAddr iop_beg, ushort bus_type)
while ((iop_beg = AscSearchIOPortAddr11(iop_beg)) != 0) {
if (AscGetChipVersion(iop_beg, bus_type) <=
ASC_CHIP_MAX_VER_VL) {
- return (iop_beg);
+ return iop_beg;
}
+ release_region(iop_beg, ASC_IOADR_GAP);
}
- return (0);
- }
- if (bus_type & ASC_IS_ISA) {
+ } else if (bus_type & ASC_IS_ISA) {
if (_isa_pnp_inited == 0) {
AscSetISAPNPWaitForKey();
_isa_pnp_inited++;
@@ -8282,40 +8280,33 @@ static PortAddr __init AscSearchIOPortAddr(PortAddr iop_beg, ushort bus_type)
while ((iop_beg = AscSearchIOPortAddr11(iop_beg)) != 0) {
if ((AscGetChipVersion(iop_beg, bus_type) &
ASC_CHIP_VER_ISA_BIT) != 0) {
- return (iop_beg);
+ return iop_beg;
}
+ release_region(iop_beg, ASC_IOADR_GAP);
}
- return (0);
}
- return (0);
+ return 0;
}
static PortAddr __init AscSearchIOPortAddr11(PortAddr s_addr)
{
int i;
- PortAddr iop_base;
for (i = 0; i < ASC_IOADR_TABLE_MAX_IX; i++) {
- if (_asc_def_iop_base[i] > s_addr) {
- break;
- }
- }
- for (; i < ASC_IOADR_TABLE_MAX_IX; i++) {
- iop_base = _asc_def_iop_base[i];
+ PortAddr iop_base = _asc_def_iop_base[i];
+ if (iop_base <= s_addr)
+ continue;
if (!request_region(iop_base, ASC_IOADR_GAP, "advansys")) {
- ASC_DBG1(1,
- "AscSearchIOPortAddr11: check_region() failed I/O port 0x%x\n",
- iop_base);
+ ASC_DBG1(1, "AscSearchIOPortAddr11: I/O port 0x%x "
+ "in use\n", iop_base);
continue;
}
ASC_DBG1(1, "AscSearchIOPortAddr11: probing I/O port 0x%x\n",
iop_base);
- release_region(iop_base, ASC_IOADR_GAP);
- if (AscFindSignature(iop_base)) {
- return (iop_base);
- }
+ if (AscFindSignature(iop_base))
+ return iop_base;
}
- return (0);
+ return 0;
}
static void __init AscSetISAPNPWaitForKey(void)
@@ -17842,14 +17833,12 @@ advansys_board_found(int iop, struct device *dev, int bus_type)
boardp->id, pci_memory_address, iolen);
goto err_shost;
}
- ASC_DBG1(1,
- "advansys_board_found: ioremap_addr: 0x%lx\n",
+ ASC_DBG1(1, "advansys_board_found: ioremap_addr: 0x%lx\n",
(ulong)boardp->ioremap_addr);
adv_dvc_varp->iop_base = (AdvPortAddr)
(boardp->ioremap_addr +
(pci_memory_address - (pci_memory_address & PAGE_MASK)));
- ASC_DBG1(1,
- "advansys_board_found: iop_base: 0x%lx\n",
+ ASC_DBG1(1, "advansys_board_found: iop_base: 0x%lx\n",
adv_dvc_varp->iop_base);
#endif /* CONFIG_PCI */
@@ -18330,25 +18319,6 @@ advansys_board_found(int iop, struct device *dev, int bus_type)
* Register Board Resources - I/O Port, DMA, IRQ
*/
- /*
- * Register I/O port range.
- *
- * For Wide boards the I/O ports are not used to access
- * the board, but request the region anyway.
- *
- * 'shost->n_io_port' is not referenced, because it may be truncated.
- */
- ASC_DBG2(2,
- "advansys_board_found: request_region port 0x%lx, len 0x%x\n",
- (ulong)shost->io_port, boardp->asc_n_io_port);
- if (request_region(shost->io_port, boardp->asc_n_io_port,
- "advansys") == NULL) {
- ASC_PRINT3
- ("advansys_board_found: board %d: request_region() failed, port 0x%lx, len 0x%x\n",
- boardp->id, (ulong)shost->io_port, boardp->asc_n_io_port);
- goto err_free_proc;
- }
-
/* Register DMA Channel for Narrow boards. */
shost->dma_channel = NO_ISA_DMA; /* Default to no ISA DMA. */
#ifdef CONFIG_ISA
@@ -18361,7 +18331,7 @@ advansys_board_found(int iop, struct device *dev, int bus_type)
ASC_PRINT3
("advansys_board_found: board %d: request_dma() %d failed %d\n",
boardp->id, shost->dma_channel, ret);
- goto err_free_region;
+ goto err_free_proc;
}
AscEnableIsaDma(shost->dma_channel);
}
@@ -18445,8 +18415,6 @@ advansys_board_found(int iop, struct device *dev, int bus_type)
err_free_dma:
if (shost->dma_channel != NO_ISA_DMA)
free_dma(shost->dma_channel);
- err_free_region:
- release_region(shost->io_port, boardp->asc_n_io_port);
err_free_proc:
kfree(boardp->prtbuf);
err_unmap:
@@ -18474,9 +18442,8 @@ advansys_board_found(int iop, struct device *dev, int bus_type)
static int __init advansys_detect(void)
{
static int detect_called = ASC_FALSE;
- int iop;
- int bus;
- int ioport = 0;
+ int iop, bus, ioport = 0;
+ struct Scsi_Host *shost;
if (detect_called == ASC_FALSE) {
detect_called = ASC_TRUE;
@@ -18533,8 +18500,7 @@ static int __init advansys_detect(void)
case ASC_IS_VL:
#ifdef CONFIG_ISA
if (asc_iopflag == ASC_FALSE) {
- iop =
- AscSearchIOPortAddr(iop,
+ iop = AscSearchIOPortAddr(iop,
asc_bus[bus]);
} else {
/*
@@ -18630,7 +18596,9 @@ static int __init advansys_detect(void)
break;
}
- advansys_board_found(iop, NULL, asc_bus[bus]);
+ shost = advansys_board_found(iop, NULL, asc_bus[bus]);
+ if (!shost)
+ release_region(iop, ASC_IOADR_GAP);
}
}
@@ -18655,7 +18623,6 @@ static int advansys_release(struct Scsi_Host *shost)
ASC_DBG(1, "advansys_release: free_dma()\n");
free_dma(shost->dma_channel);
}
- release_region(shost->io_port, boardp->asc_n_io_port);
if (ASC_WIDE_BOARD(boardp)) {
adv_sgblk_t *sgp = NULL;
@@ -18720,12 +18687,22 @@ static int __devinit advansys_eisa_probe(struct device *dev)
ioport = edev->base_addr + 0xc30;
for (i = 0; i < 2; i++, ioport += 0x20) {
- if (!AscFindSignature(ioport))
+ if (!request_region(ioport, ASC_IOADR_GAP, "advansys")) {
+ printk(KERN_WARNING "Region %x-%x busy\n", ioport,
+ ioport + ASC_IOADR_GAP - 1);
+ continue;
+ }
+ if (!AscFindSignature(ioport)) {
+ release_region(ioport, ASC_IOADR_GAP);
continue;
+ }
inw(ioport + 4);
data->host[i] = advansys_board_found(ioport, dev, ASC_IS_EISA);
- if (data->host[i])
+ if (data->host[i]) {
err = 0;
+ } else {
+ release_region(ioport, ASC_IOADR_GAP);
+ }
}
if (err) {
@@ -18748,6 +18725,7 @@ static __devexit int advansys_eisa_remove(struct device *dev)
continue;
ioport = shost->io_port;
advansys_remove(data->host[i]);
+ release_region(ioport, ASC_IOADR_GAP);
}
return 0;
@@ -18787,8 +18765,10 @@ advansys_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
int ioport;
struct Scsi_Host *shost;
- if (pci_enable_device(pdev))
+ if (pci_request_regions(pdev, "advansys"))
goto fail;
+ if (pci_enable_device(pdev))
+ goto release_regions;
ioport = pci_resource_start(pdev, 0);
shost = advansys_board_found(ioport, &pdev->dev, ASC_IS_PCI);
@@ -18799,6 +18779,8 @@ advansys_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
}
pci_disable_device(pdev);
+ release_regions:
+ pci_release_regions(pdev);
fail:
return -ENODEV;
}
@@ -18807,6 +18789,7 @@ static void __devexit advansys_pci_remove(struct pci_dev *pdev)
{
advansys_remove(pci_get_drvdata(pdev));
pci_disable_device(pdev);
+ pci_release_regions(pdev);
}
static struct pci_driver advansys_pci_driver = {
--
1.4.4.4
next prev parent reply other threads:[~2007-07-26 18:05 UTC|newest]
Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-07-26 17:11 Advansys driver Matthew Wilcox
2007-07-26 17:22 ` [PATCH 1/21] advansys: Clean up proc_info implementation Matthew Wilcox
2007-07-26 18:51 ` Jeff Garzik
2007-07-26 19:05 ` Matthew Wilcox
2007-07-26 17:22 ` [PATCH 2/21] advansys: version, copyright, etc Matthew Wilcox
2007-07-26 18:56 ` Jeff Garzik
2007-07-26 19:03 ` Matthew Wilcox
2007-07-26 19:08 ` Jeff Garzik
2007-07-26 19:16 ` Matthew Wilcox
2007-07-26 19:25 ` Christer Weinigel
2007-07-26 17:22 ` [PATCH 3/21] advansys: Convert to pci_register_driver interface Matthew Wilcox
2007-07-26 19:05 ` Jeff Garzik
2007-07-26 19:31 ` Jeff Garzik
2007-07-26 20:49 ` Matthew Wilcox
2007-07-26 21:21 ` Jeff Garzik
2007-07-27 13:48 ` Jeff Garzik
2007-07-26 17:22 ` [PATCH 4/21] advansys: restructure error handling in advansys_board_found Matthew Wilcox
2007-07-26 17:22 ` [PATCH 5/21] advansys: split advansys_init_wide_chip() out of advansys_board_found() Matthew Wilcox
2007-07-26 17:22 ` [PATCH 6/21] advansys: Move to scsi hotplug initialisation model Matthew Wilcox
2007-07-26 18:01 ` Christoph Hellwig
2007-07-26 18:04 ` Matthew Wilcox
2007-07-26 18:06 ` Matthew Wilcox
2007-07-26 18:16 ` Jeff Garzik
2007-07-26 18:29 ` Matthew Wilcox
2007-07-26 18:13 ` Jeff Garzik
2007-07-26 19:19 ` Jeff Garzik
2007-07-26 17:22 ` [PATCH 7/21] advansys: Convert to EISA driver model Matthew Wilcox
2007-07-26 19:38 ` Jeff Garzik
2007-07-26 20:37 ` Matthew Wilcox
2007-07-27 13:50 ` Jeff Garzik
2007-07-27 14:16 ` Matthew Wilcox
2007-07-27 14:55 ` Jeff Garzik
2007-07-26 17:22 ` Matthew Wilcox [this message]
2007-07-26 19:41 ` [PATCH 8/21] advansys: Rewrite resource management Jeff Garzik
2007-07-26 17:22 ` [PATCH 9/21] advansys: More PCI cleanups Matthew Wilcox
2007-07-26 19:43 ` Jeff Garzik
2007-07-26 19:50 ` Matthew Wilcox
2007-07-26 19:55 ` Jeff Garzik
2007-07-26 17:22 ` [PATCH 10/21] advansys: remove AscCompareString() Matthew Wilcox
2007-07-26 17:22 ` [PATCH 11/21] Add QUANTUM XP34301 to the blacklist Matthew Wilcox
2007-07-26 17:22 ` [PATCH 12/21] advansys: remove INQUIRY sniffing Matthew Wilcox
2007-07-26 17:22 ` [PATCH 13/21] advansys: misc reformatting Matthew Wilcox
2007-07-26 17:22 ` [PATCH 14/21] advansys: delete AscGetChipBusType Matthew Wilcox
2007-07-26 17:22 ` [PATCH 15/21] advansys: ioremap no longer needs page-aligned addresses Matthew Wilcox
2007-07-26 17:22 ` [PATCH 16/21] advansys: Stop using n_io_port in Scsi_Host structure Matthew Wilcox
2007-07-26 17:22 ` [PATCH 17/21] advansys: remove detect_called Matthew Wilcox
2007-07-26 19:48 ` Jeff Garzik
2007-07-26 17:22 ` [PATCH 18/21] advansys: Move struct device out of the cfg structures Matthew Wilcox
2007-07-26 19:49 ` Jeff Garzik
2007-07-26 20:26 ` Matthew Wilcox
2007-07-26 17:22 ` [PATCH 19/21] advansys: Remove library-style callback routines Matthew Wilcox
2007-07-26 17:22 ` [PATCH 20/21] advansys: Remove pci_slot_info Matthew Wilcox
2007-07-26 17:22 ` [PATCH 21/21] advansys: use memcpy instead of open-coded loop Matthew Wilcox
2007-07-26 19:50 ` Jeff Garzik
2007-07-27 4:58 ` Matthew Wilcox
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=11854705773172-git-send-email-matthew@wil.cx \
--to=matthew@wil.cx \
--cc=linux-scsi@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.