From patchwork Fri Apr 13 11:00:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 897907 Return-Path: X-Original-To: incoming-imx@patchwork.ozlabs.org Delivered-To: patchwork-incoming-imx@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-arm-kernel-bounces+incoming-imx=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="W1cHy5ne"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="dsxGIQqo"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40Mvvs2tq2z9s15 for ; Fri, 13 Apr 2018 21:00:57 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=GPdShIaa8Av3E3vYEb/9+Cmz9JqA7hve/DtLRnW2f3Q=; b=W1cHy5neVHBcR5 DzMUy4PonmRb3rFoJpLHAo93gdMwngUUoyPR8hs1cCm68kSJ/7b9lSi7FvwP5C83tWnl/mt4GJ0Vj zuVHB9UdjbZ0vzlMRsz/lNwPyCgYYf36PxhWYrN8xoAy/Wa1tDWbBTkkxrTy2huycKzu0144ttxq2 uDOwnD7BIqiu6wtzyzFit/TJLtR+rEeHFOY5FbhSW6D13H2JkkdrKMlnQ9g1G1RiLj80zOo1QcrIO 3jo6dBWhGZ2KP+3pw1jWmebXd63mn+LQ9s+cY1D74qBTs7X6OeY4mwtZSt2RUfu5pndFZ3uNVM8eC 4njm/HT4aM5x7n0fiOCQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1f6wRj-0001I0-S1; Fri, 13 Apr 2018 11:00:47 +0000 Received: from mail-wr0-x244.google.com ([2a00:1450:400c:c0c::244]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1f6wRc-0001EI-Jw for linux-arm-kernel@lists.infradead.org; Fri, 13 Apr 2018 11:00:42 +0000 Received: by mail-wr0-x244.google.com with SMTP id o3so7898645wri.2 for ; Fri, 13 Apr 2018 04:00:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DnxfjNnBwv14YjSYfGmUW5KVjwMfhGQA/J6NNUBHe0c=; b=dsxGIQqoKPosQOWl0Vy3ueJvbGzPUno4V8cWxA76V6pd5UgpD2EHSTw0pJmfClebr/ B2kFFjXjjGgP+LTqvlubEJD5DiBsznD7Dx2pfqdc4CBE8yxTTajJgWBztIx9HStL2Lo5 g9yOXNNQfwMktxudu0qyx9VSoNAI4i4AYZ1PE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DnxfjNnBwv14YjSYfGmUW5KVjwMfhGQA/J6NNUBHe0c=; b=D7aSEbLtiOk8a38kJg+40aP9zEwiA6yv8X7bfZsOoIOQYGmsvEyhu2ASVF/AQuOGhq VekR3IXPKhvfrEXHSRsT/UTokUFXngAkA+NgNYVjGJN5JyzrglNNYy3H+unR/oqCNF0p HYzsEjVeIdfYNpkp+8BsecTQp+/fp10qOGmk/1Kkz7YE+8we8yj+HsBh35ocTqYNULNv qA2mjspOfmxiuv+GptP5wU4ihhiYQ5mmcW3+VhlhR2fAHl/Rk2qkDQCNARjQ2AGO4+H/ ropIblxAf5jBN5EZ8xNbE/O6x8eaMMI+7pqILG+YqotgdVsTJko9PG4SOF4LtFJW1DpR l9cQ== X-Gm-Message-State: ALQs6tBECCwp8uKcnyrbgJ92KOBzaveTCrvoD7++as+1rGXPjSDDBVHp ILedLEKx+M/El04z7XoSM4LaEw== X-Google-Smtp-Source: AIpwx4+4/JhOLZrdRmxAL4EuX9zepmcJatQzQVDUm6uUxGKUMMujWugoJCVCR/x/xZowMFqBVSZP/Q== X-Received: by 10.223.128.40 with SMTP id 37mr3579492wrk.73.1523617228318; Fri, 13 Apr 2018 04:00:28 -0700 (PDT) Received: from localhost.localdomain ([2a01:e35:879a:6cd0:715b:55d4:43eb:74d5]) by smtp.gmail.com with ESMTPSA id h7sm1275845wme.0.2018.04.13.04.00.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 13 Apr 2018 04:00:27 -0700 (PDT) From: Daniel Lezcano To: b.zolnierkie@samsung.com, edubezval@gmail.com, rui.zhang@intel.com Subject: [PATCH] thermal/drivers/exynos_tmu: Fix warnings in temp_to_code / code_to_temp Date: Fri, 13 Apr 2018 13:00:09 +0200 Message-Id: <1523617209-1730-1-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <10298074.ogKH1ypqfx@amdc3058> References: <10298074.ogKH1ypqfx@amdc3058> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180413_040040_704559_6EACA209 X-CRM114-Status: GOOD ( 15.36 ) X-Spam-Score: -0.1 (/) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-0.1 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [2a00:1450:400c:c0c:0:0:0:244 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "open list:SAMSUNG THERMAL DRIVER" , linux-pm@vger.kernel.org, daniel.lezcano@linaro.org, linux-kernel@vger.kernel.org, Krzysztof Kozlowski , philip.li@intel.com, Kukjin Kim , "moderated list:ARM/SAMSUNG EXYNOS ARM ARCHITECTURES" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+incoming-imx=patchwork.ozlabs.org@lists.infradead.org List-Id: linux-imx-kernel.lists.patchwork.ozlabs.org The latest driver cleanup introduced a compilation warning drivers/thermal/samsung/exynos_tmu.c: In function ‘exynos_get_temp’: drivers/thermal/samsung/exynos_tmu.c:931:37: warning: ‘temp’ may be used uninitialized in this function [-Wmaybe-uninitialized] *temp = code_to_temp(data, value) * MCELSIUS; ^ drivers/thermal/samsung/exynos_tmu.c: In function ‘temp_to_code’ drivers/thermal/samsung/exynos_tmu.c:304:9: warning: ‘temp_code’ may be used uninitialized in this function [-Wmaybe-uninitialized] return temp_code; ^~~~~~~~~ The compiler gives a warning because semantically speaking the function has no default value. However the code path, were the variable is never initialized is a dead branch because the switch statement always choose one of the two cases as the data->cal_type is initialized in the init function to one of both values. This is unclear as it adds a dependency on the initialization function and it is prone to error. Make things clearer by converting the functions with if ... return statements, thus showing we are expecting the values to be correctly filled before calling this function. This change fixes the couple of function warnings. Signed-off-by: Daniel Lezcano Acked-by: Bartlomiej Zolnierkiewicz --- drivers/thermal/samsung/exynos_tmu.c | 46 ++++++++++-------------------------- 1 file changed, 12 insertions(+), 34 deletions(-) diff --git a/drivers/thermal/samsung/exynos_tmu.c b/drivers/thermal/samsung/exynos_tmu.c index 2ec8548..197f267 100644 --- a/drivers/thermal/samsung/exynos_tmu.c +++ b/drivers/thermal/samsung/exynos_tmu.c @@ -284,24 +284,13 @@ static void exynos_report_trigger(struct exynos_tmu_data *p) */ static int temp_to_code(struct exynos_tmu_data *data, u8 temp) { - int temp_code; - - switch (data->cal_type) { - case TYPE_TWO_POINT_TRIMMING: - temp_code = (temp - EXYNOS_FIRST_POINT_TRIM) * - (data->temp_error2 - data->temp_error1) / - (EXYNOS_SECOND_POINT_TRIM - EXYNOS_FIRST_POINT_TRIM) + - data->temp_error1; - break; - case TYPE_ONE_POINT_TRIMMING: - temp_code = temp + data->temp_error1 - EXYNOS_FIRST_POINT_TRIM; - break; - default: - WARN_ON(1); - break; - } + if (data->cal_type == TYPE_ONE_POINT_TRIMMING) + return temp + data->temp_error1 - EXYNOS_FIRST_POINT_TRIM; - return temp_code; + return (temp - EXYNOS_FIRST_POINT_TRIM) * + (data->temp_error2 - data->temp_error1) / + (EXYNOS_SECOND_POINT_TRIM - EXYNOS_FIRST_POINT_TRIM) + + data->temp_error1; } /* @@ -310,24 +299,13 @@ static int temp_to_code(struct exynos_tmu_data *data, u8 temp) */ static int code_to_temp(struct exynos_tmu_data *data, u16 temp_code) { - int temp; - - switch (data->cal_type) { - case TYPE_TWO_POINT_TRIMMING: - temp = (temp_code - data->temp_error1) * - (EXYNOS_SECOND_POINT_TRIM - EXYNOS_FIRST_POINT_TRIM) / - (data->temp_error2 - data->temp_error1) + - EXYNOS_FIRST_POINT_TRIM; - break; - case TYPE_ONE_POINT_TRIMMING: - temp = temp_code - data->temp_error1 + EXYNOS_FIRST_POINT_TRIM; - break; - default: - WARN_ON(1); - break; - } + if (data->cal_type == TYPE_ONE_POINT_TRIMMING) + return temp_code - data->temp_error1 + EXYNOS_FIRST_POINT_TRIM; - return temp; + return (temp_code - data->temp_error1) * + (EXYNOS_SECOND_POINT_TRIM - EXYNOS_FIRST_POINT_TRIM) / + (data->temp_error2 - data->temp_error1) + + EXYNOS_FIRST_POINT_TRIM; } static void sanitize_temp_error(struct exynos_tmu_data *data, u32 trim_info)