Commit 4cefaa3e authored by Alexander Viro's avatar Alexander Viro Committed by Linus Torvalds

[PATCH] mpu401 check_region() removal

mpu401 ports are claimed by callers now
probe_mpu401() gets pointer to resulting struct resource
callers updated, a bunch of check_region() calls eliminated
Signed-off-by: default avatarAl Viro <viro@parcelfarce.linux.org.uk>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent f7e40ac9
...@@ -3001,6 +3001,7 @@ static int __devinit cm_probe(struct pci_dev *pcidev, const struct pci_device_id ...@@ -3001,6 +3001,7 @@ static int __devinit cm_probe(struct pci_dev *pcidev, const struct pci_device_id
int i, val, ret; int i, val, ret;
unsigned char reg_mask; unsigned char reg_mask;
int timeout; int timeout;
struct resource *ports;
struct { struct {
unsigned short deviceid; unsigned short deviceid;
char *devicename; char *devicename;
...@@ -3202,12 +3203,16 @@ static int __devinit cm_probe(struct pci_dev *pcidev, const struct pci_device_id ...@@ -3202,12 +3203,16 @@ static int __devinit cm_probe(struct pci_dev *pcidev, const struct pci_device_id
s->iomidi = 0; s->iomidi = 0;
goto skip_mpu; goto skip_mpu;
} }
ports = request_region(s->iomidi, 2, "mpu401");
if (!ports)
goto skip_mpu;
/* disable MPU-401 */ /* disable MPU-401 */
maskb(s->iobase + CODEC_CMI_FUNCTRL1, ~0x04, 0); maskb(s->iobase + CODEC_CMI_FUNCTRL1, ~0x04, 0);
s->mpu_data.name = "cmpci mpu"; s->mpu_data.name = "cmpci mpu";
s->mpu_data.io_base = s->iomidi; s->mpu_data.io_base = s->iomidi;
s->mpu_data.irq = -s->irq; // tell mpu401 to share irq s->mpu_data.irq = -s->irq; // tell mpu401 to share irq
if (probe_mpu401(&s->mpu_data)) { if (probe_mpu401(&s->mpu_data, ports)) {
release_region(s->iomidi, 2);
s->iomidi = 0; s->iomidi = 0;
goto skip_mpu; goto skip_mpu;
} }
...@@ -3221,7 +3226,8 @@ static int __devinit cm_probe(struct pci_dev *pcidev, const struct pci_device_id ...@@ -3221,7 +3226,8 @@ static int __devinit cm_probe(struct pci_dev *pcidev, const struct pci_device_id
else else
break; break;
} }
if (!probe_mpu401(&s->mpu_data)) { if (!probe_mpu401(&s->mpu_data, ports)) {
release_region(s->iomidi, 2);
s->iomidi = 0; s->iomidi = 0;
maskb(s->iobase + CODEC_CMI_FUNCTRL1, ~0, 0x04); maskb(s->iobase + CODEC_CMI_FUNCTRL1, ~0, 0x04);
} else { } else {
......
...@@ -301,11 +301,13 @@ static int maui_load_patch(int dev, int format, const char __user *addr, ...@@ -301,11 +301,13 @@ static int maui_load_patch(int dev, int format, const char __user *addr,
static int __init probe_maui(struct address_info *hw_config) static int __init probe_maui(struct address_info *hw_config)
{ {
struct resource *ports;
int this_dev; int this_dev;
int i; int i;
int tmp1, tmp2, ret; int tmp1, tmp2, ret;
if (check_region(hw_config->io_base, 2)) ports = request_region(hw_config->io_base, 2, "mpu401");
if (!ports)
return 0; return 0;
if (!request_region(hw_config->io_base + 2, 6, "Maui")) if (!request_region(hw_config->io_base + 2, 6, "Maui"))
...@@ -357,10 +359,10 @@ static int __init probe_maui(struct address_info *hw_config) ...@@ -357,10 +359,10 @@ static int __init probe_maui(struct address_info *hw_config)
printk(KERN_DEBUG "Available DRAM %dk\n", tmp1 / 1024); printk(KERN_DEBUG "Available DRAM %dk\n", tmp1 / 1024);
for (i = 0; i < 1000; i++) for (i = 0; i < 1000; i++)
if (probe_mpu401(hw_config)) if (probe_mpu401(hw_config, ports))
break; break;
ret = probe_mpu401(hw_config); ret = probe_mpu401(hw_config, ports);
if (!ret) if (!ret)
goto out3; goto out3;
...@@ -396,6 +398,7 @@ static int __init probe_maui(struct address_info *hw_config) ...@@ -396,6 +398,7 @@ static int __init probe_maui(struct address_info *hw_config)
out2: out2:
release_region(hw_config->io_base + 2, 6); release_region(hw_config->io_base + 2, 6);
out: out:
release_region(hw_config->io_base, 2);
return 0; return 0;
} }
......
...@@ -1026,12 +1026,6 @@ int attach_mpu401(struct address_info *hw_config, struct module *owner) ...@@ -1026,12 +1026,6 @@ int attach_mpu401(struct address_info *hw_config, struct module *owner)
spin_unlock_irqrestore(&devc->lock,flags); spin_unlock_irqrestore(&devc->lock,flags);
} }
if (!request_region(hw_config->io_base, 2, "mpu401"))
{
ret = -ENOMEM;
goto out_irq;
}
if (devc->version != 0) if (devc->version != 0)
if (mpu_cmd(m, 0xC5, 0) >= 0) /* Set timebase OK */ if (mpu_cmd(m, 0xC5, 0) >= 0) /* Set timebase OK */
if (mpu_cmd(m, 0xE0, 120) >= 0) /* Set tempo OK */ if (mpu_cmd(m, 0xE0, 120) >= 0) /* Set tempo OK */
...@@ -1044,7 +1038,7 @@ int attach_mpu401(struct address_info *hw_config, struct module *owner) ...@@ -1044,7 +1038,7 @@ int attach_mpu401(struct address_info *hw_config, struct module *owner)
{ {
printk(KERN_ERR "mpu401: Can't allocate memory\n"); printk(KERN_ERR "mpu401: Can't allocate memory\n");
ret = -ENOMEM; ret = -ENOMEM;
goto out_resource; goto out_irq;
} }
if (!(devc->capabilities & MPU_CAP_INTLG)) /* No intelligent mode */ if (!(devc->capabilities & MPU_CAP_INTLG)) /* No intelligent mode */
{ {
...@@ -1126,13 +1120,12 @@ int attach_mpu401(struct address_info *hw_config, struct module *owner) ...@@ -1126,13 +1120,12 @@ int attach_mpu401(struct address_info *hw_config, struct module *owner)
return 0; return 0;
out_resource:
release_region(hw_config->io_base, 2);
out_irq: out_irq:
free_irq(devc->irq, (void *)m); free_irq(devc->irq, (void *)m);
out_mididev: out_mididev:
sound_unload_mididev(m); sound_unload_mididev(m);
out_err: out_err:
release_region(hw_config->io_base, 2);
return ret; return ret;
} }
...@@ -1207,16 +1200,11 @@ static void set_uart_mode(int dev, struct mpu_config *devc, int arg) ...@@ -1207,16 +1200,11 @@ static void set_uart_mode(int dev, struct mpu_config *devc, int arg)
} }
int probe_mpu401(struct address_info *hw_config) int probe_mpu401(struct address_info *hw_config, struct resource *ports)
{ {
int ok = 0; int ok = 0;
struct mpu_config tmp_devc; struct mpu_config tmp_devc;
if (check_region(hw_config->io_base, 2))
{
printk(KERN_ERR "mpu401: I/O port %x already in use\n\n", hw_config->io_base);
return 0;
}
tmp_devc.base = hw_config->io_base; tmp_devc.base = hw_config->io_base;
tmp_devc.irq = hw_config->irq; tmp_devc.irq = hw_config->irq;
tmp_devc.initialized = 0; tmp_devc.initialized = 0;
...@@ -1791,10 +1779,16 @@ static int __init init_mpu401(void) ...@@ -1791,10 +1779,16 @@ static int __init init_mpu401(void)
/* Can be loaded either for module use or to provide functions /* Can be loaded either for module use or to provide functions
to others */ to others */
if (io != -1 && irq != -1) { if (io != -1 && irq != -1) {
struct resource *ports;
cfg.irq = irq; cfg.irq = irq;
cfg.io_base = io; cfg.io_base = io;
if (probe_mpu401(&cfg) == 0) ports = request_region(io, 2, "mpu401");
if (!ports)
return -EBUSY;
if (probe_mpu401(&cfg, ports) == 0) {
release_region(io, 2);
return -ENODEV; return -ENODEV;
}
if ((ret = attach_mpu401(&cfg, THIS_MODULE))) if ((ret = attach_mpu401(&cfg, THIS_MODULE)))
return ret; return ret;
} }
......
...@@ -6,7 +6,7 @@ void unload_uart401 (struct address_info *hw_config); ...@@ -6,7 +6,7 @@ void unload_uart401 (struct address_info *hw_config);
irqreturn_t uart401intr (int irq, void *dev_id, struct pt_regs * dummy); irqreturn_t uart401intr (int irq, void *dev_id, struct pt_regs * dummy);
/* From mpu401.c */ /* From mpu401.c */
int probe_mpu401(struct address_info *hw_config); int probe_mpu401(struct address_info *hw_config, struct resource *ports);
int attach_mpu401(struct address_info * hw_config, struct module *owner); int attach_mpu401(struct address_info * hw_config, struct module *owner);
void unload_mpu401(struct address_info *hw_info); void unload_mpu401(struct address_info *hw_info);
......
...@@ -539,23 +539,12 @@ static struct mixer_operations opl3sa3_mixer_operations = ...@@ -539,23 +539,12 @@ static struct mixer_operations opl3sa3_mixer_operations =
* Component probe, attach, unload functions * Component probe, attach, unload functions
*/ */
static inline int __init probe_opl3sa2_mpu(struct address_info* hw_config)
{
return probe_mpu401(hw_config);
}
static inline int __init attach_opl3sa2_mpu(struct address_info* hw_config)
{
return attach_mpu401(hw_config, THIS_MODULE);
}
static inline void __exit unload_opl3sa2_mpu(struct address_info *hw_config) static inline void __exit unload_opl3sa2_mpu(struct address_info *hw_config)
{ {
unload_mpu401(hw_config); unload_mpu401(hw_config);
} }
static void __init attach_opl3sa2_mss(struct address_info* hw_config, struct resource *ports) static void __init attach_opl3sa2_mss(struct address_info* hw_config, struct resource *ports)
{ {
int initial_mixers; int initial_mixers;
...@@ -1062,15 +1051,23 @@ static int __init init_opl3sa2(void) ...@@ -1062,15 +1051,23 @@ static int __init init_opl3sa2(void)
/* Attach MPU if we've been asked to do so, failure isn't fatal */ /* Attach MPU if we've been asked to do so, failure isn't fatal */
if (opl3sa2_state[card].cfg_mpu.io_base != -1) { if (opl3sa2_state[card].cfg_mpu.io_base != -1) {
if (probe_opl3sa2_mpu(&opl3sa2_state[card].cfg_mpu)) { int base = opl3sa2_state[card].cfg_mpu.io_base;
if (attach_opl3sa2_mpu(&opl3sa2_state[card].cfg_mpu)) { struct resource *ports;
ports = request_region(base, 2, "mpu401");
if (!ports)
goto out;
if (!probe_mpu401(&opl3sa2_state[card].cfg_mpu, ports)) {
release_region(base, 2);
goto out;
}
if (attach_mpu401(&opl3sa2_state[card].cfg_mpu, THIS_MODULE)) {
printk(KERN_ERR PFX "failed to attach MPU401\n"); printk(KERN_ERR PFX "failed to attach MPU401\n");
opl3sa2_state[card].cfg_mpu.slots[1] = -1; opl3sa2_state[card].cfg_mpu.slots[1] = -1;
} }
} }
} }
}
out:
if (isapnp) { if (isapnp) {
printk(KERN_NOTICE PFX "%d PnP card(s) found.\n", opl3sa2_cards_num); printk(KERN_NOTICE PFX "%d PnP card(s) found.\n", opl3sa2_cards_num);
} }
......
...@@ -747,13 +747,15 @@ static int __init attach_pss(struct address_info *hw_config) ...@@ -747,13 +747,15 @@ static int __init attach_pss(struct address_info *hw_config)
static int __init probe_pss_mpu(struct address_info *hw_config) static int __init probe_pss_mpu(struct address_info *hw_config)
{ {
struct resource *ports;
int timeout; int timeout;
if (!pss_initialized) if (!pss_initialized)
return 0; return 0;
if (check_region(hw_config->io_base, 2)) ports = request_region(hw_config->io_base, 2, "mpu401");
{
if (!ports) {
printk(KERN_ERR "PSS: MPU I/O port conflict\n"); printk(KERN_ERR "PSS: MPU I/O port conflict\n");
return 0; return 0;
} }
...@@ -787,7 +789,7 @@ static int __init probe_pss_mpu(struct address_info *hw_config) ...@@ -787,7 +789,7 @@ static int __init probe_pss_mpu(struct address_info *hw_config)
break; /* No more input */ break; /* No more input */
} }
if (!probe_mpu401(hw_config)) if (!probe_mpu401(hw_config, ports))
goto fail; goto fail;
attach_mpu401(hw_config, THIS_MODULE); /* Slot 1 */ attach_mpu401(hw_config, THIS_MODULE); /* Slot 1 */
...@@ -795,6 +797,7 @@ static int __init probe_pss_mpu(struct address_info *hw_config) ...@@ -795,6 +797,7 @@ static int __init probe_pss_mpu(struct address_info *hw_config)
midi_devs[hw_config->slots[1]]->coproc = &pss_coproc_operations; midi_devs[hw_config->slots[1]]->coproc = &pss_coproc_operations;
return 1; return 1;
fail: fail:
release_region(hw_config->io_base, 2);
return 0; return 0;
} }
......
...@@ -1219,17 +1219,22 @@ int probe_sbmpu(struct address_info *hw_config, struct module *owner) ...@@ -1219,17 +1219,22 @@ int probe_sbmpu(struct address_info *hw_config, struct module *owner)
#if defined(CONFIG_SOUND_MPU401) #if defined(CONFIG_SOUND_MPU401)
if (devc->model == MDL_ESS) if (devc->model == MDL_ESS)
{ {
if (check_region(hw_config->io_base, 2)) struct resource *ports;
{ ports = request_region(hw_config->io_base, 2, "mpu401");
if (!ports) {
printk(KERN_ERR "sbmpu: I/O port conflict (%x)\n", hw_config->io_base); printk(KERN_ERR "sbmpu: I/O port conflict (%x)\n", hw_config->io_base);
return 0; return 0;
} }
if (!ess_midi_init(devc, hw_config)) if (!ess_midi_init(devc, hw_config)) {
release_region(hw_config->io_base, 2);
return 0; return 0;
}
hw_config->name = "ESS1xxx MPU"; hw_config->name = "ESS1xxx MPU";
devc->midi_irq_cookie = NULL; devc->midi_irq_cookie = NULL;
if (!probe_mpu401(hw_config)) if (!probe_mpu401(hw_config, ports)) {
release_region(hw_config->io_base, 2);
return 0; return 0;
}
attach_mpu401(hw_config, owner); attach_mpu401(hw_config, owner);
if (last_sb->irq == -hw_config->irq) if (last_sb->irq == -hw_config->irq)
last_sb->midi_irq_cookie=(void *)hw_config->slots[1]; last_sb->midi_irq_cookie=(void *)hw_config->slots[1];
......
...@@ -600,6 +600,7 @@ static coproc_operations sscape_coproc_operations = ...@@ -600,6 +600,7 @@ static coproc_operations sscape_coproc_operations =
&adev_info &adev_info
}; };
static struct resource *sscape_ports;
static int sscape_is_pnp; static int sscape_is_pnp;
static void __init attach_sscape(struct address_info *hw_config) static void __init attach_sscape(struct address_info *hw_config)
...@@ -637,7 +638,6 @@ static void __init attach_sscape(struct address_info *hw_config) ...@@ -637,7 +638,6 @@ static void __init attach_sscape(struct address_info *hw_config)
int i, irq_bits = 0xff; int i, irq_bits = 0xff;
request_region(devc->base + 2, 6, "SoundScape");
if (old_hardware) if (old_hardware)
{ {
valid_interrupts = valid_interrupts_old; valid_interrupts = valid_interrupts_old;
...@@ -657,6 +657,8 @@ static void __init attach_sscape(struct address_info *hw_config) ...@@ -657,6 +657,8 @@ static void __init attach_sscape(struct address_info *hw_config)
if (hw_config->irq > 15 || (regs[4] = irq_bits == 0xff)) if (hw_config->irq > 15 || (regs[4] = irq_bits == 0xff))
{ {
printk(KERN_ERR "Invalid IRQ%d\n", hw_config->irq); printk(KERN_ERR "Invalid IRQ%d\n", hw_config->irq);
release_region(devc->base, 2);
release_region(devc->base + 2, 6);
if (sscape_is_pnp) if (sscape_is_pnp)
release_region(devc->codec, 2); release_region(devc->codec, 2);
return; return;
...@@ -696,7 +698,7 @@ static void __init attach_sscape(struct address_info *hw_config) ...@@ -696,7 +698,7 @@ static void __init attach_sscape(struct address_info *hw_config)
} }
#endif #endif
if (probe_mpu401(hw_config)) if (probe_mpu401(hw_config, sscape_ports))
hw_config->always_detect = 1; hw_config->always_detect = 1;
hw_config->name = "SoundScape"; hw_config->name = "SoundScape";
...@@ -720,9 +722,6 @@ static int detect_ga(sscape_info * devc) ...@@ -720,9 +722,6 @@ static int detect_ga(sscape_info * devc)
DDB(printk("Entered Soundscape detect_ga(%x)\n", devc->base)); DDB(printk("Entered Soundscape detect_ga(%x)\n", devc->base));
if (check_region(devc->base, 8))
return 0;
/* /*
* First check that the address register of "ODIE" is * First check that the address register of "ODIE" is
* there and that it has exactly 4 writable bits. * there and that it has exactly 4 writable bits.
...@@ -1115,11 +1114,6 @@ static int __init detect_sscape_pnp(sscape_info* devc) ...@@ -1115,11 +1114,6 @@ static int __init detect_sscape_pnp(sscape_info* devc)
DDB(printk("Entered detect_sscape_pnp(%x)\n", devc->base)); DDB(printk("Entered detect_sscape_pnp(%x)\n", devc->base));
if (check_region(devc->base, 8)) {
printk(KERN_ERR "detect_sscape_pnp: port %x is not free\n", devc->base);
return 0;
}
if (!request_region(devc->codec, 2, "sscape codec")) { if (!request_region(devc->codec, 2, "sscape codec")) {
printk(KERN_ERR "detect_sscape_pnp: port %x is not free\n", devc->codec); printk(KERN_ERR "detect_sscape_pnp: port %x is not free\n", devc->codec);
return 0; return 0;
...@@ -1243,9 +1237,20 @@ static int __init probe_sscape(struct address_info *hw_config) ...@@ -1243,9 +1237,20 @@ static int __init probe_sscape(struct address_info *hw_config)
#endif #endif
devc->failed = 1; devc->failed = 1;
sscape_ports = request_region(devc->base, 2, "mpu401");
if (!sscape_ports)
return 0;
if (!request_region(devc->base + 2, 6, "SoundScape")) {
release_region(devc->base, 2);
return 0;
}
if (!detect_ga(devc)) { if (!detect_ga(devc)) {
if (detect_sscape_pnp(devc)) if (detect_sscape_pnp(devc))
return 1; return 1;
release_region(devc->base, 2);
release_region(devc->base + 2, 6);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment