aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Van Asbroeck <thesven73@gmail.com>2016-08-12 09:10:27 -0400
committerSebastian Reichel <sre@kernel.org>2016-08-12 16:42:25 -0400
commit5381cfb6f0422da24cfa9da35b0433c0415830e0 (patch)
treea740ad125b8dbf4436b1e6fc8d8570d97e66dd46
parent29b4817d4018df78086157ea3a55c1d9424a7cfc (diff)
power: supply: max17042_battery: fix model download bug.
The device's model download function returns the model data as an array of u32s, which is later compared to the reference model data. However, since the latter is an array of u16s, the comparison does not happen correctly, and model verification fails. This in turn breaks the POR initialization sequence. Fixes: 39e7213edc4f3 ("max17042_battery: Support regmap to access device's registers") Reported-by: Dan Carpenter <dan.carpenter@oracle.com> Signed-off-by: Sven Van Asbroeck <TheSven73@googlemail.com> Reviewed-by: Krzysztof Kozlowski <k.kozlowski@samsung.com> Signed-off-by: Sebastian Reichel <sre@kernel.org>
-rw-r--r--drivers/power/max17042_battery.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/drivers/power/max17042_battery.c b/drivers/power/max17042_battery.c
index 9c65f134d447..da7a75f82489 100644
--- a/drivers/power/max17042_battery.c
+++ b/drivers/power/max17042_battery.c
@@ -457,13 +457,16 @@ static inline void max17042_write_model_data(struct max17042_chip *chip,
457} 457}
458 458
459static inline void max17042_read_model_data(struct max17042_chip *chip, 459static inline void max17042_read_model_data(struct max17042_chip *chip,
460 u8 addr, u32 *data, int size) 460 u8 addr, u16 *data, int size)
461{ 461{
462 struct regmap *map = chip->regmap; 462 struct regmap *map = chip->regmap;
463 int i; 463 int i;
464 u32 tmp;
464 465
465 for (i = 0; i < size; i++) 466 for (i = 0; i < size; i++) {
466 regmap_read(map, addr + i, &data[i]); 467 regmap_read(map, addr + i, &tmp);
468 data[i] = (u16)tmp;
469 }
467} 470}
468 471
469static inline int max17042_model_data_compare(struct max17042_chip *chip, 472static inline int max17042_model_data_compare(struct max17042_chip *chip,
@@ -486,7 +489,7 @@ static int max17042_init_model(struct max17042_chip *chip)
486{ 489{
487 int ret; 490 int ret;
488 int table_size = ARRAY_SIZE(chip->pdata->config_data->cell_char_tbl); 491 int table_size = ARRAY_SIZE(chip->pdata->config_data->cell_char_tbl);
489 u32 *temp_data; 492 u16 *temp_data;
490 493
491 temp_data = kcalloc(table_size, sizeof(*temp_data), GFP_KERNEL); 494 temp_data = kcalloc(table_size, sizeof(*temp_data), GFP_KERNEL);
492 if (!temp_data) 495 if (!temp_data)
@@ -501,7 +504,7 @@ static int max17042_init_model(struct max17042_chip *chip)
501 ret = max17042_model_data_compare( 504 ret = max17042_model_data_compare(
502 chip, 505 chip,
503 chip->pdata->config_data->cell_char_tbl, 506 chip->pdata->config_data->cell_char_tbl,
504 (u16 *)temp_data, 507 temp_data,
505 table_size); 508 table_size);
506 509
507 max10742_lock_model(chip); 510 max10742_lock_model(chip);
@@ -514,7 +517,7 @@ static int max17042_verify_model_lock(struct max17042_chip *chip)
514{ 517{
515 int i; 518 int i;
516 int table_size = ARRAY_SIZE(chip->pdata->config_data->cell_char_tbl); 519 int table_size = ARRAY_SIZE(chip->pdata->config_data->cell_char_tbl);
517 u32 *temp_data; 520 u16 *temp_data;
518 int ret = 0; 521 int ret = 0;
519 522
520 temp_data = kcalloc(table_size, sizeof(*temp_data), GFP_KERNEL); 523 temp_data = kcalloc(table_size, sizeof(*temp_data), GFP_KERNEL);