Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1136639ybt; Tue, 7 Jul 2020 08:33:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwXbWgOYj8Vti5RST7FJzorUVgSlbs3ShCW4Vthx+cxPfFGYhGbMOtdvTELwvqlz97XjohG X-Received: by 2002:aa7:d693:: with SMTP id d19mr21221794edr.317.1594136013310; Tue, 07 Jul 2020 08:33:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594136013; cv=none; d=google.com; s=arc-20160816; b=USSdXgHkRltexmNujggRELt/7WTBArgJ+s9OvpWypL2wHBZjn6FKECFo1LhKwNi898 6V1MHO6urJUaYLdKPq3J/KptPUz07Annc7v91ANgHbV/FwfMvBkRYaLrFcSTHACrfEfV 2qXYq/Sx2WgXAl42YHKg/zyMoHtAYjrkaYLOs7hPNMa1tjWcsoo7gvtk0JqTlJ+ARv2o EGQ5/GJzIms6BB5fnsn2RdaokreXgOiy0enaK9zuw467Q1q7c3MBbZh2/R0FyKDW0fjj hULegGshW2lkce/HsiBbrLfLhoV3odZ573JPu3M8VK2Lo5OXvhDTDHSClRJRQy6C3S+J ziEw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=zGVs1hJ3AAOuK7SdrAGsEudekSgT2xsqNh/BwrnOksc=; b=D0cH7oQk55eTGP3WzEAkKCv+mRLTxZYtlEpW0qHFHjCHId5BJycEDaDn84QB/kmjFP tUUjujXq4HYQAuJwIFqUsO4uJgx4OGzCULbs3YhDt2QB3QUQ/Ym0p90Hiy5ZS7IToSBN /mV/p/NYR8qmisDdSCaq4KqvOTqbgbW/NbOd/YnnARD6SeeUIf/NyJjHuo2IAIipp/R8 b04suFH9g0kUz/Nk5XfnbpnUKKOs+1He4MDsxAVqYbL1hAsyhc07NIqnKe1TOsd/dgL/ TWKgdtdq6UROgnJeUtQDATpIa2a40WqnDX2IuZWfpHVy1KObG6T8i+M2KOfBYJ3nEiis gmQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=TTjyLkOS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id qh22si15760036ejb.553.2020.07.07.08.33.09; Tue, 07 Jul 2020 08:33:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=TTjyLkOS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729672AbgGGPVM (ORCPT + 99 others); Tue, 7 Jul 2020 11:21:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:33320 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729658AbgGGPVK (ORCPT ); Tue, 7 Jul 2020 11:21:10 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 58C8A206E2; Tue, 7 Jul 2020 15:21:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1594135269; bh=Yb/kN+Ykzu3y1QxV3gSKWsc82uPftmNrmA3t8MPJMyU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TTjyLkOSdkpwkwYk5BDzu4L1QzK0DeDjczK9ClNCjRuG8T8PCIEhtUxxD3FhFUHzq gkqEGmo65kXgXgKjIAsxO1cEPfFawVDI7PBX6LKmVuceOP4kRRnDIiBQXMlqC8ZGGa 5RJGaOLbrxaz7/0mwvzc1lN91dsdSJyzPmSiTPfk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Van Do , Dien Pham , Yoshihiro Shimoda , Niklas Soderlund , Amit Kucheria , Daniel Lezcano , Sasha Levin Subject: [PATCH 5.4 33/65] thermal/drivers/rcar_gen3: Fix undefined temperature if negative Date: Tue, 7 Jul 2020 17:17:12 +0200 Message-Id: <20200707145754.075806633@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200707145752.417212219@linuxfoundation.org> References: <20200707145752.417212219@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Dien Pham [ Upstream commit 5f8f06425a0dcdad7bedbb77e67f5c65ab4dacfc ] As description for DIV_ROUND_CLOSEST in file include/linux/kernel.h. "Result is undefined for negative divisors if the dividend variable type is unsigned and for negative dividends if the divisor variable type is unsigned." In current code, the FIXPT_DIV uses DIV_ROUND_CLOSEST but has not checked sign of divisor before using. It makes undefined temperature value in case the value is negative. This patch fixes to satisfy DIV_ROUND_CLOSEST description and fix bug too. Note that the variable name "reg" is not good because it should be the same type as rcar_gen3_thermal_read(). However, it's better to rename the "reg" in a further patch as cleanup. Signed-off-by: Van Do Signed-off-by: Dien Pham [shimoda: minor fixes, add Fixes tag] Fixes: 564e73d283af ("thermal: rcar_gen3_thermal: Add R-Car Gen3 thermal driver") Signed-off-by: Yoshihiro Shimoda Reviewed-by: Niklas Soderlund Tested-by: Niklas Soderlund Reviewed-by: Amit Kucheria Signed-off-by: Daniel Lezcano Link: https://lore.kernel.org/r/1593085099-2057-1-git-send-email-yoshihiro.shimoda.uh@renesas.com Signed-off-by: Sasha Levin --- drivers/thermal/rcar_gen3_thermal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/thermal/rcar_gen3_thermal.c b/drivers/thermal/rcar_gen3_thermal.c index 755d2b5bd2c2b..1ab2ffff4e7c7 100644 --- a/drivers/thermal/rcar_gen3_thermal.c +++ b/drivers/thermal/rcar_gen3_thermal.c @@ -169,7 +169,7 @@ static int rcar_gen3_thermal_get_temp(void *devdata, int *temp) { struct rcar_gen3_thermal_tsc *tsc = devdata; int mcelsius, val; - u32 reg; + int reg; /* Read register and convert to mili Celsius */ reg = rcar_gen3_thermal_read(tsc, REG_GEN3_TEMP) & CTEMP_MASK; -- 2.25.1