Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp22611pxb; Fri, 15 Jan 2021 04:57:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJy3pH8mYVTW3uqAl6qZue7KvLKuC87pgd3noV12og22Ya9wlSSwB3N/0urTWcmgTZZKKvZ+ X-Received: by 2002:a05:6402:17:: with SMTP id d23mr9563662edu.341.1610715451540; Fri, 15 Jan 2021 04:57:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610715451; cv=none; d=google.com; s=arc-20160816; b=We1VBxI4vn4Dhfpnb8yqtB6KOEPymXEMOUGKzRVminOAmSzIYLtTsjeWUxccYnv+6i P1E3vbLLx222o7d1IiAMMAR16Y1gbXnn6lz4SUbb2cKDLUbyqkXFWzIpPGQjG/mhRyz8 BmmPpCikX6e0pAL+yVZ8doQq8qEua5/RJkPkfZWBOHCyvbaKHyfWAgM71RyC5JzbE5Iv dcUEj37awa9JCgodnc+ffT+r+pfQvreL/xj7SbfADmH0iQzZxLrIS0aJnVEHCreRhuPY NOMQuHFrYaLXYu0QbL0dyRXPm45Ssv69aq4Axj24q5RTcJTToTS/opCKbVOGgMpKM1jK /aQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=xQ+Cepqo37QXtFrQjcNMfcXAlnKMTS/zMPMXkiElKFI=; b=jjD7D2GxD3O4RIUoRAfDRR8jkAnxkSQ2g0PEwT+R+6hCyCHjY1JgWuBXw214BLCrSz X8yqmqfvocQj5xosn982+R8d+82cdxMc6nLwsyZhu3Ibo7r1bHdSHmNN0VjMDCS7m3PM c5jxJB2VbQgVsQE0h+ELVuQ7DVAk1Y1To/Ou7mF4hWZwmZzlHCXCDPxqCZYSMChjLl3H 9Nk9pzeMJK/Gb0HSr+vKNXQuzNi0UExxEH/FtRKhpAHi3rfivhb413QBwM/NfoQu1PzS I4FOs2QNa+I7CQ1vDE3SeKPw4lsfccvRewwmvvJSogsRC+PZPNMSnunCKWxpAJX+p99f ZTPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=WF0h0uxt; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b6si4703399edu.567.2021.01.15.04.57.07; Fri, 15 Jan 2021 04:57:31 -0800 (PST) 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=@linuxfoundation.org header.s=korg header.b=WF0h0uxt; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388048AbhAOM4d (ORCPT + 99 others); Fri, 15 Jan 2021 07:56:33 -0500 Received: from mail.kernel.org ([198.145.29.99]:41310 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387474AbhAOMen (ORCPT ); Fri, 15 Jan 2021 07:34:43 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4099F207C4; Fri, 15 Jan 2021 12:34:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1610714067; bh=qD8t3yfuxRe1FK7vPwW1t7d8isOLIsh2qYREjRYkVAA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WF0h0uxtF45YlHp2Bi5A46tp0uLzE2aChUzZO+WMUF33KdafUqHvgZP0egpkBU9ZA UW1xjiN+XwA71nh7Kx87pnRZX6x2zAhHdmTCfZIsr9a5HcNE9u/1moaHWYyO2hc+oS WT+ygFcvgNCFlk8oYQaTup2v9dhXzSNQhVnACFP4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lorenzo Bianconi , Stable@vger.kernel.org, Jonathan Cameron , Sudip Mukherjee Subject: [PATCH 5.4 31/62] iio: imu: st_lsm6dsx: fix edge-trigger interrupts Date: Fri, 15 Jan 2021 13:27:53 +0100 Message-Id: <20210115121959.912680991@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210115121958.391610178@linuxfoundation.org> References: <20210115121958.391610178@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Lorenzo Bianconi commit 3f9bce7a22a3f8ac9d885c9d75bc45569f24ac8b upstream If we are using edge IRQs, new samples can arrive while processing current interrupt since there are no hw guarantees the irq line stays "low" long enough to properly detect the new interrupt. In this case the new sample will be missed. Polling FIFO status register in st_lsm6dsx_handler_thread routine allow us to read new samples even if the interrupt arrives while processing previous data and the timeslot where the line is "low" is too short to be properly detected. Fixes: 89ca88a7cdf2 ("iio: imu: st_lsm6dsx: support active-low interrupts") Fixes: 290a6ce11d93 ("iio: imu: add support to lsm6dsx driver") Signed-off-by: Lorenzo Bianconi Link: https://lore.kernel.org/r/5e93cda7dc1e665f5685c53ad8e9ea71dbae782d.1605378871.git.lorenzo@kernel.org Cc: Signed-off-by: Jonathan Cameron [sudip: manual backport to old irq handler path] Signed-off-by: Sudip Mukherjee Signed-off-by: Greg Kroah-Hartman --- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c | 26 ++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c @@ -664,13 +664,29 @@ static irqreturn_t st_lsm6dsx_handler_ir static irqreturn_t st_lsm6dsx_handler_thread(int irq, void *private) { struct st_lsm6dsx_hw *hw = private; - int count; + int fifo_len = 0, len; - mutex_lock(&hw->fifo_lock); - count = hw->settings->fifo_ops.read_fifo(hw); - mutex_unlock(&hw->fifo_lock); + /* + * If we are using edge IRQs, new samples can arrive while + * processing current interrupt since there are no hw + * guarantees the irq line stays "low" long enough to properly + * detect the new interrupt. In this case the new sample will + * be missed. + * Polling FIFO status register allow us to read new + * samples even if the interrupt arrives while processing + * previous data and the timeslot where the line is "low" is + * too short to be properly detected. + */ + do { + mutex_lock(&hw->fifo_lock); + len = hw->settings->fifo_ops.read_fifo(hw); + mutex_unlock(&hw->fifo_lock); - return count ? IRQ_HANDLED : IRQ_NONE; + if (len > 0) + fifo_len += len; + } while (len > 0); + + return fifo_len ? IRQ_HANDLED : IRQ_NONE; } static int st_lsm6dsx_buffer_preenable(struct iio_dev *iio_dev)