Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp655284imm; Thu, 26 Jul 2018 09:40:59 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfxv+oTA+29weqfcjKqbTrgMdplhWB4y6v5QqapheT0nYPvH/8B1FA53UH6DpiSrxtQCxJ8 X-Received: by 2002:a63:1c13:: with SMTP id c19-v6mr2683849pgc.332.1532623259656; Thu, 26 Jul 2018 09:40:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532623259; cv=none; d=google.com; s=arc-20160816; b=pcRtLQa/Z4SCkMCs9NeUyW/4cOrQTJeqs5dEqAAzuATv2rMc0n3tUgEUidrXue7yiL CqstRVCwqKx+QNPLXzlBl19uo8Yx6IxD30hRm1SZdSujp9GBl2+PcfXNFN+XvmFV8Gdk mL7qijYNCRw9IwOnyfGNd5hVd7QKgdatFUpWIPrJipmwow59m3GxPmuf98fhWi7ujTyt Xsdf6Wj3pr+6QVCiWJF+o6YS2QekQ4A6W3os1Et6P7e5TJ7Q+vrOGnF32S3vymB1XG6o 5iHF/IvmP1cJBGWRrCBvUG3zz3jEEzKeDuiJ3Os82Undm0pllQtoodzkx3hevkY0AGd7 mFvQ== 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=c9iF+U7dQUahRCWtGKav/2xWhC5XpoY6NxVIGXCntFE=; b=KOeh99wMyvULXoDF5yxfFCbCz1VFWTZQyWNIQb1tRy2VrF4G6Or0wxY7ZbvfGZxMlN C0px3Q0yPf6T4iHXqtkzEjNYiIub9Li/yt0bQx1a2g6LnbiG81B1dzaPZlho8ohxmOvV cAQgDF0n1h61h4+smx9a64FUMh+ckhe2RTWB92fTzdHgyLv+QFhZ+X7GaziFTMxFbC8m ThKGM+FyXFbnUR1Qsz3GAqS6h7/1IQkGwknwPxDyP24BHLKHxHKRXCDb5jWVzTndbBDk GcRnRNuWt3ntOksKIGj1eAifgewBnWqcfGpABUydeoT3wVNxf/ua9F4/tnR+hFhj3M3i /cdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="kgHq/Jl0"; 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 n11-v6si1490528plg.344.2018.07.26.09.40.44; Thu, 26 Jul 2018 09:40:59 -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="kgHq/Jl0"; 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 S1732996AbeGZR4C (ORCPT + 99 others); Thu, 26 Jul 2018 13:56:02 -0400 Received: from mail-pl0-f67.google.com ([209.85.160.67]:33853 "EHLO mail-pl0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731856AbeGZR4B (ORCPT ); Thu, 26 Jul 2018 13:56:01 -0400 Received: by mail-pl0-f67.google.com with SMTP id f6-v6so1072428plo.1 for ; Thu, 26 Jul 2018 09:38:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=c9iF+U7dQUahRCWtGKav/2xWhC5XpoY6NxVIGXCntFE=; b=kgHq/Jl0wFun2YSzV9CPWZxasHGJgkYqC+2UvmKAV4uABgRo3n2FQaUNsN5hwVgi76 VSe4fK2gHtKeQ/QtYlzN/4hFX+6PoIeBMuM9r/t/yi6iWnGHIhQerZZNDs1DhqP5avVx 7vnaAgOFBEIr5uynKVpM6AaE/j9Fc/ikcbGKk= 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=c9iF+U7dQUahRCWtGKav/2xWhC5XpoY6NxVIGXCntFE=; b=fy60IdwPANef9smCZyS4EC/U2Da8lV7yD7cHovecSDnDv7IOBbOCEQJ7pYfQXZb9zv 93NySJYo/n9AZNOZJw+1Q8rhLIrYFLuUure7ndDkGUyYUQTqJfyoCAoswGZrAubmDTMJ OGPDeaHC7wou3bb3liqIQ8jwxv5K2JGY31jTFKaLTHHWejG11LXcZ1Voe/IlzHITr2yX q+wXQ+8nOhfz2bw9gGYQSa5DM4EQPrNHXe+gPsMQCnvrqpor68QKD/IaJgwfFIWBSLv5 2o1gBAs/p7zKHonFFTYvtT2TOMSKr9+hWx00puRiHkSnGCnZcN8cwT7ACMH8nHZ+cU4M C0Ow== X-Gm-Message-State: AOUpUlEFFyhKqVgyb1CmSmry58GvkyLo6TzITiz6TcpZjdhAzhUW5yig CWPOTLOwJMSwnNSb4JoYgxAw1Q== X-Received: by 2002:a17:902:b401:: with SMTP id x1-v6mr2636998plr.236.1532623104617; Thu, 26 Jul 2018 09:38:24 -0700 (PDT) Received: from tuxbook-pro (104-188-17-28.lightspeed.sndgca.sbcglobal.net. [104.188.17.28]) by smtp.gmail.com with ESMTPSA id k123-v6sm3484282pga.21.2018.07.26.09.38.23 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 26 Jul 2018 09:38:23 -0700 (PDT) Date: Thu, 26 Jul 2018 09:41:32 -0700 From: Bjorn Andersson To: Amit Kucheria Cc: linux-kernel@vger.kernel.org, rnayak@codeaurora.org, linux-arm-msm@vger.kernel.org, edubezval@gmail.com, smohanad@codeaurora.org, andy.gross@linaro.org, dianders@chromium.org, mka@chromium.org, Zhang Rui , linux-pm@vger.kernel.org Subject: Re: [PATCH v2 3/3] thermal: tsens: Fix negative temperature reporting Message-ID: <20180726164132.GC5450@tuxbook-pro> References: <52516c287c9455676e7cbde4a4fa94282d73367f.1532600791.git.amit.kucheria@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <52516c287c9455676e7cbde4a4fa94282d73367f.1532600791.git.amit.kucheria@linaro.org> User-Agent: Mutt/1.10.0 (2018-05-17) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu 26 Jul 03:33 PDT 2018, Amit Kucheria wrote: > The current code will always return 0xffffffff in case of negative > temperatures due to a bug in how the binary sign extension is being done. > > Use sign_extend32() instead. > > Signed-off-by: Amit Kucheria > Reviewed-by: Matthias Kaehlcke Reviewed-by: Bjorn Andersson Regards, Bjorn > --- > drivers/thermal/qcom/tsens-v2.c | 13 +++++-------- > 1 file changed, 5 insertions(+), 8 deletions(-) > > diff --git a/drivers/thermal/qcom/tsens-v2.c b/drivers/thermal/qcom/tsens-v2.c > index 908e3dcb2d5c..44da02f594ac 100644 > --- a/drivers/thermal/qcom/tsens-v2.c > +++ b/drivers/thermal/qcom/tsens-v2.c > @@ -5,19 +5,20 @@ > */ > > #include > +#include > #include "tsens.h" > > #define STATUS_OFFSET 0xa0 > #define LAST_TEMP_MASK 0xfff > #define STATUS_VALID_BIT BIT(21) > -#define CODE_SIGN_BIT BIT(11) > > static int get_temp_tsens_v2(struct tsens_device *tmdev, int id, int *temp) > { > struct tsens_sensor *s = &tmdev->sensor[id]; > u32 code; > unsigned int status_reg; > - int last_temp = 0, last_temp2 = 0, last_temp3 = 0, ret; > + u32 last_temp = 0, last_temp2 = 0, last_temp3 = 0; > + int ret; > > status_reg = tmdev->tm_offset + STATUS_OFFSET + s->hw_id * 4; > ret = regmap_read(tmdev->map, status_reg, &code); > @@ -54,12 +55,8 @@ static int get_temp_tsens_v2(struct tsens_device *tmdev, int id, int *temp) > else if (last_temp2 == last_temp3) > last_temp = last_temp3; > done: > - /* Code sign bit is the sign extension for a negative value */ > - if (last_temp & CODE_SIGN_BIT) > - last_temp |= ~CODE_SIGN_BIT; > - > - /* Temperatures are in deciCelicius */ > - *temp = last_temp * 100; > + /* Convert temperature from deciCelsius to milliCelsius */ > + *temp = sign_extend32(last_temp, fls(LAST_TEMP_MASK) - 1) * 100; > > return 0; > } > -- > 2.17.GIT >