diff options
author | Jiri Slaby <jslaby@suse.cz> | 2012-08-07 15:47:34 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2012-08-10 16:27:51 -0400 |
commit | fbf1c247dac8574ef3973adce4b20d40ff22214e (patch) | |
tree | 0b7e03cc3a89eaa237e5ab4aeb2f48034bbd85fa /drivers/misc | |
parent | 3140bae26c9105b4ec8ff4935631f2f09882553d (diff) |
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: Jiri Slaby <jslaby@suse.cz>
Cc: J Freyensee <james_p_freyensee@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/misc')
-rw-r--r-- | drivers/misc/pti.c | 53 |
1 files changed, 25 insertions, 28 deletions
diff --git a/drivers/misc/pti.c b/drivers/misc/pti.c index be6e6795d79d..90de855abb90 100644 --- a/drivers/misc/pti.c +++ b/drivers/misc/pti.c | |||
@@ -811,7 +811,7 @@ static int __devinit pti_pci_probe(struct pci_dev *pdev, | |||
811 | __func__, __LINE__); | 811 | __func__, __LINE__); |
812 | pr_err("%s(%d): Error value returned: %d\n", | 812 | pr_err("%s(%d): Error value returned: %d\n", |
813 | __func__, __LINE__, retval); | 813 | __func__, __LINE__, retval); |
814 | return retval; | 814 | goto err; |
815 | } | 815 | } |
816 | 816 | ||
817 | retval = pci_enable_device(pdev); | 817 | retval = pci_enable_device(pdev); |
@@ -819,17 +819,16 @@ static int __devinit pti_pci_probe(struct pci_dev *pdev, | |||
819 | dev_err(&pdev->dev, | 819 | dev_err(&pdev->dev, |
820 | "%s: pci_enable_device() returned error %d\n", | 820 | "%s: pci_enable_device() returned error %d\n", |
821 | __func__, retval); | 821 | __func__, retval); |
822 | return retval; | 822 | goto err_unreg_misc; |
823 | } | 823 | } |
824 | 824 | ||
825 | drv_data = kzalloc(sizeof(*drv_data), GFP_KERNEL); | 825 | drv_data = kzalloc(sizeof(*drv_data), GFP_KERNEL); |
826 | |||
827 | if (drv_data == NULL) { | 826 | if (drv_data == NULL) { |
828 | retval = -ENOMEM; | 827 | retval = -ENOMEM; |
829 | dev_err(&pdev->dev, | 828 | dev_err(&pdev->dev, |
830 | "%s(%d): kmalloc() returned NULL memory.\n", | 829 | "%s(%d): kmalloc() returned NULL memory.\n", |
831 | __func__, __LINE__); | 830 | __func__, __LINE__); |
832 | return retval; | 831 | goto err_disable_pci; |
833 | } | 832 | } |
834 | drv_data->pti_addr = pci_resource_start(pdev, pci_bar); | 833 | drv_data->pti_addr = pci_resource_start(pdev, pci_bar); |
835 | 834 | ||
@@ -838,18 +837,15 @@ static int __devinit pti_pci_probe(struct pci_dev *pdev, | |||
838 | dev_err(&pdev->dev, | 837 | dev_err(&pdev->dev, |
839 | "%s(%d): pci_request_region() returned error %d\n", | 838 | "%s(%d): pci_request_region() returned error %d\n", |
840 | __func__, __LINE__, retval); | 839 | __func__, __LINE__, retval); |
841 | kfree(drv_data); | 840 | goto err_free_dd; |
842 | return retval; | ||
843 | } | 841 | } |
844 | drv_data->aperture_base = drv_data->pti_addr+APERTURE_14; | 842 | drv_data->aperture_base = drv_data->pti_addr+APERTURE_14; |
845 | drv_data->pti_ioaddr = | 843 | drv_data->pti_ioaddr = |
846 | ioremap_nocache((u32)drv_data->aperture_base, | 844 | ioremap_nocache((u32)drv_data->aperture_base, |
847 | APERTURE_LEN); | 845 | APERTURE_LEN); |
848 | if (!drv_data->pti_ioaddr) { | 846 | if (!drv_data->pti_ioaddr) { |
849 | pci_release_region(pdev, pci_bar); | ||
850 | retval = -ENOMEM; | 847 | retval = -ENOMEM; |
851 | kfree(drv_data); | 848 | goto err_rel_reg; |
852 | return retval; | ||
853 | } | 849 | } |
854 | 850 | ||
855 | pci_set_drvdata(pdev, drv_data); | 851 | pci_set_drvdata(pdev, drv_data); |
@@ -862,6 +858,16 @@ static int __devinit pti_pci_probe(struct pci_dev *pdev, | |||
862 | 858 | ||
863 | register_console(&pti_console); | 859 | register_console(&pti_console); |
864 | 860 | ||
861 | return 0; | ||
862 | err_rel_reg: | ||
863 | pci_release_region(pdev, pci_bar); | ||
864 | err_free_dd: | ||
865 | kfree(drv_data); | ||
866 | err_disable_pci: | ||
867 | pci_disable_device(pdev); | ||
868 | err_unreg_misc: | ||
869 | misc_deregister(&pti_char_driver); | ||
870 | err: | ||
865 | return retval; | 871 | return retval; |
866 | } | 872 | } |
867 | 873 | ||
@@ -937,25 +943,24 @@ static int __init pti_init(void) | |||
937 | pr_err("%s(%d): Error value returned: %d\n", | 943 | pr_err("%s(%d): Error value returned: %d\n", |
938 | __func__, __LINE__, retval); | 944 | __func__, __LINE__, retval); |
939 | 945 | ||
940 | pti_tty_driver = NULL; | 946 | goto put_tty; |
941 | return retval; | ||
942 | } | 947 | } |
943 | 948 | ||
944 | retval = pci_register_driver(&pti_pci_driver); | 949 | retval = pci_register_driver(&pti_pci_driver); |
945 | |||
946 | if (retval) { | 950 | if (retval) { |
947 | pr_err("%s(%d): PCI registration failed of pti driver\n", | 951 | pr_err("%s(%d): PCI registration failed of pti driver\n", |
948 | __func__, __LINE__); | 952 | __func__, __LINE__); |
949 | pr_err("%s(%d): Error value returned: %d\n", | 953 | pr_err("%s(%d): Error value returned: %d\n", |
950 | __func__, __LINE__, retval); | 954 | __func__, __LINE__, retval); |
951 | 955 | goto unreg_tty; | |
952 | tty_unregister_driver(pti_tty_driver); | ||
953 | pr_err("%s(%d): Unregistering TTY part of pti driver\n", | ||
954 | __func__, __LINE__); | ||
955 | pti_tty_driver = NULL; | ||
956 | return retval; | ||
957 | } | 956 | } |
958 | 957 | ||
958 | return 0; | ||
959 | unreg_tty: | ||
960 | tty_unregister_driver(pti_tty_driver); | ||
961 | put_tty: | ||
962 | put_tty_driver(pti_tty_driver); | ||
963 | pti_tty_driver = NULL; | ||
959 | return retval; | 964 | return retval; |
960 | } | 965 | } |
961 | 966 | ||
@@ -964,17 +969,9 @@ static int __init pti_init(void) | |||
964 | */ | 969 | */ |
965 | static void __exit pti_exit(void) | 970 | static void __exit pti_exit(void) |
966 | { | 971 | { |
967 | int retval; | 972 | tty_unregister_driver(pti_tty_driver); |
968 | |||
969 | retval = tty_unregister_driver(pti_tty_driver); | ||
970 | if (retval) { | ||
971 | pr_err("%s(%d): TTY unregistration failed of pti driver\n", | ||
972 | __func__, __LINE__); | ||
973 | pr_err("%s(%d): Error value returned: %d\n", | ||
974 | __func__, __LINE__, retval); | ||
975 | } | ||
976 | |||
977 | pci_unregister_driver(&pti_pci_driver); | 973 | pci_unregister_driver(&pti_pci_driver); |
974 | put_tty_driver(pti_tty_driver); | ||
978 | } | 975 | } |
979 | 976 | ||
980 | module_init(pti_init); | 977 | module_init(pti_init); |