Commit d884ee3ece668ecc56cba7fdc8582a9680f2697b

Authored by Kyle Manna
Committed by Afzal Mohammed
1 parent cf2ad47409
Exists in master

regulator: TPS65910: Create an array for reg init data

Create an array of fixed size for the platform to pass regulator
initalization data through.

Passing an array of pointers to init data also allows more flexible
definition of init data as well as prevents reading past the end of the
array should the platform define an incorrectly sized array.

Signed-off-by: Kyle Manna <kyle.manna@fuel7.com>

Showing 2 changed files with 14 additions and 4 deletions Side-by-side Diff

drivers/regulator/tps65910-regulator.c
... ... @@ -861,8 +861,6 @@
861 861 if (!pmic_plat_data)
862 862 return -EINVAL;
863 863  
864   - reg_data = pmic_plat_data->tps65910_pmic_init_data;
865   -
866 864 pmic = kzalloc(sizeof(*pmic), GFP_KERNEL);
867 865 if (!pmic)
868 866 return -ENOMEM;
... ... @@ -913,7 +911,16 @@
913 911 goto err_free_info;
914 912 }
915 913  
916   - for (i = 0; i < pmic->num_regulators; i++, info++, reg_data++) {
  914 + for (i = 0; i < pmic->num_regulators && i < TPS65910_NUM_REGS;
  915 + i++, info++) {
  916 +
  917 + reg_data = pmic_plat_data->tps65910_pmic_init_data[i];
  918 +
  919 + /* Regulator API handles empty constraints but not NULL
  920 + * constraints */
  921 + if (!reg_data)
  922 + continue;
  923 +
917 924 /* Register the regulators */
918 925 pmic->info[i] = info;
919 926  
include/linux/mfd/tps65910.h
... ... @@ -771,6 +771,9 @@
771 771 #define TPS65911_REG_LDO7 11
772 772 #define TPS65911_REG_LDO8 12
773 773  
  774 +/* Max number of TPS65910/11 regulators */
  775 +#define TPS65910_NUM_REGS 13
  776 +
774 777 /**
775 778 * struct tps65910_board
776 779 * Board platform data may be used to initialize regulators.
... ... @@ -782,7 +785,7 @@
782 785 int irq_base;
783 786 int vmbch_threshold;
784 787 int vmbch2_threshold;
785   - struct regulator_init_data *tps65910_pmic_init_data;
  788 + struct regulator_init_data *tps65910_pmic_init_data[TPS65910_NUM_REGS];
786 789 };
787 790  
788 791 /**