diff options
author | Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com> | 2014-04-14 12:28:37 -0400 |
---|---|---|
committer | Tejun Heo <tj@kernel.org> | 2014-04-14 13:33:28 -0400 |
commit | 7a56c0ba266844d7b1964694c47eff2199986e83 (patch) | |
tree | 41db43f9c8f5e0c32b299645ffd77d1e46a49895 /drivers/ata | |
parent | c9eaa447e77efe77b7fa4c953bd62de8297fd6c5 (diff) |
pata_octeon_cf: use devm_kzalloc() to allocate cf_port
As a nice side effect this fixes the cf_port leak on
dma_coerce_mask_and_coherent() or ata_host_activate()
failure.
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: David Daney <david.daney@cavium.com>
Suggested-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
Diffstat (limited to 'drivers/ata')
-rw-r--r-- | drivers/ata/pata_octeon_cf.c | 50 |
1 files changed, 17 insertions, 33 deletions
diff --git a/drivers/ata/pata_octeon_cf.c b/drivers/ata/pata_octeon_cf.c index 83c4ddb1bc7f..2a97d3a531ec 100644 --- a/drivers/ata/pata_octeon_cf.c +++ b/drivers/ata/pata_octeon_cf.c | |||
@@ -865,7 +865,7 @@ static int octeon_cf_probe(struct platform_device *pdev) | |||
865 | if (node == NULL) | 865 | if (node == NULL) |
866 | return -EINVAL; | 866 | return -EINVAL; |
867 | 867 | ||
868 | cf_port = kzalloc(sizeof(*cf_port), GFP_KERNEL); | 868 | cf_port = devm_kzalloc(&pdev->dev, sizeof(*cf_port), GFP_KERNEL); |
869 | if (!cf_port) | 869 | if (!cf_port) |
870 | return -ENOMEM; | 870 | return -ENOMEM; |
871 | 871 | ||
@@ -881,10 +881,9 @@ static int octeon_cf_probe(struct platform_device *pdev) | |||
881 | n_size = of_n_size_cells(node); | 881 | n_size = of_n_size_cells(node); |
882 | 882 | ||
883 | reg_prop = of_find_property(node, "reg", ®_len); | 883 | reg_prop = of_find_property(node, "reg", ®_len); |
884 | if (!reg_prop || reg_len < sizeof(__be32)) { | 884 | if (!reg_prop || reg_len < sizeof(__be32)) |
885 | rv = -EINVAL; | 885 | return -EINVAL; |
886 | goto free_cf_port; | 886 | |
887 | } | ||
888 | cs_num = reg_prop->value; | 887 | cs_num = reg_prop->value; |
889 | cf_port->cs0 = be32_to_cpup(cs_num); | 888 | cf_port->cs0 = be32_to_cpup(cs_num); |
890 | 889 | ||
@@ -901,16 +900,13 @@ static int octeon_cf_probe(struct platform_device *pdev) | |||
901 | res_dma = platform_get_resource(dma_dev, IORESOURCE_MEM, 0); | 900 | res_dma = platform_get_resource(dma_dev, IORESOURCE_MEM, 0); |
902 | if (!res_dma) { | 901 | if (!res_dma) { |
903 | of_node_put(dma_node); | 902 | of_node_put(dma_node); |
904 | rv = -EINVAL; | 903 | return -EINVAL; |
905 | goto free_cf_port; | ||
906 | } | 904 | } |
907 | cf_port->dma_base = (u64)devm_ioremap_nocache(&pdev->dev, res_dma->start, | 905 | cf_port->dma_base = (u64)devm_ioremap_nocache(&pdev->dev, res_dma->start, |
908 | resource_size(res_dma)); | 906 | resource_size(res_dma)); |
909 | |||
910 | if (!cf_port->dma_base) { | 907 | if (!cf_port->dma_base) { |
911 | of_node_put(dma_node); | 908 | of_node_put(dma_node); |
912 | rv = -EINVAL; | 909 | return -EINVAL; |
913 | goto free_cf_port; | ||
914 | } | 910 | } |
915 | 911 | ||
916 | irq_handler = octeon_cf_interrupt; | 912 | irq_handler = octeon_cf_interrupt; |
@@ -921,41 +917,34 @@ static int octeon_cf_probe(struct platform_device *pdev) | |||
921 | of_node_put(dma_node); | 917 | of_node_put(dma_node); |
922 | } | 918 | } |
923 | res_cs1 = platform_get_resource(pdev, IORESOURCE_MEM, 1); | 919 | res_cs1 = platform_get_resource(pdev, IORESOURCE_MEM, 1); |
924 | if (!res_cs1) { | 920 | if (!res_cs1) |
925 | rv = -EINVAL; | 921 | return -EINVAL; |
926 | goto free_cf_port; | 922 | |
927 | } | ||
928 | cs1 = devm_ioremap_nocache(&pdev->dev, res_cs1->start, | 923 | cs1 = devm_ioremap_nocache(&pdev->dev, res_cs1->start, |
929 | resource_size(res_cs1)); | 924 | resource_size(res_cs1)); |
930 | |||
931 | if (!cs1) | 925 | if (!cs1) |
932 | goto free_cf_port; | 926 | return rv; |
927 | |||
928 | if (reg_len < (n_addr + n_size + 1) * sizeof(__be32)) | ||
929 | return -EINVAL; | ||
933 | 930 | ||
934 | if (reg_len < (n_addr + n_size + 1) * sizeof(__be32)) { | ||
935 | rv = -EINVAL; | ||
936 | goto free_cf_port; | ||
937 | } | ||
938 | cs_num += n_addr + n_size; | 931 | cs_num += n_addr + n_size; |
939 | cf_port->cs1 = be32_to_cpup(cs_num); | 932 | cf_port->cs1 = be32_to_cpup(cs_num); |
940 | } | 933 | } |
941 | 934 | ||
942 | res_cs0 = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 935 | res_cs0 = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
943 | 936 | if (!res_cs0) | |
944 | if (!res_cs0) { | 937 | return -EINVAL; |
945 | rv = -EINVAL; | ||
946 | goto free_cf_port; | ||
947 | } | ||
948 | 938 | ||
949 | cs0 = devm_ioremap_nocache(&pdev->dev, res_cs0->start, | 939 | cs0 = devm_ioremap_nocache(&pdev->dev, res_cs0->start, |
950 | resource_size(res_cs0)); | 940 | resource_size(res_cs0)); |
951 | |||
952 | if (!cs0) | 941 | if (!cs0) |
953 | goto free_cf_port; | 942 | return rv; |
954 | 943 | ||
955 | /* allocate host */ | 944 | /* allocate host */ |
956 | host = ata_host_alloc(&pdev->dev, 1); | 945 | host = ata_host_alloc(&pdev->dev, 1); |
957 | if (!host) | 946 | if (!host) |
958 | goto free_cf_port; | 947 | return rv; |
959 | 948 | ||
960 | ap = host->ports[0]; | 949 | ap = host->ports[0]; |
961 | ap->private_data = cf_port; | 950 | ap->private_data = cf_port; |
@@ -1020,17 +1009,12 @@ static int octeon_cf_probe(struct platform_device *pdev) | |||
1020 | 1009 | ||
1021 | ata_port_desc(ap, "cmd %p ctl %p", base, ap->ioaddr.ctl_addr); | 1010 | ata_port_desc(ap, "cmd %p ctl %p", base, ap->ioaddr.ctl_addr); |
1022 | 1011 | ||
1023 | |||
1024 | dev_info(&pdev->dev, "version " DRV_VERSION" %d bit%s.\n", | 1012 | dev_info(&pdev->dev, "version " DRV_VERSION" %d bit%s.\n", |
1025 | is_16bit ? 16 : 8, | 1013 | is_16bit ? 16 : 8, |
1026 | cf_port->is_true_ide ? ", True IDE" : ""); | 1014 | cf_port->is_true_ide ? ", True IDE" : ""); |
1027 | 1015 | ||
1028 | return ata_host_activate(host, irq, irq_handler, | 1016 | return ata_host_activate(host, irq, irq_handler, |
1029 | IRQF_SHARED, &octeon_cf_sht); | 1017 | IRQF_SHARED, &octeon_cf_sht); |
1030 | |||
1031 | free_cf_port: | ||
1032 | kfree(cf_port); | ||
1033 | return rv; | ||
1034 | } | 1018 | } |
1035 | 1019 | ||
1036 | static void octeon_cf_shutdown(struct device *dev) | 1020 | static void octeon_cf_shutdown(struct device *dev) |