Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp1335745ybp; Thu, 17 Oct 2019 11:14:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqwfj2Ap7D1Fi2Bxv3vwg7lVgwb9YxXe039xlxRUups0IEnqQpcenOYiywrNF7Jp7zoh8HZR X-Received: by 2002:a05:6402:650:: with SMTP id u16mr5260868edx.211.1571336047907; Thu, 17 Oct 2019 11:14:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571336047; cv=none; d=google.com; s=arc-20160816; b=pP87ejgTsUPGvi8x63vDZZLDgw6qu3tQU68v0GQCyLKIYWjw/u/OgoxuGTrbcC1c6K uOnZxGcd6+ytaGu4s+v2MGuuskOWVP1X2b0ay08fc1/DVP6/gg4SWS6zyXWbUEF/7kBL 9ZFCNqFVWk9syc6tYh4bvcAJHQJnK9GXvelWeZQchEch8+DYx1qMubBLbfILq2i833gu 6SmaRSiJ6YC8X9n21gzvIad5g+0vjldq6EERrT9+mbfGdqVNRA8bASKbE863a9V6J21S bGM1/3ixLpbmLEsW7DgdbBXiZcyNvb3SblQju2wjQHBfP55GP7mxtd0idwa/GAFD/IOQ eycw== 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=T2+EkjoU8rXFvOqyLiR0snNkiybjR16gxIS60fWkVBI=; b=rAqQP9KCKDwUYceZLdawWhqj7FD7Zhk4q80pC6dV8GspA3+SH6/bC2sAHxom5cBgKp y8/fg4gll/eFbGcqQReCtlH8aMXYl9RGrIglUbJ0b9VARJrUf2iujOcxvyB4CTNuFT9G la4o7LeAsNuwR/NJnN6m/aO0zgmXSSj99CBtlsE36SYJriJb0ctFv3h7KFWdJoZ4EP51 QtzIWJRCAEhr6omGxWhEDnLlPW24Y1HlIS/r7WtqB2zuHaEM9w+DXaCj78gtNWH95QOk HJBra3FCcBqYnCx5CJe8lRPk+FVlLZOj7qENr5SXowkswY54AehZRcFmV6Ux71WYAyjS J77w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="Bl/lUss3"; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f17si2736065edf.328.2019.10.17.11.13.44; Thu, 17 Oct 2019 11:14:07 -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=@kernel.org header.s=default header.b="Bl/lUss3"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2406721AbfJPV7x (ORCPT + 99 others); Wed, 16 Oct 2019 17:59:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:52728 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2438278AbfJPV6u (ORCPT ); Wed, 16 Oct 2019 17:58:50 -0400 Received: from localhost (unknown [192.55.54.58]) (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 445C420872; Wed, 16 Oct 2019 21:58:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1571263129; bh=vO0yUZV65ERdk3w+vcfuwASmrtK1bHnh3veVjPqCnuY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Bl/lUss3I5eG5XpRIMVdtWdy7YHBLcX1xHg6oAnTbMMI/kYrVUVTCDdMaCVlFHAmf TPbU31WQIGGkarPsm4vUzDaQH/0n89w1H5dhNhFL5orNaVLdjNWEZmOA63mJbwdwwW 44jQNObDhldViye/KlzD+sR4TjplgpChqHlrW/EM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andreas Klinger , Stable@vger.kernel.org, Jonathan Cameron Subject: [PATCH 5.3 052/112] iio: adc: hx711: fix bug in sampling of data Date: Wed, 16 Oct 2019 14:50:44 -0700 Message-Id: <20191016214857.800085108@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191016214844.038848564@linuxfoundation.org> References: <20191016214844.038848564@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 commit 4043ecfb5fc4355a090111e14faf7945ff0fdbd5 upstream. Fix bug in sampling function hx711_cycle() when interrupt occures while PD_SCK is high. If PD_SCK is high for at least 60 us power down mode of the sensor is entered which in turn leads to a wrong measurement. Switch off interrupts during a PD_SCK high period and move query of DOUT to the latest point of time which is at the end of PD_SCK low period. This bug exists in the driver since it's initial addition. The more interrupts on the system the higher is the probability that it happens. Fixes: c3b2fdd0ea7e ("iio: adc: hx711: Add IIO driver for AVIA HX711") Signed-off-by: Andreas Klinger Cc: Signed-off-by: Jonathan Cameron Signed-off-by: Greg Kroah-Hartman --- drivers/iio/adc/hx711.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) --- a/drivers/iio/adc/hx711.c +++ b/drivers/iio/adc/hx711.c @@ -100,14 +100,14 @@ struct hx711_data { static int hx711_cycle(struct hx711_data *hx711_data) { - int val; + unsigned long flags; /* * if preempted for more then 60us while PD_SCK is high: * hx711 is going in reset * ==> measuring is false */ - preempt_disable(); + local_irq_save(flags); gpiod_set_value(hx711_data->gpiod_pd_sck, 1); /* @@ -117,7 +117,6 @@ static int hx711_cycle(struct hx711_data */ ndelay(hx711_data->data_ready_delay_ns); - val = gpiod_get_value(hx711_data->gpiod_dout); /* * here we are not waiting for 0.2 us as suggested by the datasheet, * because the oscilloscope showed in a test scenario @@ -125,7 +124,7 @@ static int hx711_cycle(struct hx711_data * and 0.56 us for PD_SCK low on TI Sitara with 800 MHz */ gpiod_set_value(hx711_data->gpiod_pd_sck, 0); - preempt_enable(); + local_irq_restore(flags); /* * make it a square wave for addressing cases with capacitance on @@ -133,7 +132,8 @@ static int hx711_cycle(struct hx711_data */ ndelay(hx711_data->data_ready_delay_ns); - return val; + /* sample as late as possible */ + return gpiod_get_value(hx711_data->gpiod_dout); } static int hx711_read(struct hx711_data *hx711_data)