@@ -59,45 +59,52 @@ MODULE_DEVICE_TABLE(pci, emu_tbl);
5959
6060static int __devinit emu_probe (struct pci_dev * pdev , const struct pci_device_id * ent )
6161{
62- int ioport , iolen ;
6362 struct emu * emu ;
6463 struct gameport * port ;
65-
66- if (pci_enable_device (pdev ))
67- return - EBUSY ;
68-
69- ioport = pci_resource_start (pdev , 0 );
70- iolen = pci_resource_len (pdev , 0 );
71-
72- if (!request_region (ioport , iolen , "emu10k1-gp" ))
73- return - EBUSY ;
64+ int error ;
7465
7566 emu = kzalloc (sizeof (struct emu ), GFP_KERNEL );
7667 port = gameport_allocate_port ();
7768 if (!emu || !port ) {
7869 printk (KERN_ERR "emu10k1-gp: Memory allocation failed\n" );
79- release_region (ioport , iolen );
80- pci_disable_device (pdev );
81- kfree (emu );
82- gameport_free_port (port );
83- return - ENOMEM ;
70+ error = - ENOMEM ;
71+ goto err_out_free ;
8472 }
8573
86- emu -> io = ioport ;
87- emu -> size = iolen ;
74+ error = pci_enable_device (pdev );
75+ if (error )
76+ goto err_out_free ;
77+
78+ emu -> io = pci_resource_start (pdev , 0 );
79+ emu -> size = pci_resource_len (pdev , 0 );
80+
8881 emu -> dev = pdev ;
8982 emu -> gameport = port ;
9083
9184 gameport_set_name (port , "EMU10K1" );
9285 gameport_set_phys (port , "pci%s/gameport0" , pci_name (pdev ));
9386 port -> dev .parent = & pdev -> dev ;
94- port -> io = ioport ;
87+ port -> io = emu -> io ;
88+
89+ if (!request_region (emu -> io , emu -> size , "emu10k1-gp" )) {
90+ printk (KERN_ERR "emu10k1-gp: unable to grab region 0x%x-0x%x\n" ,
91+ emu -> io , emu -> io + emu -> size - 1 );
92+ error = - EBUSY ;
93+ goto err_out_disable_dev ;
94+ }
9595
9696 pci_set_drvdata (pdev , emu );
9797
9898 gameport_register_port (port );
9999
100100 return 0 ;
101+
102+ err_out_disable_dev :
103+ pci_disable_device (pdev );
104+ err_out_free :
105+ gameport_free_port (port );
106+ kfree (emu );
107+ return error ;
101108}
102109
103110static void __devexit emu_remove (struct pci_dev * pdev )
0 commit comments