aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/regulator/max8998.c
diff options
context:
space:
mode:
authorAxel Lin <axel.lin@gmail.com>2012-04-18 21:47:37 -0400
committerMark Brown <broonie@opensource.wolfsonmicro.com>2012-04-23 08:20:27 -0400
commit0f80ea1499ae047dcaa29ccecfe0d58bb229c4e9 (patch)
treebfdb673754c520d9728d635466e76807f0c11f00 /drivers/regulator/max8998.c
parent8ae5767ba1c4e149ee9970aa7a4e9bf6b251bb77 (diff)
regulator: max8998: Convert ot use devm_kzalloc
Also simplify the error handling to start unwind from the place regulator_register fails. No need to check rdev[i] is NULL or not before calling regulator_unregister. regulator_unregister is safe if rdev is NULL, Signed-off-by: Axel Lin <axel.lin@gmail.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'drivers/regulator/max8998.c')
-rw-r--r--drivers/regulator/max8998.c45
1 files changed, 17 insertions, 28 deletions
diff --git a/drivers/regulator/max8998.c b/drivers/regulator/max8998.c
index 052ee3594af7..18bb58b9b96e 100644
--- a/drivers/regulator/max8998.c
+++ b/drivers/regulator/max8998.c
@@ -718,16 +718,15 @@ static __devinit int max8998_pmic_probe(struct platform_device *pdev)
718 return -ENODEV; 718 return -ENODEV;
719 } 719 }
720 720
721 max8998 = kzalloc(sizeof(struct max8998_data), GFP_KERNEL); 721 max8998 = devm_kzalloc(&pdev->dev, sizeof(struct max8998_data),
722 GFP_KERNEL);
722 if (!max8998) 723 if (!max8998)
723 return -ENOMEM; 724 return -ENOMEM;
724 725
725 size = sizeof(struct regulator_dev *) * pdata->num_regulators; 726 size = sizeof(struct regulator_dev *) * pdata->num_regulators;
726 max8998->rdev = kzalloc(size, GFP_KERNEL); 727 max8998->rdev = devm_kzalloc(&pdev->dev, size, GFP_KERNEL);
727 if (!max8998->rdev) { 728 if (!max8998->rdev)
728 kfree(max8998);
729 return -ENOMEM; 729 return -ENOMEM;
730 }
731 730
732 rdev = max8998->rdev; 731 rdev = max8998->rdev;
733 max8998->dev = &pdev->dev; 732 max8998->dev = &pdev->dev;
@@ -751,14 +750,14 @@ static __devinit int max8998_pmic_probe(struct platform_device *pdev)
751 printk(KERN_ERR "MAX8998 SET1 GPIO defined as 0 !\n"); 750 printk(KERN_ERR "MAX8998 SET1 GPIO defined as 0 !\n");
752 WARN_ON(!pdata->buck1_set1); 751 WARN_ON(!pdata->buck1_set1);
753 ret = -EIO; 752 ret = -EIO;
754 goto err_free_mem; 753 goto err_out;
755 } 754 }
756 /* Check if SET2 is not equal to 0 */ 755 /* Check if SET2 is not equal to 0 */
757 if (!pdata->buck1_set2) { 756 if (!pdata->buck1_set2) {
758 printk(KERN_ERR "MAX8998 SET2 GPIO defined as 0 !\n"); 757 printk(KERN_ERR "MAX8998 SET2 GPIO defined as 0 !\n");
759 WARN_ON(!pdata->buck1_set2); 758 WARN_ON(!pdata->buck1_set2);
760 ret = -EIO; 759 ret = -EIO;
761 goto err_free_mem; 760 goto err_out;
762 } 761 }
763 762
764 gpio_request(pdata->buck1_set1, "MAX8998 BUCK1_SET1"); 763 gpio_request(pdata->buck1_set1, "MAX8998 BUCK1_SET1");
@@ -778,7 +777,7 @@ static __devinit int max8998_pmic_probe(struct platform_device *pdev)
778 max8998->buck1_vol[0] = i; 777 max8998->buck1_vol[0] = i;
779 ret = max8998_write_reg(i2c, MAX8998_REG_BUCK1_VOLTAGE1, i); 778 ret = max8998_write_reg(i2c, MAX8998_REG_BUCK1_VOLTAGE1, i);
780 if (ret) 779 if (ret)
781 goto err_free_mem; 780 goto err_out;
782 781
783 /* Set predefined value for BUCK1 register 2 */ 782 /* Set predefined value for BUCK1 register 2 */
784 i = 0; 783 i = 0;
@@ -790,7 +789,7 @@ static __devinit int max8998_pmic_probe(struct platform_device *pdev)
790 max8998->buck1_vol[1] = i; 789 max8998->buck1_vol[1] = i;
791 ret = max8998_write_reg(i2c, MAX8998_REG_BUCK1_VOLTAGE2, i); 790 ret = max8998_write_reg(i2c, MAX8998_REG_BUCK1_VOLTAGE2, i);
792 if (ret) 791 if (ret)
793 goto err_free_mem; 792 goto err_out;
794 793
795 /* Set predefined value for BUCK1 register 3 */ 794 /* Set predefined value for BUCK1 register 3 */
796 i = 0; 795 i = 0;
@@ -802,7 +801,7 @@ static __devinit int max8998_pmic_probe(struct platform_device *pdev)
802 max8998->buck1_vol[2] = i; 801 max8998->buck1_vol[2] = i;
803 ret = max8998_write_reg(i2c, MAX8998_REG_BUCK1_VOLTAGE3, i); 802 ret = max8998_write_reg(i2c, MAX8998_REG_BUCK1_VOLTAGE3, i);
804 if (ret) 803 if (ret)
805 goto err_free_mem; 804 goto err_out;
806 805
807 /* Set predefined value for BUCK1 register 4 */ 806 /* Set predefined value for BUCK1 register 4 */
808 i = 0; 807 i = 0;
@@ -814,7 +813,7 @@ static __devinit int max8998_pmic_probe(struct platform_device *pdev)
814 max8998->buck1_vol[3] = i; 813 max8998->buck1_vol[3] = i;
815 ret = max8998_write_reg(i2c, MAX8998_REG_BUCK1_VOLTAGE4, i); 814 ret = max8998_write_reg(i2c, MAX8998_REG_BUCK1_VOLTAGE4, i);
816 if (ret) 815 if (ret)
817 goto err_free_mem; 816 goto err_out;
818 817
819 } 818 }
820 819
@@ -824,7 +823,7 @@ static __devinit int max8998_pmic_probe(struct platform_device *pdev)
824 printk(KERN_ERR "MAX8998 SET3 GPIO defined as 0 !\n"); 823 printk(KERN_ERR "MAX8998 SET3 GPIO defined as 0 !\n");
825 WARN_ON(!pdata->buck2_set3); 824 WARN_ON(!pdata->buck2_set3);
826 ret = -EIO; 825 ret = -EIO;
827 goto err_free_mem; 826 goto err_out;
828 } 827 }
829 gpio_request(pdata->buck2_set3, "MAX8998 BUCK2_SET3"); 828 gpio_request(pdata->buck2_set3, "MAX8998 BUCK2_SET3");
830 gpio_direction_output(pdata->buck2_set3, 829 gpio_direction_output(pdata->buck2_set3,
@@ -839,7 +838,7 @@ static __devinit int max8998_pmic_probe(struct platform_device *pdev)
839 max8998->buck2_vol[0] = i; 838 max8998->buck2_vol[0] = i;
840 ret = max8998_write_reg(i2c, MAX8998_REG_BUCK2_VOLTAGE1, i); 839 ret = max8998_write_reg(i2c, MAX8998_REG_BUCK2_VOLTAGE1, i);
841 if (ret) 840 if (ret)
842 goto err_free_mem; 841 goto err_out;
843 842
844 /* BUCK2 register 2 */ 843 /* BUCK2 register 2 */
845 i = 0; 844 i = 0;
@@ -850,7 +849,7 @@ static __devinit int max8998_pmic_probe(struct platform_device *pdev)
850 max8998->buck2_vol[1] = i; 849 max8998->buck2_vol[1] = i;
851 ret = max8998_write_reg(i2c, MAX8998_REG_BUCK2_VOLTAGE2, i); 850 ret = max8998_write_reg(i2c, MAX8998_REG_BUCK2_VOLTAGE2, i);
852 if (ret) 851 if (ret)
853 goto err_free_mem; 852 goto err_out;
854 } 853 }
855 854
856 for (i = 0; i < pdata->num_regulators; i++) { 855 for (i = 0; i < pdata->num_regulators; i++) {
@@ -880,14 +879,9 @@ static __devinit int max8998_pmic_probe(struct platform_device *pdev)
880 879
881 return 0; 880 return 0;
882err: 881err:
883 for (i = 0; i < max8998->num_regulators; i++) 882 while (--i >= 0)
884 if (rdev[i]) 883 regulator_unregister(rdev[i]);
885 regulator_unregister(rdev[i]); 884err_out:
886
887err_free_mem:
888 kfree(max8998->rdev);
889 kfree(max8998);
890
891 return ret; 885 return ret;
892} 886}
893 887
@@ -898,12 +892,7 @@ static int __devexit max8998_pmic_remove(struct platform_device *pdev)
898 int i; 892 int i;
899 893
900 for (i = 0; i < max8998->num_regulators; i++) 894 for (i = 0; i < max8998->num_regulators; i++)
901 if (rdev[i]) 895 regulator_unregister(rdev[i]);
902 regulator_unregister(rdev[i]);
903
904 kfree(max8998->rdev);
905 kfree(max8998);
906
907 return 0; 896 return 0;
908} 897}
909 898