Received: by 10.192.165.156 with SMTP id m28csp252697imm; Thu, 12 Apr 2018 21:22:49 -0700 (PDT) X-Google-Smtp-Source: AIpwx48FH7YuL2393QS77lNNInC+MEKsXKDZ/C5qGe9RIovcA+nnnO8DrL1gjqNLJUCLzIGZMzEb X-Received: by 10.99.119.2 with SMTP id s2mr2845221pgc.436.1523593369500; Thu, 12 Apr 2018 21:22:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523593369; cv=none; d=google.com; s=arc-20160816; b=arKZvTHGHaja6hHeEqXlaWgpv7VVHVeIdqKR9dR+WWbfLuXHmXqhP5cC1Y2o7hWudq 38pro1exEHXlvSFTkGlPjsXNrEh3QyvFAqndgDHXiuxmLTwDWuvx5HAEC854BPM+p8hq yN+5OLCkK1F6nEl0JrT2gikBCngWtnQqTJm5AcOkheNH2qNzheLegmSLeQ9GrGYvHEyh 19Qy62NMx0iv5rT1U0r6NeOflM4Jy7qfJhxDw7ecRirXcg5mNMsWV22mcNlCST451a0L GvOlBbKx2Hzxr16Wm1xpxKBhV2/8xsd+dmB/oF1hpTBqxIARU3wDN/kAxj4Kc13ncq9c /yOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=0Qm+ERQOtPeAFfe6TPEZ2HJhJjipScxLf8RZ7LlRmgg=; b=chYksiAeEFO7vETUy2qmrY9AW8uOnlHKhohbFDSb1FfHg8L7eUP+70eMnhlUeJX0Y7 w4JIKVHtPW2uakZWD0QGA1rC1Q1oPHvsxAWaS7o22msVji4NQ2ytNsY1FgzH2FfFqbFy uVyrodZouI74F/wbWyaUN2X603zz/UxsVgCYVh7Sz8sTkT6gz9iypT1fvI9JgGGAjV5v P9iZ8Ezh7Xz5Hp7VrDgEPFAhm5RX3SpAoAPb3rJENbhLSiuiFiUfzddkifd9PtGZ3RDx r1033CfEg7b93wk0XeGytgLWUrd+oP/ppuFtqPg+tZNrGnAPRAdptSLCHwsrNAHphGfQ 8b+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=nPgrGRmf; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w4si3409180pgo.305.2018.04.12.21.22.34; Thu, 12 Apr 2018 21:22:49 -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=@gmail.com header.s=20161025 header.b=nPgrGRmf; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751208AbeDMEJD (ORCPT + 99 others); Fri, 13 Apr 2018 00:09:03 -0400 Received: from mail-pg0-f68.google.com ([74.125.83.68]:39233 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750904AbeDMEJA (ORCPT ); Fri, 13 Apr 2018 00:09:00 -0400 Received: by mail-pg0-f68.google.com with SMTP id b9so1346047pgf.6; Thu, 12 Apr 2018 21:09:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=0Qm+ERQOtPeAFfe6TPEZ2HJhJjipScxLf8RZ7LlRmgg=; b=nPgrGRmfxCX+/+MrbzvhmPvYjQ9Nt9pcFy3GF1DTtxCVvTWnlnCwNziOXgv+C1zCEE FaCFbE/E3P0ulxblBYAMdPC1n+dm7pkxKgrCW6O4/r6lxIVXWr8bEMaQTHVjsK9JMzPl aTkjDGC4aPlwWScwps8RR2Rc9gCh7nhJMH+2H5bwXyYyKLimDLk+Pgjvu26NHYpuSjWF LuhcomPUtsVNAwtTjvBfwpaGjSaA/JZCYyTzNUdQSTOutQZTM6yFOjYQTJjSdQfTMPNl m1JR1aAmxzD6paz8ACfuYpYKjPjYGWUUNQHztFCrOjWMZDlCr/sjgNEFf/CJQU6SpaZp sSnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=0Qm+ERQOtPeAFfe6TPEZ2HJhJjipScxLf8RZ7LlRmgg=; b=Ayx0mTdb23q18eeuIEqpcOMt0nwbXHFyfEjDHRRwjPZ40mHNkDxVPRTkEQtFXSsfdx UMturgdF1V1UsfirWfQzczSF1uIpMpl4Zd7QC8++eHeph80Sulka04FMi5MwAu6cDbas 8R1vnwar7SE5tpjk89RrlV3JNhCUhHBUq56bpD05da9h1qftxngZWVKOo0WCcqvdRrQm ISpvnGoNa+XpuZaYwQcb/Vp8ssC0twk180p5vKJngkglcBFRBuiYdHrnZPnXuAEhVM8k 77FXSJ3W76/XAJEV5icATeRof7jThyI0Vcuwy18OEK/EMtbC7NTHnDbqnfpmi+iGWBVw MBDw== X-Gm-Message-State: ALQs6tD9X6GcaTdrJTyQmh3YQiNvggJ2Oj8rS0hUGq7gfzJuSLq4o7qD r0yUMYkdU5yh1F+EU7ahu7ApbXy1 X-Received: by 10.98.87.7 with SMTP id l7mr10025471pfb.148.1523592539973; Thu, 12 Apr 2018 21:08:59 -0700 (PDT) Received: from localhost.localdomain ([2601:644:8201:32e0:7256:81ff:febd:926d]) by smtp.gmail.com with ESMTPSA id d4sm9475820pgc.43.2018.04.12.21.08.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 Apr 2018 21:08:59 -0700 (PDT) Date: Thu, 12 Apr 2018 21:08:57 -0700 From: Eduardo Valentin To: Linus Torvalds , Zhang Rui , Bartlomiej Zolnierkiewicz Cc: LKML , Linux PM list , "Li, Philip" Subject: Re: [GIT PULL] Thermal management updates for v4.17-rc1 Message-ID: <20180413040855.GA29826@localhost.localdomain> References: <1523436077.16235.5.camel@intel.com> <1523509711.16235.25.camel@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello, On Thu, Apr 12, 2018 at 09:55:19AM -0700, Linus Torvalds wrote: > On Wed, Apr 11, 2018 at 10:08 PM, Zhang Rui wrote: > > > > could you please illustrate me what the kconfig & warning is? > > Just "make allmodconfig" and the warning is about a uninitialized variable. > > Line 304 in drivers/thermal/samsung/exynos_tmu.c if my shell history > is to be believed. > > Linus Yeah, this has also passed my local compilation error. Somehow my gcc4.9 is not catching it. Using an older gcc (gcc4.6) does catch it. Anyways, given that the conversion functions are written to cover for unexpected cal_type, the right way of fixing this is to rewrite the conversion functions to allow for returning error codes and adjusting the callers as expected. Rui, bzolnier, please consider the following fix: From 2aaf94f80c0021a21b4122c9f4197acff08ea398 Mon Sep 17 00:00:00 2001 From: Eduardo Valentin Date: Thu, 12 Apr 2018 21:00:48 -0700 Subject: [PATCH 1/1] thermal: exynos: fix compilation warning around conversion functions In order to fix the warns: drivers/thermal/samsung/exynos_tmu.c:931:37: warning: 'temp' may be used uninitialized in this function [-Wmaybe-uninitialized] drivers/thermal/samsung/exynos_tmu.c:304:9: warning: 'temp_code' may be used uninitialized in this function [-Wmaybe-uninitialized] the conversion functions should allow return error codes and the not mix the converted value with error code. This patch change the conversion functions to return error code or success and adjusts the callers accordingly. Signed-off-by: Eduardo Valentin --- drivers/thermal/samsung/exynos_tmu.c | 120 ++++++++++++++++++++++++----------- 1 file changed, 84 insertions(+), 36 deletions(-) diff --git a/drivers/thermal/samsung/exynos_tmu.c b/drivers/thermal/samsung/exynos_tmu.c index 2ec8548..b3f0704 100644 --- a/drivers/thermal/samsung/exynos_tmu.c +++ b/drivers/thermal/samsung/exynos_tmu.c @@ -282,52 +282,54 @@ static void exynos_report_trigger(struct exynos_tmu_data *p) * TMU treats temperature as a mapped temperature code. * The temperature is converted differently depending on the calibration type. */ -static int temp_to_code(struct exynos_tmu_data *data, u8 temp) +static int temp_to_code(struct exynos_tmu_data *data, u8 temp, int *temp_code) { - int temp_code; + int ret = 0; switch (data->cal_type) { case TYPE_TWO_POINT_TRIMMING: - temp_code = (temp - EXYNOS_FIRST_POINT_TRIM) * + *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; + *temp_code = temp + data->temp_error1 - EXYNOS_FIRST_POINT_TRIM; break; default: WARN_ON(1); + ret = -EINVAL; break; } - return temp_code; + return ret; } /* * Calculate a temperature value from a temperature code. * The unit of the temperature is degree Celsius. */ -static int code_to_temp(struct exynos_tmu_data *data, u16 temp_code) +static int code_to_temp(struct exynos_tmu_data *data, u16 temp_code, int *temp) { - int temp; + int ret = 0; switch (data->cal_type) { case TYPE_TWO_POINT_TRIMMING: - temp = (temp_code - data->temp_error1) * + *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; + *temp = temp_code - data->temp_error1 + EXYNOS_FIRST_POINT_TRIM; break; default: WARN_ON(1); + ret = -EINVAL; break; } - return temp; + return ret; } static void sanitize_temp_error(struct exynos_tmu_data *data, u32 trim_info) @@ -352,7 +354,7 @@ static u32 get_th_reg(struct exynos_tmu_data *data, u32 threshold, bool falling) struct thermal_zone_device *tz = data->tzd; const struct thermal_trip * const trips = of_thermal_get_trip_points(tz); - unsigned long temp; + int temp; int i; if (!trips) { @@ -362,6 +364,8 @@ static u32 get_th_reg(struct exynos_tmu_data *data, u32 threshold, bool falling) } for (i = 0; i < of_thermal_get_ntrips(tz); i++) { + int val, ret; + if (trips[i].type == THERMAL_TRIP_CRITICAL) continue; @@ -371,7 +375,14 @@ static u32 get_th_reg(struct exynos_tmu_data *data, u32 threshold, bool falling) else threshold &= ~(0xff << 8 * i); - threshold |= temp_to_code(data, temp) << 8 * i; + ret = temp_to_code(data, temp, &val); + if (ret) { + pr_err("%s: Convertion error from temp (%d) to code: %d!\n", + __func__, temp, ret); + return 0; + } + + threshold |= val << 8 * i; } return threshold; @@ -460,11 +471,10 @@ static int exynos4210_tmu_initialize(struct platform_device *pdev) /* Write temperature code for threshold */ reference = trips[0].temperature / MCELSIUS; - threshold_code = temp_to_code(data, reference); - if (threshold_code < 0) { - ret = threshold_code; + ret = temp_to_code(data, reference, &threshold_code); + if (ret < 0 || threshold_code < 0) goto out; - } + writeb(threshold_code, data->base + EXYNOS4210_TMU_REG_THRESHOLD_TEMP); for (i = 0; i < of_thermal_get_ntrips(tz); i++) { @@ -537,7 +547,10 @@ static int exynos4412_tmu_initialize(struct platform_device *pdev) goto out; } - threshold_code = temp_to_code(data, crit_temp / MCELSIUS); + ret = temp_to_code(data, crit_temp / MCELSIUS, &threshold_code); + if (ret) + goto out; + /* 1-4 level to be assigned in th0 reg */ rising_threshold &= ~(0xff << 8 * i); rising_threshold |= threshold_code << 8 * i; @@ -620,7 +633,9 @@ static int exynos5433_tmu_initialize(struct platform_device *pdev) /* Write temperature code for rising threshold */ tz->ops->get_trip_temp(tz, i, &temp); temp /= MCELSIUS; - threshold_code = temp_to_code(data, temp); + ret = temp_to_code(data, temp, &threshold_code); + if (ret) + goto out; rising_threshold = readl(data->base + rising_reg_offset); rising_threshold |= (threshold_code << j * 8); @@ -629,7 +644,9 @@ static int exynos5433_tmu_initialize(struct platform_device *pdev) /* Write temperature code for falling threshold */ tz->ops->get_trip_hyst(tz, i, &temp_hist); temp_hist = temp - (temp_hist / MCELSIUS); - threshold_code = temp_to_code(data, temp_hist); + ret = temp_to_code(data, temp_hist, &threshold_code); + if (ret) + goto out; falling_threshold = readl(data->base + falling_reg_offset); falling_threshold &= ~(0xff << j * 8); @@ -677,7 +694,12 @@ static int exynos5440_tmu_initialize(struct platform_device *pdev) /* if last threshold limit is also present */ if (!data->tzd->ops->get_crit_temp(data->tzd, &crit_temp)) { - threshold_code = temp_to_code(data, crit_temp / MCELSIUS); + int ret; + + ret = temp_to_code(data, crit_temp / MCELSIUS, &threshold_code); + if (ret) + return ret; + /* 5th level to be assigned in th2 reg */ rising_threshold = threshold_code << EXYNOS5440_TMU_TH_RISE4_SHIFT; @@ -749,7 +771,10 @@ static int exynos7_tmu_initialize(struct platform_device *pdev) temp_hist = temp - (temp_hist / MCELSIUS); /* Set 9-bit temperature code for rising threshold levels */ - threshold_code = temp_to_code(data, temp); + ret = temp_to_code(data, temp, &threshold_code); + if (ret) + goto out; + rising_threshold = readl(data->base + EXYNOS7_THD_TEMP_RISE7_6 + reg_off); rising_threshold &= ~(EXYNOS7_TMU_TEMP_MASK << (16 * bit_off)); @@ -758,7 +783,9 @@ static int exynos7_tmu_initialize(struct platform_device *pdev) data->base + EXYNOS7_THD_TEMP_RISE7_6 + reg_off); /* Set 9-bit temperature code for falling threshold levels */ - threshold_code = temp_to_code(data, temp_hist); + ret = temp_to_code(data, temp_hist, &threshold_code); + if (ret) + goto out; falling_threshold &= ~(EXYNOS7_TMU_TEMP_MASK << (16 * bit_off)); falling_threshold |= threshold_code << (16 * bit_off); writel(falling_threshold, @@ -925,11 +952,18 @@ static int exynos_get_temp(void *p, int *temp) clk_enable(data->clk); value = data->tmu_read(data); - if (value < 0) + if (value < 0) { ret = value; - else - *temp = code_to_temp(data, value) * MCELSIUS; + goto out; + } + + ret = code_to_temp(data, value, temp); + if (ret) + goto out; + *temp *= MCELSIUS; + +out: clk_disable(data->clk); mutex_unlock(&data->lock); @@ -937,9 +971,11 @@ static int exynos_get_temp(void *p, int *temp) } #ifdef CONFIG_THERMAL_EMULATION -static u32 get_emul_con_reg(struct exynos_tmu_data *data, unsigned int val, - int temp) +static int get_emul_con_reg(struct exynos_tmu_data *data, unsigned int val, + int temp, u32 *con_reg) { + int code, ret = 0; + if (temp) { temp /= MCELSIUS; @@ -950,27 +986,36 @@ static u32 get_emul_con_reg(struct exynos_tmu_data *data, unsigned int val, if (data->soc == SOC_ARCH_EXYNOS7) { val &= ~(EXYNOS7_EMUL_DATA_MASK << EXYNOS7_EMUL_DATA_SHIFT); - val |= (temp_to_code(data, temp) << - EXYNOS7_EMUL_DATA_SHIFT) | + ret = temp_to_code(data, temp, &code); + if (ret) + goto out; + + val |= (code << EXYNOS7_EMUL_DATA_SHIFT) | EXYNOS_EMUL_ENABLE; } else { val &= ~(EXYNOS_EMUL_DATA_MASK << EXYNOS_EMUL_DATA_SHIFT); - val |= (temp_to_code(data, temp) << - EXYNOS_EMUL_DATA_SHIFT) | + ret = temp_to_code(data, temp, &code); + if (ret) + goto out; + + val |= (code << EXYNOS_EMUL_DATA_SHIFT) | EXYNOS_EMUL_ENABLE; } } else { val &= ~EXYNOS_EMUL_ENABLE; } - return val; + *con_reg = val; +out: + return ret; } static void exynos4412_tmu_set_emulation(struct exynos_tmu_data *data, int temp) { unsigned int val; + int ret; u32 emul_con; if (data->soc == SOC_ARCH_EXYNOS5260) @@ -983,18 +1028,21 @@ static void exynos4412_tmu_set_emulation(struct exynos_tmu_data *data, emul_con = EXYNOS_EMUL_CON; val = readl(data->base + emul_con); - val = get_emul_con_reg(data, val, temp); - writel(val, data->base + emul_con); + ret = get_emul_con_reg(data, val, temp, &val); + if (!ret) + writel(val, data->base + emul_con); } static void exynos5440_tmu_set_emulation(struct exynos_tmu_data *data, int temp) { unsigned int val; + int ret; val = readl(data->base + EXYNOS5440_TMU_S0_7_DEBUG); - val = get_emul_con_reg(data, val, temp); - writel(val, data->base + EXYNOS5440_TMU_S0_7_DEBUG); + ret = get_emul_con_reg(data, val, temp, &val); + if (!ret) + writel(val, data->base + EXYNOS5440_TMU_S0_7_DEBUG); } static int exynos_tmu_set_emulation(void *drv_data, int temp) -- 2.1.4