Commit fbf1c247 authored by Jiri Slaby's avatar Jiri Slaby Committed by Greg Kroah-Hartman

misc: pti, fix fail paths

Fail paths in ->probe and pti_init are incomplete. Fix that by adding
proper clean-up paths.

Note that we used to leak tty_driver on module unload. This is fixed
here too.

tty_unregister_driver needs not retval checking, so remove that.
Signed-off-by: default avatarJiri Slaby <jslaby@suse.cz>
Cc: J Freyensee <james_p_freyensee@linux.intel.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 3140bae2
...@@ -811,7 +811,7 @@ static int __devinit pti_pci_probe(struct pci_dev *pdev, ...@@ -811,7 +811,7 @@ static int __devinit pti_pci_probe(struct pci_dev *pdev,
__func__, __LINE__); __func__, __LINE__);
pr_err("%s(%d): Error value returned: %d\n", pr_err("%s(%d): Error value returned: %d\n",
__func__, __LINE__, retval); __func__, __LINE__, retval);
return retval; goto err;
} }
retval = pci_enable_device(pdev); retval = pci_enable_device(pdev);
...@@ -819,17 +819,16 @@ static int __devinit pti_pci_probe(struct pci_dev *pdev, ...@@ -819,17 +819,16 @@ static int __devinit pti_pci_probe(struct pci_dev *pdev,
dev_err(&pdev->dev, dev_err(&pdev->dev,
"%s: pci_enable_device() returned error %d\n", "%s: pci_enable_device() returned error %d\n",
__func__, retval); __func__, retval);
return retval; goto err_unreg_misc;
} }
drv_data = kzalloc(sizeof(*drv_data), GFP_KERNEL); drv_data = kzalloc(sizeof(*drv_data), GFP_KERNEL);
if (drv_data == NULL) { if (drv_data == NULL) {
retval = -ENOMEM; retval = -ENOMEM;
dev_err(&pdev->dev, dev_err(&pdev->dev,
"%s(%d): kmalloc() returned NULL memory.\n", "%s(%d): kmalloc() returned NULL memory.\n",
__func__, __LINE__); __func__, __LINE__);
return retval; goto err_disable_pci;
} }
drv_data->pti_addr = pci_resource_start(pdev, pci_bar); drv_data->pti_addr = pci_resource_start(pdev, pci_bar);
...@@ -838,18 +837,15 @@ static int __devinit pti_pci_probe(struct pci_dev *pdev, ...@@ -838,18 +837,15 @@ static int __devinit pti_pci_probe(struct pci_dev *pdev,
dev_err(&pdev->dev, dev_err(&pdev->dev,
"%s(%d): pci_request_region() returned error %d\n", "%s(%d): pci_request_region() returned error %d\n",
__func__, __LINE__, retval); __func__, __LINE__, retval);
kfree(drv_data); goto err_free_dd;
return retval;
} }
drv_data->aperture_base = drv_data->pti_addr+APERTURE_14; drv_data->aperture_base = drv_data->pti_addr+APERTURE_14;
drv_data->pti_ioaddr = drv_data->pti_ioaddr =
ioremap_nocache((u32)drv_data->aperture_base, ioremap_nocache((u32)drv_data->aperture_base,
APERTURE_LEN); APERTURE_LEN);
if (!drv_data->pti_ioaddr) { if (!drv_data->pti_ioaddr) {
pci_release_region(pdev, pci_bar);
retval = -ENOMEM; retval = -ENOMEM;
kfree(drv_data); goto err_rel_reg;
return retval;
} }
pci_set_drvdata(pdev, drv_data); pci_set_drvdata(pdev, drv_data);
...@@ -862,6 +858,16 @@ static int __devinit pti_pci_probe(struct pci_dev *pdev, ...@@ -862,6 +858,16 @@ static int __devinit pti_pci_probe(struct pci_dev *pdev,
register_console(&pti_console); register_console(&pti_console);
return 0;
err_rel_reg:
pci_release_region(pdev, pci_bar);
err_free_dd:
kfree(drv_data);
err_disable_pci:
pci_disable_device(pdev);
err_unreg_misc:
misc_deregister(&pti_char_driver);
err:
return retval; return retval;
} }
...@@ -937,25 +943,24 @@ static int __init pti_init(void) ...@@ -937,25 +943,24 @@ static int __init pti_init(void)
pr_err("%s(%d): Error value returned: %d\n", pr_err("%s(%d): Error value returned: %d\n",
__func__, __LINE__, retval); __func__, __LINE__, retval);
pti_tty_driver = NULL; goto put_tty;
return retval;
} }
retval = pci_register_driver(&pti_pci_driver); retval = pci_register_driver(&pti_pci_driver);
if (retval) { if (retval) {
pr_err("%s(%d): PCI registration failed of pti driver\n", pr_err("%s(%d): PCI registration failed of pti driver\n",
__func__, __LINE__); __func__, __LINE__);
pr_err("%s(%d): Error value returned: %d\n", pr_err("%s(%d): Error value returned: %d\n",
__func__, __LINE__, retval); __func__, __LINE__, retval);
goto unreg_tty;
tty_unregister_driver(pti_tty_driver);
pr_err("%s(%d): Unregistering TTY part of pti driver\n",
__func__, __LINE__);
pti_tty_driver = NULL;
return retval;
} }
return 0;
unreg_tty:
tty_unregister_driver(pti_tty_driver);
put_tty:
put_tty_driver(pti_tty_driver);
pti_tty_driver = NULL;
return retval; return retval;
} }
...@@ -964,17 +969,9 @@ static int __init pti_init(void) ...@@ -964,17 +969,9 @@ static int __init pti_init(void)
*/ */
static void __exit pti_exit(void) static void __exit pti_exit(void)
{ {
int retval; tty_unregister_driver(pti_tty_driver);
retval = tty_unregister_driver(pti_tty_driver);
if (retval) {
pr_err("%s(%d): TTY unregistration failed of pti driver\n",
__func__, __LINE__);
pr_err("%s(%d): Error value returned: %d\n",
__func__, __LINE__, retval);
}
pci_unregister_driver(&pti_pci_driver); pci_unregister_driver(&pti_pci_driver);
put_tty_driver(pti_tty_driver);
} }
module_init(pti_init); module_init(pti_init);
......
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