From patchwork Fri Aug 12 13:10:27 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sven Van Asbroeck X-Patchwork-Id: 9276917 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E911760752 for ; Fri, 12 Aug 2016 13:11:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DA2FE289BB for ; Fri, 12 Aug 2016 13:11:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CEC6F289E9; Fri, 12 Aug 2016 13:11:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, FSL_HELO_FAKE, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 53130289BB for ; Fri, 12 Aug 2016 13:11:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752408AbcHLNK7 (ORCPT ); Fri, 12 Aug 2016 09:10:59 -0400 Received: from mail-it0-f65.google.com ([209.85.214.65]:33272 "EHLO mail-it0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751982AbcHLNK6 (ORCPT ); Fri, 12 Aug 2016 09:10:58 -0400 Received: by mail-it0-f65.google.com with SMTP id d65so891497ith.0; Fri, 12 Aug 2016 06:10:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:date:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=teGFzzmqCZIjYDKQPB3DwclxDNwkEUxmSf6WJc/8AEI=; b=A1hhvBvl258giRnXfLcNQRbzB4fhyEToRxsJKj0INGx5ljfKo3Xgc5NBvjqWsF2QHm kACyj5YFbQEGVKiqnMbAnVBM2kQ0CGruq1q1UWShQcEOXlWv0MIAcYMHnyz7AWkqPvt0 NMBXl1fIdx11HX/VIMkCx5LBEx4Oo0VqFKRCUUGPv5uxSBkUqvlMt5rvA9TwPTtbHQ/Z q8QOk3gUMLNxlw3L2LKK/twgWVv7pcN3T4cJvvbq2axtaefZitmleRtF5wogbkKWzfSO kmYEbswQ3aimEapQ0o1ju1b3XuV/gpEJcacYprom5L7qVTFPvqMvA8f0B60KZoX+2QiW 0FXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:date:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=teGFzzmqCZIjYDKQPB3DwclxDNwkEUxmSf6WJc/8AEI=; b=FnYqSlRzNnXX+szLsa3OqviSTEeyu8fScHpuBqBJKlQRRg572ZuIWdHMW59cd4x4tg iLjhoShvzCDf0VMOBUAOvzXQMIHJ1PB0NifOM5Aa9MjYAHdA7dBjIRu5Uhudfhsf89gg 1s3NyMQBVf+6v60VVM003LhuDjcnxUfAtBf3E7CxXtndRkvwqZipnvyw0QFoMj1xjwTN DnphLTxElpzdK9LdbymUJqlbE/LidDIT9hCQSbmJPmy8uPE5KZxg2nNyQ9cUuaTn1QzR i2WMELFgc94GDGo3hwcrwsXDTeAnyZV+KgKinr4BxtW/Bi95vQFc/ZU5XSIEKiGa3VTG 56pw== X-Gm-Message-State: AEkoouuGr764vUgPMu5fejdOSMv1kccmUbrdZJp9TzV1a+tDfHNAJGKW5StlSCCZy4c3Nw== X-Received: by 10.36.17.20 with SMTP id 20mr3332292itf.94.1471007430534; Fri, 12 Aug 2016 06:10:30 -0700 (PDT) Received: from gmail.com (184-94-50-30.dedicated.allstream.net. [184.94.50.30]) by smtp.gmail.com with ESMTPSA id o5sm998278ith.20.2016.08.12.06.10.29 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Fri, 12 Aug 2016 06:10:29 -0700 (PDT) From: Sven Van Asbroeck X-Google-Original-From: Sven Van Asbroeck Date: Fri, 12 Aug 2016 09:10:27 -0400 To: linux-kernel@vger.kernel.org, sre@kernel.org, linux-pm@vger.kernel.org Cc: stable@vger.kernel.org, jonghwa3.lee@samsung.com, k.kozlowski@samsung.com Subject: [PATCH V2] max17042_battery: fix model download bug. Message-ID: <20160812131026.GC5379@gmail.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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") Reviewed-by: Krzysztof Kozlowski Cc: Reported-by: Dan Carpenter Link: https://www.marc.info/?l=linux-pm&m=143954612610000&w=4 Signed-off-by: Sven Van Asbroeck --- drivers/power/max17042_battery.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/drivers/power/max17042_battery.c b/drivers/power/max17042_battery.c index 9c65f13..da7a75f 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, } static inline void max17042_read_model_data(struct max17042_chip *chip, - u8 addr, u32 *data, int size) + u8 addr, u16 *data, int size) { struct regmap *map = chip->regmap; int i; + u32 tmp; - for (i = 0; i < size; i++) - regmap_read(map, addr + i, &data[i]); + for (i = 0; i < size; i++) { + regmap_read(map, addr + i, &tmp); + data[i] = (u16)tmp; + } } static inline int max17042_model_data_compare(struct max17042_chip *chip, @@ -486,7 +489,7 @@ static int max17042_init_model(struct max17042_chip *chip) { int ret; int table_size = ARRAY_SIZE(chip->pdata->config_data->cell_char_tbl); - u32 *temp_data; + u16 *temp_data; temp_data = kcalloc(table_size, sizeof(*temp_data), GFP_KERNEL); if (!temp_data) @@ -501,7 +504,7 @@ static int max17042_init_model(struct max17042_chip *chip) ret = max17042_model_data_compare( chip, chip->pdata->config_data->cell_char_tbl, - (u16 *)temp_data, + temp_data, table_size); max10742_lock_model(chip); @@ -514,7 +517,7 @@ static int max17042_verify_model_lock(struct max17042_chip *chip) { int i; int table_size = ARRAY_SIZE(chip->pdata->config_data->cell_char_tbl); - u32 *temp_data; + u16 *temp_data; int ret = 0; temp_data = kcalloc(table_size, sizeof(*temp_data), GFP_KERNEL);