Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1356390imm; Wed, 25 Jul 2018 16:50:53 -0700 (PDT) X-Google-Smtp-Source: AAOMgpc5tZfVNKfN5cS3m2Fu3HIyVeYfpfEcgqLpz9j1hfGkBCgtEOT0CvPtrP5evwGGYuPb2RLi X-Received: by 2002:a63:3190:: with SMTP id x138-v6mr22221561pgx.60.1532562653682; Wed, 25 Jul 2018 16:50:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532562653; cv=none; d=google.com; s=arc-20160816; b=ZMKOYuPa2Pc2xaBNBwqXvaqZcyj4QlEt0vEYBxb8P5a58Z/YYkwMvHICWpBZqIU8dI NudsMlhRDTNxHpKhNA2W/EurPxzNfHEQCt4Px3rA9ONwd8sVno6BHLbbk3uYj7rQw1Vd KUadtgJia/QDzSt7B1hs4AL2tnQrm5ojcybKKJiw1Mn0ddUKhHNm8H+n8jZqdbBIrUS4 l4GUoy5perP8H70y91Eb8ooPBbz7bBDSXBF+XSNsWwq8dpF4v+Uoyqu2dDIWurRg/3TX tXBIBsTp3H6lZEsBj7QL4o1HuQOjlozy7Gr82TTLHKZwr8zBCzdrd/oCVBH674XfHm5r 6/kQ== 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=TI9y3QJnwJ8xsSkl1/i3nEl03g27qlylrQLC6+UXpD4=; b=NvjCQCMRNFP2WbjEXtJV17CsKG7UJsH5Dh20tsjzt6NA0OOrf/7/4gScJF92E7Z+91 2AiuAvY6mzQ3+6b+U/GWOnhToAQlfkGUCI4VzRm4Id4C8vE8Ht4k5PApqpu6ShaC5vw8 bHhA8ximePylc728GRqugOyuisR9IFxUOkPAYpETg3OHU32cVFzS4PV0f2dS310aWFnn I9r2Pyde1Ske3hK9Kwnu+TcbNkpxdxA5fO41uC+bof5Z8x1eEgRKmi+Kvici3iKEUl5A ZZHru6UHvtdDanmleQvoXqwDgcQyDgiSGPpbGTcos1nHgZk3TPvj6TPqYtJ6i6KJFLUn B8SA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Int6DamW; 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=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y186-v6si15278138pgb.395.2018.07.25.16.50.38; Wed, 25 Jul 2018 16:50:53 -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=@chromium.org header.s=google header.b=Int6DamW; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731769AbeGZBDk (ORCPT + 99 others); Wed, 25 Jul 2018 21:03:40 -0400 Received: from mail-pl0-f65.google.com ([209.85.160.65]:32998 "EHLO mail-pl0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731522AbeGZBDj (ORCPT ); Wed, 25 Jul 2018 21:03:39 -0400 Received: by mail-pl0-f65.google.com with SMTP id 6-v6so3956286plb.0 for ; Wed, 25 Jul 2018 16:49:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=TI9y3QJnwJ8xsSkl1/i3nEl03g27qlylrQLC6+UXpD4=; b=Int6DamWZsJymYpIhZV8juX7pwxy+DB9CjVhkzw2q8lBI0ElkxnkTlLDstBgvf62iH mQZS1OENJSJpzBjYhhDUTPsgJfhJjHIo9/8scHI7bN4kaEB5xHjaCYkBfDuxFfEd8/gg dbIc/EN3InjW2aUCsiDu1eGFCXqFC8NEDwqgE= 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=TI9y3QJnwJ8xsSkl1/i3nEl03g27qlylrQLC6+UXpD4=; b=mCoSSDWZi/dWGYXesys6zfYMgVpk2qi3ZcdqydQuhVWArq+VeT0JKAQrdxxsVBvfFC sFGvv6JPq8AGxnB6WzBZ1zqMK/HXDq4ibKdgubtinEhtdXgZCaeyyBbQQDpTQBKfA9gf f0fYM1dnWRYlmxfhfSi2VvFP1ealAzjjK8lV72Cd4mXOftNJDyOVazngdm5ssGd5Wpxq TbaH6o7YeK+pE1DX7PQMYwDiBxtuNDhMZ9tqdecVYPE+ifGuE5zt4aMFMH8BzkXSW0mB t8u0jV3IvPiL+qp6FjkH/KZBl/F8ydcaVUNWU5gsO28jvDflcsxjcXoIpm9bVE+FkKTV Q0Dw== X-Gm-Message-State: AOUpUlEmTSvxmh055j9OwO262tqZrfv+0CeOq/hB7ZfcJuvwwzFkFpkq rZLhXqnbueZRL4A+ZDOWzON+G1pLg/I= X-Received: by 2002:a17:902:209:: with SMTP id 9-v6mr23068102plc.270.1532562577136; Wed, 25 Jul 2018 16:49:37 -0700 (PDT) Received: from localhost ([2620:0:1000:1501:8e2d:4727:1211:622]) by smtp.gmail.com with ESMTPSA id s27-v6sm25734461pfk.133.2018.07.25.16.49.36 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 25 Jul 2018 16:49:36 -0700 (PDT) Date: Wed, 25 Jul 2018 16:49:36 -0700 From: Matthias Kaehlcke To: Amit Kucheria Cc: linux-kernel@vger.kernel.org, rnayak@codeaurora.org, linux-arm-msm@vger.kernel.org, bjorn.andersson@linaro.org, edubezval@gmail.com, smohanad@codeaurora.org, andy.gross@linaro.org, dianders@chromium.org, Zhang Rui , linux-pm@vger.kernel.org Subject: Re: [PATCH v1 3/3] thermal: tsens: Fix negative temperature reporting Message-ID: <20180725234936.GT129942@google.com> References: <42d6f2a6f9babd6351bd2fcde4000d5ca9c351ce.1531898088.git.amit.kucheria@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <42d6f2a6f9babd6351bd2fcde4000d5ca9c351ce.1531898088.git.amit.kucheria@linaro.org> User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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/ > + *temp = sign_extend32(last_temp, fls(LAST_TEMP_MASK) - 1) * 100; > > return 0; > } Reviewed-by: Matthias Kaehlcke