Commit 82b9dbe2e0f6870bf385b759b91e403b62a60c5e
Committed by
David Woodhouse
1 parent
e2f6bce8d9
Exists in
smarc-l5.0.0_1.0.0-ga
and in
5 other branches
mtd: nand/fsmc: Use devm routines
fsmc_nand driver currently uses normal kzalloc, request_mem etc routines. This patch replaces these routines with devm_kzalloc and devm_request_mem_region etc. Consequently, the error and driver removal scenarios are curtailed. Signed-off-by: Vipin Kumar <vipin.kumar@st.com> Reviewed-by: Viresh Kumar <viresh.kumar@st.com> Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com> Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Showing 1 changed file with 43 additions and 91 deletions Side-by-side Diff
drivers/mtd/nand/fsmc_nand.c
... | ... | @@ -298,11 +298,6 @@ |
298 | 298 | unsigned int bank; |
299 | 299 | struct clk *clk; |
300 | 300 | |
301 | - struct resource *resregs; | |
302 | - struct resource *rescmd; | |
303 | - struct resource *resaddr; | |
304 | - struct resource *resdata; | |
305 | - | |
306 | 301 | struct fsmc_nand_timings *dev_timings; |
307 | 302 | |
308 | 303 | void __iomem *data_va; |
309 | 304 | |
310 | 305 | |
311 | 306 | |
312 | 307 | |
313 | 308 | |
314 | 309 | |
315 | 310 | |
316 | 311 | |
317 | 312 | |
318 | 313 | |
319 | 314 | |
320 | 315 | |
321 | 316 | |
322 | 317 | |
323 | 318 | |
324 | 319 | |
... | ... | @@ -706,88 +701,81 @@ |
706 | 701 | } |
707 | 702 | |
708 | 703 | /* Allocate memory for the device structure (and zero it) */ |
709 | - host = kzalloc(sizeof(*host), GFP_KERNEL); | |
704 | + host = devm_kzalloc(&pdev->dev, sizeof(*host), GFP_KERNEL); | |
710 | 705 | if (!host) { |
711 | 706 | dev_err(&pdev->dev, "failed to allocate device structure\n"); |
712 | 707 | return -ENOMEM; |
713 | 708 | } |
714 | 709 | |
715 | 710 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "nand_data"); |
716 | - if (!res) { | |
717 | - ret = -EIO; | |
718 | - goto err_probe1; | |
719 | - } | |
711 | + if (!res) | |
712 | + return -EINVAL; | |
720 | 713 | |
721 | - host->resdata = request_mem_region(res->start, resource_size(res), | |
722 | - pdev->name); | |
723 | - if (!host->resdata) { | |
724 | - ret = -EIO; | |
725 | - goto err_probe1; | |
714 | + if (!devm_request_mem_region(&pdev->dev, res->start, resource_size(res), | |
715 | + pdev->name)) { | |
716 | + dev_err(&pdev->dev, "Failed to get memory data resourse\n"); | |
717 | + return -ENOENT; | |
726 | 718 | } |
727 | 719 | |
728 | - host->data_va = ioremap(res->start, resource_size(res)); | |
720 | + host->data_va = devm_ioremap(&pdev->dev, res->start, | |
721 | + resource_size(res)); | |
729 | 722 | if (!host->data_va) { |
730 | - ret = -EIO; | |
731 | - goto err_probe1; | |
723 | + dev_err(&pdev->dev, "data ioremap failed\n"); | |
724 | + return -ENOMEM; | |
732 | 725 | } |
733 | 726 | |
734 | - host->resaddr = request_mem_region(res->start + pdata->ale_off, | |
735 | - resource_size(res), pdev->name); | |
736 | - if (!host->resaddr) { | |
737 | - ret = -EIO; | |
738 | - goto err_probe1; | |
727 | + if (!devm_request_mem_region(&pdev->dev, res->start + pdata->ale_off, | |
728 | + resource_size(res), pdev->name)) { | |
729 | + dev_err(&pdev->dev, "Failed to get memory ale resourse\n"); | |
730 | + return -ENOENT; | |
739 | 731 | } |
740 | 732 | |
741 | - host->addr_va = ioremap(res->start + pdata->ale_off, | |
733 | + host->addr_va = devm_ioremap(&pdev->dev, res->start + pdata->ale_off, | |
742 | 734 | resource_size(res)); |
743 | 735 | if (!host->addr_va) { |
744 | - ret = -EIO; | |
745 | - goto err_probe1; | |
736 | + dev_err(&pdev->dev, "ale ioremap failed\n"); | |
737 | + return -ENOMEM; | |
746 | 738 | } |
747 | 739 | |
748 | - host->rescmd = request_mem_region(res->start + pdata->cle_off, | |
749 | - resource_size(res), pdev->name); | |
750 | - if (!host->rescmd) { | |
751 | - ret = -EIO; | |
752 | - goto err_probe1; | |
740 | + if (!devm_request_mem_region(&pdev->dev, res->start + pdata->cle_off, | |
741 | + resource_size(res), pdev->name)) { | |
742 | + dev_err(&pdev->dev, "Failed to get memory cle resourse\n"); | |
743 | + return -ENOENT; | |
753 | 744 | } |
754 | 745 | |
755 | - host->cmd_va = ioremap(res->start + pdata->cle_off, resource_size(res)); | |
746 | + host->cmd_va = devm_ioremap(&pdev->dev, res->start + pdata->cle_off, | |
747 | + resource_size(res)); | |
756 | 748 | if (!host->cmd_va) { |
757 | - ret = -EIO; | |
758 | - goto err_probe1; | |
749 | + dev_err(&pdev->dev, "ale ioremap failed\n"); | |
750 | + return -ENOMEM; | |
759 | 751 | } |
760 | 752 | |
761 | 753 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "fsmc_regs"); |
762 | - if (!res) { | |
763 | - ret = -EIO; | |
764 | - goto err_probe1; | |
765 | - } | |
754 | + if (!res) | |
755 | + return -EINVAL; | |
766 | 756 | |
767 | - host->resregs = request_mem_region(res->start, resource_size(res), | |
768 | - pdev->name); | |
769 | - if (!host->resregs) { | |
770 | - ret = -EIO; | |
771 | - goto err_probe1; | |
757 | + if (!devm_request_mem_region(&pdev->dev, res->start, resource_size(res), | |
758 | + pdev->name)) { | |
759 | + dev_err(&pdev->dev, "Failed to get memory regs resourse\n"); | |
760 | + return -ENOENT; | |
772 | 761 | } |
773 | 762 | |
774 | - host->regs_va = ioremap(res->start, resource_size(res)); | |
763 | + host->regs_va = devm_ioremap(&pdev->dev, res->start, | |
764 | + resource_size(res)); | |
775 | 765 | if (!host->regs_va) { |
776 | - ret = -EIO; | |
777 | - goto err_probe1; | |
766 | + dev_err(&pdev->dev, "regs ioremap failed\n"); | |
767 | + return -ENOMEM; | |
778 | 768 | } |
779 | 769 | |
780 | 770 | host->clk = clk_get(&pdev->dev, NULL); |
781 | 771 | if (IS_ERR(host->clk)) { |
782 | 772 | dev_err(&pdev->dev, "failed to fetch block clock\n"); |
783 | - ret = PTR_ERR(host->clk); | |
784 | - host->clk = NULL; | |
785 | - goto err_probe1; | |
773 | + return PTR_ERR(host->clk); | |
786 | 774 | } |
787 | 775 | |
788 | 776 | ret = clk_enable(host->clk); |
789 | 777 | if (ret) |
790 | - goto err_probe1; | |
778 | + goto err_clk_enable; | |
791 | 779 | |
792 | 780 | /* |
793 | 781 | * This device ID is actually a common AMBA ID as used on the |
... | ... | @@ -852,7 +840,7 @@ |
852 | 840 | if (nand_scan_ident(&host->mtd, 1, NULL)) { |
853 | 841 | ret = -ENXIO; |
854 | 842 | dev_err(&pdev->dev, "No NAND Device found!\n"); |
855 | - goto err_probe; | |
843 | + goto err_scan_ident; | |
856 | 844 | } |
857 | 845 | |
858 | 846 | if (AMBA_REV_BITS(host->pid) >= 8) { |
859 | 847 | |
... | ... | @@ -927,32 +915,10 @@ |
927 | 915 | return 0; |
928 | 916 | |
929 | 917 | err_probe: |
918 | +err_scan_ident: | |
930 | 919 | clk_disable(host->clk); |
931 | -err_probe1: | |
932 | - if (host->clk) | |
933 | - clk_put(host->clk); | |
934 | - if (host->regs_va) | |
935 | - iounmap(host->regs_va); | |
936 | - if (host->resregs) | |
937 | - release_mem_region(host->resregs->start, | |
938 | - resource_size(host->resregs)); | |
939 | - if (host->cmd_va) | |
940 | - iounmap(host->cmd_va); | |
941 | - if (host->rescmd) | |
942 | - release_mem_region(host->rescmd->start, | |
943 | - resource_size(host->rescmd)); | |
944 | - if (host->addr_va) | |
945 | - iounmap(host->addr_va); | |
946 | - if (host->resaddr) | |
947 | - release_mem_region(host->resaddr->start, | |
948 | - resource_size(host->resaddr)); | |
949 | - if (host->data_va) | |
950 | - iounmap(host->data_va); | |
951 | - if (host->resdata) | |
952 | - release_mem_region(host->resdata->start, | |
953 | - resource_size(host->resdata)); | |
954 | - | |
955 | - kfree(host); | |
920 | +err_clk_enable: | |
921 | + clk_put(host->clk); | |
956 | 922 | return ret; |
957 | 923 | } |
958 | 924 | |
959 | 925 | |
... | ... | @@ -969,22 +935,8 @@ |
969 | 935 | nand_release(&host->mtd); |
970 | 936 | clk_disable(host->clk); |
971 | 937 | clk_put(host->clk); |
972 | - | |
973 | - iounmap(host->regs_va); | |
974 | - release_mem_region(host->resregs->start, | |
975 | - resource_size(host->resregs)); | |
976 | - iounmap(host->cmd_va); | |
977 | - release_mem_region(host->rescmd->start, | |
978 | - resource_size(host->rescmd)); | |
979 | - iounmap(host->addr_va); | |
980 | - release_mem_region(host->resaddr->start, | |
981 | - resource_size(host->resaddr)); | |
982 | - iounmap(host->data_va); | |
983 | - release_mem_region(host->resdata->start, | |
984 | - resource_size(host->resdata)); | |
985 | - | |
986 | - kfree(host); | |
987 | 938 | } |
939 | + | |
988 | 940 | return 0; |
989 | 941 | } |
990 | 942 |