Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp270177imm; Thu, 26 Jul 2018 03:19:33 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeqv4QU26cqocHfCQhMC9nrqjln5vZ1R/VzTqTYWt9cdqCRM7pN2PJje2bHnEII8qLMEduV X-Received: by 2002:a62:4a41:: with SMTP id x62-v6mr1486148pfa.45.1532600373567; Thu, 26 Jul 2018 03:19:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532600373; cv=none; d=google.com; s=arc-20160816; b=up46ZiBhjrswu8hHwog35vPzQuMmx/SZW1FEzcwPmhuvUCUmOhwfscXk0QO5eLX4jO 9u0D8wy5IVVdKGkf4wy12ZW80dUk64RkJoYnH/A0EDuCfM2vLJ8eE5vntOGKi2aX+SUu kmi9V6b+/AX9Ego5mktffwGHEM5jtojqETji1/k0yZ6U5BxayYMD/cSx+T0DxDFwrwDO r2S7aoBWkdFJMBK2B2jYQCnYwFl9GF5cLW5GFdnF/7xe/hqBN+qSVZeu3+M54uixqtes 34NonteSexXKGrgno+GhVNXq7jkkmlfNRBf8/GX4JXdKj6ZsUl/UX8AgvJxFjPDZUwgr br4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature:dkim-signature :arc-authentication-results; bh=4E1p3TM9bdttR79YBBfgcm5sWZnATxNp3jMrdJpqdzI=; b=y4mX6aKhs+ClhqeegQF6p3SkA1SwqE7z6YNRnudya+KvVbMBWWjdb273q6f0SPnnZ+ 8QCZ547pZiDVy5GYane7DSVTVB2hkBom137snJvb7YwOtPLcvYFtfUdtvhzLYrjNBWaC RpdvbSk6e8c3SlbXWQ0YbNncWXHDBmTERiziSGPV9G3sTYR5OwcSHLw1FXqdlNHdthEj Zowwc4LITvyTyOy9kAILM6G43cNu8UuYNQZGqMO/7EPcW6so0rml7+IH4kOicwHQJEpY weVFD3yX853BKIh8BYmD32oUftYHZDPp5qI42VH2VVDqI3MCGpWAQ/OC/C1OoZ68N0TL x0ow== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@verdurent-com.20150623.gappssmtp.com header.s=20150623 header.b=Si2K8LpL; dkim=fail header.i=@linaro.org header.s=google header.b=GDXccAmE; 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=fail (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 n7-v6si876225plp.363.2018.07.26.03.19.18; Thu, 26 Jul 2018 03:19:33 -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=fail header.i=@verdurent-com.20150623.gappssmtp.com header.s=20150623 header.b=Si2K8LpL; dkim=fail header.i=@linaro.org header.s=google header.b=GDXccAmE; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729347AbeGZLeF (ORCPT + 99 others); Thu, 26 Jul 2018 07:34:05 -0400 Received: from mail-oi0-f67.google.com ([209.85.218.67]:42143 "EHLO mail-oi0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729157AbeGZLeF (ORCPT ); Thu, 26 Jul 2018 07:34:05 -0400 Received: by mail-oi0-f67.google.com with SMTP id n84-v6so1985084oib.9 for ; Thu, 26 Jul 2018 03:17:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=verdurent-com.20150623.gappssmtp.com; s=20150623; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=4E1p3TM9bdttR79YBBfgcm5sWZnATxNp3jMrdJpqdzI=; b=Si2K8LpLHyMQ5mFlyae70zqsWwdsVNOhn0Mh58MkWrLz5jXe2Y7RkcH+Ymbvq0zI6x Yfc1akmS2ei9VPe8/Djgc1P8YWv+F2AHqhkhJx1PhoI1KyQCBXyVxU69H24feM0vmKez uFGaK4nju5ADdvZ5q9LfPuc/QeZpNQdMK5ZM7y9awr+W3kMBhqfQpE1nAh7cMxO7KrEt 5b7TChUTmpWmmtEWrM44lLF/+8gkVy45dvYU2RsT+2SC5cU3AkTD15f2cVfd8v9G5G/Z nD2bh0F1y4EiJ+c0/Z+p/O7yWqzmIuarDIJXdVLMVmCCCserF0moZQQG47VujpHptJ4y XjtQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=4E1p3TM9bdttR79YBBfgcm5sWZnATxNp3jMrdJpqdzI=; b=GDXccAmEhLiITXl1b/VMuv3T2sxqYdxIDqcTMuLWjRaR9ud8aEAlMeVmbNL1Y74HyI tl32rzU/xhRAS9vhJLeElOX/H+XZaW3m3N2xvaCcBtCjkC9klUMgKhpPKU9gWJSg54MJ Rl+7wd1gE8ZHN5N/Ch6kVokcM0aTUcuOGw5Do= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=4E1p3TM9bdttR79YBBfgcm5sWZnATxNp3jMrdJpqdzI=; b=ef6esj+RSFLihxEGQZtjv2z53wmELoFlb27XudqbLi5QqwLSNyCB+tpQLSvL5/8yQ9 z4z5STWBM0mT+hzeesRCId1vtFvBeOkyirNQXFP5wf8Fi7TL32RrR1BxkN673D0A7h0X re8D/C7l1QwAM0BvrFhNfwi0nLLDzzYG656g7cJGhB/5GNklmq0On5ii98/eBLItkPMJ zQqkXFUh+xsWKzijwBCd6stPV0a3c3CQ8+3lxSzhCUtm7H+xiKqzpC3Rhjqb8QPSPrUq oheBqlocsEVQ9+OQDx11Bt5++0a5HNnVGQ7HypqwxAvzXs16s8QuSQg+7bgNa4YKz5fY nL8w== X-Gm-Message-State: AOUpUlGaDlpV7nNa6GA0BFP7bJuQvNR1zuqTdG7NfPX70FLTTZKLHHG+ pf7UFfPfizap5yA0kJUKXvJznS4vLKPLC+L2FAzZJA== X-Received: by 2002:aca:d605:: with SMTP id n5-v6mr1158083oig.287.1532600274853; Thu, 26 Jul 2018 03:17:54 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a4a:3745:0:0:0:0:0 with HTTP; Thu, 26 Jul 2018 03:17:54 -0700 (PDT) In-Reply-To: <20180725234936.GT129942@google.com> References: <42d6f2a6f9babd6351bd2fcde4000d5ca9c351ce.1531898088.git.amit.kucheria@linaro.org> <20180725234936.GT129942@google.com> From: Amit Kucheria Date: Thu, 26 Jul 2018 15:47:54 +0530 X-Google-Sender-Auth: kiBhv976Ycssnq42WZluUOLWtCI Message-ID: Subject: Re: [PATCH v1 3/3] thermal: tsens: Fix negative temperature reporting To: Matthias Kaehlcke Cc: LKML , Rajendra Nayak , linux-arm-msm , Bjorn Andersson , Eduardo Valentin , smohanad@codeaurora.org, Andy Gross , Douglas Anderson , Zhang Rui , Linux PM list Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jul 26, 2018 at 5:19 AM, Matthias Kaehlcke wrote: > On Wed, Jul 18, 2018 at 12:55:03PM +0530, 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 >> --- >> 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 908e3dc..46abc21 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 temperatures to milliCelicius */ > > nits: > > s/temperatures/temperature/ > s/milliCelicius/milliCelsius/ Embarrassing to have two typos in a single sentence. :-) >> + *temp = sign_extend32(last_temp, fls(LAST_TEMP_MASK) - 1) * 100; >> >> return 0; >> } > > Reviewed-by: Matthias Kaehlcke Thanks for the review.