Received: by 10.192.165.156 with SMTP id m28csp555543imm; Fri, 13 Apr 2018 04:01:57 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/mO9yTf0HftgjTVcQr/4ecff0rTDhRbpfgqAS5J7iM+jzKiQ7gw/yfIbIfiRctieD5rARw X-Received: by 10.101.82.194 with SMTP id z2mr3811174pgp.69.1523617317270; Fri, 13 Apr 2018 04:01:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523617317; cv=none; d=google.com; s=arc-20160816; b=rsdS7dTLrl8T0m2W4SUGpSsDkFqfQlcfkPk7yg7ttXXbjXvvR7lQNcniDH+GdEI67E JFTX6gTq9pB4RhxDUi3g5whri78QU6DkMvscBV0+TEqsNlqTPQvtI08CCSDX8YVgVAde yn2tGJgBbXYaDZ9I01hXdTWUxd+5s41knRYnmfk2k7nZGoRQ7OLGvXlrM6LK1UR3wTxf uciAVMjQefWOWomZWxbnkJmtc3v87+TeNp6VRDLFmiBrPu2XZTVdrJecslZ79tkklJKn jr3lFWB6t2A82wJfMDqgFLYK9aTxQxGzxnhQcXSgCo+oYHHJ576Z9jrLKZv5G1itVNR8 SP/A== 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=DnxfjNnBwv14YjSYfGmUW5KVjwMfhGQA/J6NNUBHe0c=; b=hkXaQA4NQab7vzTeVWc6MQ6QolJQqMboEjsbP9lEd4IxSIgvSNQU/u3MKwJD/ITQSN uK7gmrz5OGVZaw0LE7KFu1u2oDMsntghqqIwqOI5h+7ScAdTrNtIDmabcVK1MaswRS4I N3EsDkKXFXA/Gz4oyhC2mDKw1iy/Du7BX2NrhDP+X6qmGhsW7PxlwTTS8LAyZKNmYf9n 62DCfXIP3JQNEOX2g9e6cqZx+YCxqKtrbpaM9RHArYggaW83Z4S0vX1StOkNpuLM5R6w Ip4ZpesYhZA5SIleqEOshROVnYnC4gBHi5oFHcevKSIopmSoKcXBo3LV9LSIW9KeQYpX vXzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dsxGIQqo; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (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 b8si3671234pfl.223.2018.04.13.04.01.43; Fri, 13 Apr 2018 04:01:57 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dsxGIQqo; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754104AbeDMLAc (ORCPT + 99 others); Fri, 13 Apr 2018 07:00:32 -0400 Received: from mail-wr0-f194.google.com ([209.85.128.194]:41872 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752940AbeDMLA3 (ORCPT ); Fri, 13 Apr 2018 07:00:29 -0400 Received: by mail-wr0-f194.google.com with SMTP id s12so7874311wrc.8 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=UfBknNjXoyB+zD8lq6H0ZrgDQb5s8dxGGAe2kUPiEaVjp+L28hSWQnnHNdpNyXWmqt Zv9iyT2qaP3nUuZE6FTCy+tevuG7lZrRVQ6hdRq5vV+X6REZrgCcynYtKrw99MQGiUFi E6pD5JxN0GTQm2X5uWV40xgjrZivYJ6oA6AeHxCXrrycuwHPMcgIlyxrpUjY5ZRseGIQ IrI9wH7CmBq13B7H3uNB7L1YumRLoubGbCc6SlaP8vczb+GUXipH7j2DElaCMQpDcQ4J ELtRAHKPn8ItOfzWMzPBgUJ1VEXbiT3+rSMznOboO91jTs01UO+nIEh8QrT4eeWo8FRl 7yzg== X-Gm-Message-State: ALQs6tBY11IIQXdwNOxhISwC/rb43z4zO1Rr6/NY7rEiqo7gHT+AhIo1 OlSRWzpb6jxx1YAPt9UkG0HwZQ1mim0= 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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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(-) 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) -- 2.7.4