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: 133359 Delivered-To: patch@linaro.org Received: by 10.46.84.18 with SMTP id i18csp599609ljb; Fri, 13 Apr 2018 04:00:32 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+16/Qs5puKg6CINwnZYuesu3kRVecydKGDODdDuvCLiC+M2tMf6VU9jHQQF7HjH6J8GhzV X-Received: by 2002:a17:902:24a5:: with SMTP id w34-v6mr4832126pla.328.1523617231878; Fri, 13 Apr 2018 04:00:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523617231; cv=none; d=google.com; s=arc-20160816; b=RvNy77VkVZVqW/0YhAjgTkY1gRj5dHHTG0UaVkZNh1j0hMinx8x+g7dQAc3wtGig39 NIQ3fei4OJiuVQ/NMouS81AJWznkcPqKtsktNMyS7J17zMD8nCG3X98o+iuCwDZbd7i4 EtED3oo5uxEcMLWBFa60nAMb0cw9imbb4f1us9tMH5pxI9jx/NDxdWOI9GrSkcUSiooa z/gQqPLG1D7xDtHR5NCOVge7Kj50vnKsROMu5gAoIEITTcsR4IYA2msK1q/edsXnp+B9 HDBv1ivJE8175b0Sg3gMAGi/y94uqWC2xPex65D2AfdppQJVc3201eemEidsIvtNamUt 0itg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=9x2D9Gh6r/7JN/TMLKTY8IgZu512B4t9GVBqlyNe8Vo=; b=gDzYOdpDLWujDXaJV5SFBEFtKq/DxMIZ3SGQukXWDoh/7v7bnBctAXOMUPUYptVh8t aRm851+1x8E9B2cIdIBNvXVNU5rMI0bt+EbtHKv8wlCzBn3WbYxxxZLfv2Bs/wIhFHkh ERl3IleK4MbciayYaNJ+eI6i3xNAfeQce2aviDzvgjdQqohQAinyG7iPbrzx6S5+Hk+x T3SjBGAsaIGmPwLCSNyfldODcPj3aJcS+5FGaYtkAykHZoXVA9GzAp12fjI1X1KcfWTv sf2wOYsjVqOBEXqBkn6sTFQGpGShbTty5cXAKFypcERNpAKTpal0RBmCOLpDjKp7st15 dD1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=dsxGIQqo; spf=pass (google.com: best guess record for domain of linux-samsung-soc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-samsung-soc-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b35-v6si5363914plh.84.2018.04.13.04.00.31; Fri, 13 Apr 2018 04:00:31 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-samsung-soc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=dsxGIQqo; spf=pass (google.com: best guess record for domain of linux-samsung-soc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-samsung-soc-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753927AbeDMLAa (ORCPT + 3 others); Fri, 13 Apr 2018 07:00:30 -0400 Received: from mail-wr0-f193.google.com ([209.85.128.193]:44056 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752929AbeDMLA3 (ORCPT ); Fri, 13 Apr 2018 07:00:29 -0400 Received: by mail-wr0-f193.google.com with SMTP id u46so7883579wrc.11 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=G9SBcEVdwWuoi4xLpZqcVbRHgo0ziJVPSMZAu1DakvrXd6AUOTXdBCfxvQXrBqq3IT WLayyKPcCHH51TVWlGwqCSyIBRClwAoQrC+eQbkrT43uhRgjBaQoapr1myWCdqec3RnC 0CavrNS3DxFv8yL4QbtiNfbo5wjXruudO+o2GveYXgtWtVeP6T/eVjEdwiUJPzwr8xW3 CBLt+0RyB5CE9Q4lzzS8XGWxEQ2WNOpgbSr21vN8gCq5Bfp0Q0tMRsMxk0YNIDPgBIBw vP68GDFMbw2UIYamH6KjNxU+DCt4qmaTMwRUn2OtEa1FeaCiK4IBYjIdE9NBsD0NZmiE Icgg== X-Gm-Message-State: ALQs6tA5SStzA7319Jhjqywaa5BwHqGbsD59DzH4G6fxoBt8A27gHwKn TuxT43PLwe9R+2Y+Y7Hf9JV9UQ== 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 Cc: philip.li@intel.com, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, daniel.lezcano@linaro.org, Kukjin Kim , Krzysztof Kozlowski , linux-samsung-soc@vger.kernel.org (open list:SAMSUNG THERMAL DRIVER), linux-arm-kernel@lists.infradead.org (moderated list:ARM/SAMSUNG EXYNOS ARM ARCHITECTURES) 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 Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.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 --- drivers/thermal/samsung/exynos_tmu.c | 46 ++++++++++-------------------------- 1 file changed, 12 insertions(+), 34 deletions(-) -- 2.7.4 -- To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Acked-by: Bartlomiej Zolnierkiewicz 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)