]> git.hungrycats.org Git - linux/commitdiff
[PATCH] mpu401 check_region() removal
authorAlexander Viro <viro@www.linux.org.uk>
Fri, 27 Aug 2004 12:12:55 +0000 (05:12 -0700)
committerLinus Torvalds <torvalds@ppc970.osdl.org>
Fri, 27 Aug 2004 12:12:55 +0000 (05:12 -0700)
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: Al Viro <viro@parcelfarce.linux.org.uk>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
sound/oss/cmpci.c
sound/oss/maui.c
sound/oss/mpu401.c
sound/oss/mpu401.h
sound/oss/opl3sa2.c
sound/oss/pss.c
sound/oss/sb_common.c
sound/oss/sscape.c

index 3b94f37f101e69c6fe338919ba787dc88b77bf9b..a862958ac4d2ad6c42b54d6b7c5b2368eac8aef8 100644 (file)
@@ -3001,6 +3001,7 @@ static int __devinit cm_probe(struct pci_dev *pcidev, const struct pci_device_id
        int i, val, ret;
        unsigned char reg_mask;
        int timeout;
+       struct resource *ports;
        struct {
                unsigned short  deviceid;
                char            *devicename;
@@ -3202,12 +3203,16 @@ static int __devinit cm_probe(struct pci_dev *pcidev, const struct pci_device_id
                s->iomidi = 0;
                goto skip_mpu;
        }
+       ports = request_region(s->iomidi, 2, "mpu401");
+       if (!ports)
+               goto skip_mpu;
        /* disable MPU-401 */
        maskb(s->iobase + CODEC_CMI_FUNCTRL1, ~0x04, 0);
        s->mpu_data.name = "cmpci mpu";
        s->mpu_data.io_base = s->iomidi;
        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;
                goto skip_mpu;
        }
@@ -3221,7 +3226,8 @@ static int __devinit cm_probe(struct pci_dev *pcidev, const struct pci_device_id
                else
                        break;
        }
-       if (!probe_mpu401(&s->mpu_data)) {
+       if (!probe_mpu401(&s->mpu_data, ports)) {
+               release_region(s->iomidi, 2);
                s->iomidi = 0;
                maskb(s->iobase + CODEC_CMI_FUNCTRL1, ~0, 0x04);
        } else {
index 27203adfaba55ac4d89c0c58d3976853ba720535..4f749b5b7e6a24fdd134853e57154591856f834e 100644 (file)
@@ -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)
 {
+       struct resource *ports;
        int this_dev;
        int i;
        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;
 
        if (!request_region(hw_config->io_base + 2, 6, "Maui"))
@@ -357,10 +359,10 @@ static int __init probe_maui(struct address_info *hw_config)
        printk(KERN_DEBUG "Available DRAM %dk\n", tmp1 / 1024);
 
        for (i = 0; i < 1000; i++)
-               if (probe_mpu401(hw_config))
+               if (probe_mpu401(hw_config, ports))
                        break;
 
-       ret = probe_mpu401(hw_config);
+       ret = probe_mpu401(hw_config, ports);
        if (!ret)
                goto out3;
 
@@ -396,6 +398,7 @@ out3:
 out2:
        release_region(hw_config->io_base + 2, 6);
 out:
+       release_region(hw_config->io_base, 2);
        return 0;
 }
 
index 341983bff7b76d04166443188d8e8efe3d4915db..73c3ce32a69def591fd1fa2f9fa65ceb838f21cf 100644 (file)
@@ -1026,12 +1026,6 @@ int attach_mpu401(struct address_info *hw_config, struct module *owner)
                        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 (mpu_cmd(m, 0xC5, 0) >= 0)   /* Set timebase 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)
        {
                printk(KERN_ERR "mpu401: Can't allocate memory\n");
                ret = -ENOMEM;
-               goto out_resource;
+               goto out_irq;
        }
        if (!(devc->capabilities & MPU_CAP_INTLG))      /* No intelligent mode */
        {
@@ -1126,13 +1120,12 @@ int attach_mpu401(struct address_info *hw_config, struct module *owner)
        
        return 0;
 
-out_resource:
-       release_region(hw_config->io_base, 2);
 out_irq:
        free_irq(devc->irq, (void *)m);
 out_mididev:
        sound_unload_mididev(m);
 out_err:
+       release_region(hw_config->io_base, 2);
        return ret;
 }
 
@@ -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;
        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.irq = hw_config->irq;
        tmp_devc.initialized = 0;
@@ -1791,10 +1779,16 @@ static int __init init_mpu401(void)
        /* Can be loaded either for module use or to provide functions
           to others */
        if (io != -1 && irq != -1) {
+               struct resource *ports;
                cfg.irq = irq;
                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;
+               }
                if ((ret = attach_mpu401(&cfg, THIS_MODULE)))
                        return ret;
        }
index 43ff5430cd4507f162f6347b835e6fbf0e0830e6..bdc5bde641e6b7fc56dfbb1b2e40df9bda0cf9bd 100644 (file)
@@ -6,7 +6,7 @@ void unload_uart401 (struct address_info *hw_config);
 irqreturn_t uart401intr (int irq, void *dev_id, struct pt_regs * dummy);
 
 /*     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);
 void unload_mpu401(struct address_info *hw_info);
 
index fb98c6ee60a909909e1b200d36ea1ff73e6a11d1..7d7a981734fc203a16ac4a89e7e61e3a69f89025 100644 (file)
@@ -539,23 +539,12 @@ static struct mixer_operations opl3sa3_mixer_operations =
  * 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)
 {
        unload_mpu401(hw_config);
 }
 
+
 static void __init attach_opl3sa2_mss(struct address_info* hw_config, struct resource *ports)
 {
        int initial_mixers;
@@ -1062,15 +1051,23 @@ static int __init init_opl3sa2(void)
                
                /* Attach MPU if we've been asked to do so, failure isn't fatal */
                if (opl3sa2_state[card].cfg_mpu.io_base != -1) {
-                       if (probe_opl3sa2_mpu(&opl3sa2_state[card].cfg_mpu)) {
-                               if (attach_opl3sa2_mpu(&opl3sa2_state[card].cfg_mpu)) {
-                                       printk(KERN_ERR PFX "failed to attach MPU401\n");
-                                       opl3sa2_state[card].cfg_mpu.slots[1] = -1;
-                               }
+                       int base = opl3sa2_state[card].cfg_mpu.io_base;
+                       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");
+                               opl3sa2_state[card].cfg_mpu.slots[1] = -1;
                        }
                }
        }
 
+out:
        if (isapnp) {
                printk(KERN_NOTICE PFX "%d PnP card(s) found.\n", opl3sa2_cards_num);
        }
index 3e6ba68d09237e5090b11a7387feec458431f35d..af3f96ad02ca8100facea843b1a1352097e62736 100644 (file)
@@ -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)
 {
+       struct resource *ports;
        int timeout;
 
        if (!pss_initialized)
                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");
                return 0;
        }
@@ -787,7 +789,7 @@ static int __init probe_pss_mpu(struct address_info *hw_config)
                        break;  /* No more input */
        }
 
-       if (!probe_mpu401(hw_config))
+       if (!probe_mpu401(hw_config, ports))
                goto fail;
 
        attach_mpu401(hw_config, THIS_MODULE);  /* Slot 1 */
@@ -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;
        return 1;
 fail:
+       release_region(hw_config->io_base, 2);
        return 0;
 }
 
index e27f80ab01fb10f908f70ccd6dd50582aca4f0f2..e33a50e8222993ecd694cbb251f931796713111d 100644 (file)
@@ -1219,17 +1219,22 @@ int probe_sbmpu(struct address_info *hw_config, struct module *owner)
 #if defined(CONFIG_SOUND_MPU401)
        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);
                        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;
+               }
                hw_config->name = "ESS1xxx MPU";
                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;
+               }
                attach_mpu401(hw_config, owner);
                if (last_sb->irq == -hw_config->irq)
                        last_sb->midi_irq_cookie=(void *)hw_config->slots[1];
index dfe02f101264144d44a7fce5d82c242bd811d4d9..7c9b5d41bbb2d2e834d58e9eb9800d97a7e75c6d 100644 (file)
@@ -600,6 +600,7 @@ static coproc_operations sscape_coproc_operations =
        &adev_info
 };
 
+static struct resource *sscape_ports;
 static int sscape_is_pnp;
 
 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;
 
-       request_region(devc->base + 2, 6, "SoundScape");
        if (old_hardware)
        {
                valid_interrupts = valid_interrupts_old;
@@ -657,6 +657,8 @@ static void __init attach_sscape(struct address_info *hw_config)
        if (hw_config->irq > 15 || (regs[4] = irq_bits == 0xff))
        {
                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)
                        release_region(devc->codec, 2);
                return;
@@ -696,7 +698,7 @@ static void __init attach_sscape(struct address_info *hw_config)
        }
 #endif
 
-       if (probe_mpu401(hw_config))
+       if (probe_mpu401(hw_config, sscape_ports))
                hw_config->always_detect = 1;
        hw_config->name = "SoundScape";
 
@@ -720,9 +722,6 @@ static int detect_ga(sscape_info * devc)
 
        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
         * there and that it has exactly 4 writable bits.
@@ -1115,11 +1114,6 @@ static int __init detect_sscape_pnp(sscape_info* devc)
 
        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")) {
                printk(KERN_ERR "detect_sscape_pnp: port %x is not free\n", devc->codec);       
                return 0;
@@ -1243,9 +1237,20 @@ static int __init probe_sscape(struct address_info *hw_config)
 #endif
        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_sscape_pnp(devc))
                        return 1;
+               release_region(devc->base, 2);
+               release_region(devc->base + 2, 6);
                return 0;
        }