Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1133573ybt; Tue, 7 Jul 2020 08:30:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzCRHsoRd6ztCthld+RqGCtEzCmGJAIx37f7GQoj/5NyTOLm+QfhguOypJyOGoQ6kX5+8RR X-Received: by 2002:a50:da83:: with SMTP id q3mr64174665edj.325.1594135806575; Tue, 07 Jul 2020 08:30:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594135806; cv=none; d=google.com; s=arc-20160816; b=GTKfDgZGxKlUo0FBN+wIhBacy3K8WYDGEd5ztuOXdBAe+zuqsz0om0FTOwOQK43fhv Z1SOT9aDbdXig9tvtUMFgFl6BYgJ6hOPHISV28u/tW2DP3+ItDxn9VAUhrNlZHPpsBwF pp7AFqhlwwbJDRiMBsEe+srVI8UoJy1Nqy41VMX9+K0AU8LqNwfSX7lTyj5zJ7xl5OKg m/S7c1TPCP1GKXPR92vcfu5Q0ly6yJMnSqtpi2noe+5kdF17ZPjAyKp+Rt8BXE4PDyQl rf7LN06rz+Pc70AgCLza0rv5fPjXShgz2X+HnDIODa0Y3/LzFDsGpXxnMc61xiI+EvNx s7jQ== 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=yl31mK9T0Kual3jHc0wSbOk5qxljW1Rt1ciygN07nRA=; b=rhU3VqcK+Dr1b2BigoHMNEAlIhIzAqDEo7LEAM4eEuQJwWNyFWvkh2WP1Rd8mEAQQk gRdNzTq4mIy2Z1C67uOpXox9gJ/SEj7csraTyRCxBSZuQccvR0fd++YjbuJt8hGJnB0h Skt8lyG835dEm3imUVa9nwmQ9CkGvn8icXk7Bb2512brH7pL1yHB5pQEQbjYKjL04aRl l4isGymmd9kk8fW2HzBIWlpHmzhyLVlzTeWSOAMUCAZ+vtSf0tgZn7IOeoidh6atjsm9 eT4NZ1q2xfvIkTbMQ6CChvNhTu/COeeMpHdgRwgKd6hvLcz/5UIJHkjL6sgUK0eB1Tq1 2ZpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=CYgbedha; 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 i6si16231662edv.52.2020.07.07.08.29.43; Tue, 07 Jul 2020 08:30:06 -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=CYgbedha; 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 S1730020AbgGGP3T (ORCPT + 99 others); Tue, 7 Jul 2020 11:29:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:38942 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730165AbgGGPZI (ORCPT ); Tue, 7 Jul 2020 11:25:08 -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 D783F2083B; Tue, 7 Jul 2020 15:25:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1594135507; bh=SYFssJ2fYNETHUelv4SR9+zQb3uOZ92wRAwxCOFXqBE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CYgbedhahGM8m+qtSoqoky909T67A4l+lMiRJm4a+P5Y4HjoRB+ngINX410VengL2 XRBgaPntd0Mjnzd/CbhWyOCGusiBfYvKcv1Uy3Nd4hR8rf3qIlQ9y1QPuuyfrhqJWx TVNITh+iSVHYIdGj5DkWwsFwkwVB5LUzqpA1ZNXc= 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.7 069/112] thermal/drivers/rcar_gen3: Fix undefined temperature if negative Date: Tue, 7 Jul 2020 17:17:14 +0200 Message-Id: <20200707145804.284375172@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200707145800.925304888@linuxfoundation.org> References: <20200707145800.925304888@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 58fe7c1ef00b1..c48c5e9b8f203 100644 --- a/drivers/thermal/rcar_gen3_thermal.c +++ b/drivers/thermal/rcar_gen3_thermal.c @@ -167,7 +167,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