Input: emu10k1 - do not leave device enabled when probe fails
Rework emu_probe() to make sure we leave the device disabled if probe fails for any reason. Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
This commit is contained in:
parent
05e93a746a
commit
7aed3fb73f
|
@ -59,45 +59,52 @@ MODULE_DEVICE_TABLE(pci, emu_tbl);
|
||||||
|
|
||||||
static int __devinit emu_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
|
static int __devinit emu_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
|
||||||
{
|
{
|
||||||
int ioport, iolen;
|
|
||||||
struct emu *emu;
|
struct emu *emu;
|
||||||
struct gameport *port;
|
struct gameport *port;
|
||||||
|
int error;
|
||||||
if (pci_enable_device(pdev))
|
|
||||||
return -EBUSY;
|
|
||||||
|
|
||||||
ioport = pci_resource_start(pdev, 0);
|
|
||||||
iolen = pci_resource_len(pdev, 0);
|
|
||||||
|
|
||||||
if (!request_region(ioport, iolen, "emu10k1-gp"))
|
|
||||||
return -EBUSY;
|
|
||||||
|
|
||||||
emu = kzalloc(sizeof(struct emu), GFP_KERNEL);
|
emu = kzalloc(sizeof(struct emu), GFP_KERNEL);
|
||||||
port = gameport_allocate_port();
|
port = gameport_allocate_port();
|
||||||
if (!emu || !port) {
|
if (!emu || !port) {
|
||||||
printk(KERN_ERR "emu10k1-gp: Memory allocation failed\n");
|
printk(KERN_ERR "emu10k1-gp: Memory allocation failed\n");
|
||||||
release_region(ioport, iolen);
|
error = -ENOMEM;
|
||||||
pci_disable_device(pdev);
|
goto err_out_free;
|
||||||
kfree(emu);
|
|
||||||
gameport_free_port(port);
|
|
||||||
return -ENOMEM;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
emu->io = ioport;
|
error = pci_enable_device(pdev);
|
||||||
emu->size = iolen;
|
if (error)
|
||||||
|
goto err_out_free;
|
||||||
|
|
||||||
|
emu->io = pci_resource_start(pdev, 0);
|
||||||
|
emu->size = pci_resource_len(pdev, 0);
|
||||||
|
|
||||||
emu->dev = pdev;
|
emu->dev = pdev;
|
||||||
emu->gameport = port;
|
emu->gameport = port;
|
||||||
|
|
||||||
gameport_set_name(port, "EMU10K1");
|
gameport_set_name(port, "EMU10K1");
|
||||||
gameport_set_phys(port, "pci%s/gameport0", pci_name(pdev));
|
gameport_set_phys(port, "pci%s/gameport0", pci_name(pdev));
|
||||||
port->dev.parent = &pdev->dev;
|
port->dev.parent = &pdev->dev;
|
||||||
port->io = ioport;
|
port->io = emu->io;
|
||||||
|
|
||||||
|
if (!request_region(emu->io, emu->size, "emu10k1-gp")) {
|
||||||
|
printk(KERN_ERR "emu10k1-gp: unable to grab region 0x%x-0x%x\n",
|
||||||
|
emu->io, emu->io + emu->size - 1);
|
||||||
|
error = -EBUSY;
|
||||||
|
goto err_out_disable_dev;
|
||||||
|
}
|
||||||
|
|
||||||
pci_set_drvdata(pdev, emu);
|
pci_set_drvdata(pdev, emu);
|
||||||
|
|
||||||
gameport_register_port(port);
|
gameport_register_port(port);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
err_out_disable_dev:
|
||||||
|
pci_disable_device(pdev);
|
||||||
|
err_out_free:
|
||||||
|
gameport_free_port(port);
|
||||||
|
kfree(emu);
|
||||||
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __devexit emu_remove(struct pci_dev *pdev)
|
static void __devexit emu_remove(struct pci_dev *pdev)
|
||||||
|
|
Loading…
Reference in New Issue