Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp11197ybt; Tue, 23 Jun 2020 13:57:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxDWf+k+xR1j1vVGN8ukAD2Y81czmGafGnkYFLuxAjBOXqioD776pF2nYjJBazAUGibTLuq X-Received: by 2002:a17:906:2304:: with SMTP id l4mr21372886eja.104.1592945868163; Tue, 23 Jun 2020 13:57:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592945868; cv=none; d=google.com; s=arc-20160816; b=WdY40ND1OewVkkds7VNfoIgrXw5DSPzuRXgx/ir/8D74cFGwbCraXc7H8kGp04LAeU Oa4Sd+cKQ7lDopKadJQh+Dm6vRXZn/pdhIOdEhe72g/Ycx+oWi+56OPUb87wAtOzv3VY DUrNDte7XaI1l7WVmoWmZvawUXg4Ib7JwCKwM+SthUQ2tLmuJ7oJk/HWEhaVAyNku03w fevHx8uiFx5wJIUBTrN7749om0UuYk/AorbvXkONv6twdhnhD6/FNQsQMJ3j0I1F0Ilu iRYPcSExvAUn0hzrshlq2FJGtEel0UXG2AxJvSVvneUq4uWPZCrSvI9XDq4Ck/dNNDbE hspw== 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=9tj4RxWs/Jrn2DgLlQvrqZht0MsvytmHx8RiXJXHuDc=; b=H+9w+aaf+P3+vs6tJQSXCDNgFmieghUpJUsNIWp8aZxYAymgwzdHzSTwDYep4cbdB6 R3vq58kBlkKhOQc6MLgUcC3L0SQP8FEdHUUlzJwdB18miqVcEkSlkvb8XfSjCMcvDEvt KYW491/Y9Ck8E5r3JU0fex1wq1tPsUoLjgWtsszmcOlSLK8GJXnfojOP2VhjHnpKSQK0 /ivHKwOp1TEvUl3mh271S2TUDs7KsuYM7ifMDdtwmXh/a8KmYmtEc4Oby0kI8oH1lwce LeLrlLofPeFgotmB9Piiu86+ak4GgQVode+o2JlMrSsrsRU4FT/be7oD3ss/Plho/JoU BLOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=q2YG61S7; 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 b5si11421091ejk.381.2020.06.23.13.57.24; Tue, 23 Jun 2020 13:57:48 -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=q2YG61S7; 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 S2403946AbgFWUoB (ORCPT + 99 others); Tue, 23 Jun 2020 16:44:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:40968 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2403944AbgFWUn4 (ORCPT ); Tue, 23 Jun 2020 16:43:56 -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 74CD32053B; Tue, 23 Jun 2020 20:43:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592945036; bh=uzp3mKvVRrBvfecNk35oT5htFvfV3OuITUf9HZ4FDOI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=q2YG61S7TADHx+RBP2o0nJnB1G0zbckbGcMGIiORhrsPiWFzAGC7ovosZ3E2PuI+1 QcNSU7dlCFfEpsrZOx4s1rIJQDG51eHVC160axw5fSeAZPgqUs46xTNkKUI6Y7TNp7 h7VHux8KvMXLg8tg4CRUrUmGUEQGU4JNEVFZPwsA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andreas Klinger , Jonathan Cameron , Sasha Levin Subject: [PATCH 4.14 015/136] iio: bmp280: fix compensation of humidity Date: Tue, 23 Jun 2020 21:57:51 +0200 Message-Id: <20200623195304.383283498@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200623195303.601828702@linuxfoundation.org> References: <20200623195303.601828702@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: Andreas Klinger [ Upstream commit dee2dabc0e4115b80945fe2c91603e634f4b4686 ] Limit the output of humidity compensation to the range between 0 and 100 percent. Depending on the calibration parameters of the individual sensor it happens, that a humidity above 100 percent or below 0 percent is calculated, which don't make sense in terms of relative humidity. Add a clamp to the compensation formula as described in the datasheet of the sensor in chapter 4.2.3. Although this clamp is documented, it was never in the driver of the kernel. It depends on the circumstances (calibration parameters, temperature, humidity) if one can see a value above 100 percent without the clamp. The writer of this patch was working with this type of sensor without noting this error. So it seems to be a rare event when this bug occures. Signed-off-by: Andreas Klinger Signed-off-by: Jonathan Cameron Signed-off-by: Sasha Levin --- drivers/iio/pressure/bmp280-core.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c index 3204dff34e0ad..ae415b4e381af 100644 --- a/drivers/iio/pressure/bmp280-core.c +++ b/drivers/iio/pressure/bmp280-core.c @@ -182,6 +182,8 @@ static u32 bmp280_compensate_humidity(struct bmp280_data *data, + (s32)2097152) * H2 + 8192) >> 14); var -= ((((var >> 15) * (var >> 15)) >> 7) * (s32)H1) >> 4; + var = clamp_val(var, 0, 419430400); + return var >> 12; }; -- 2.25.1