From patchwork Mon Oct 29 03:18:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kelly X-Patchwork-Id: 10658755 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2E27413BF for ; Mon, 29 Oct 2018 03:18:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 24F7B297A4 for ; Mon, 29 Oct 2018 03:18:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 188F7297A8; Mon, 29 Oct 2018 03:18:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7ECD4297A4 for ; Mon, 29 Oct 2018 03:18:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729159AbeJ2MFo (ORCPT ); Mon, 29 Oct 2018 08:05:44 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:40807 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729140AbeJ2MFo (ORCPT ); Mon, 29 Oct 2018 08:05:44 -0400 Received: by mail-pl1-f194.google.com with SMTP id b9-v6so3088407pls.7 for ; Sun, 28 Oct 2018 20:18:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=martingkelly-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=Wm4/I9L8Ymd/TmlIXMJBztJ0DlfkSgRCiuM1t0nSWUA=; b=yc0pg04nknbomxVr+/v4dwLWGywoU/QHKroyH2/ijJ44bRp9KYTqVBVPreqGqRwa4O 4YY50dOvJlbgna6B7RQ/uAKwJ1KNoCrMOgEuzig0zo5YwygkbXUJhpTWjKtfHdas5Yse ak+I1qUv1slfUxTFHbqZXEwO2R1iR+jcQIIXGmwnsoX1NWNvvucFGryMV9w+wiiKfgPn G8qQUltANqO+CZpPHBmptjS0iwnGcAAAa1mGppLw+yfx/Jxav/GXV5EB2mYJ8kKR28ZI VZ+lQbrONliWGDBlbQiy90PLb3a6CiaIPnMFIJqb5jBVW2BhVcWsNPsprhRi8uKLhujH S3kQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=Wm4/I9L8Ymd/TmlIXMJBztJ0DlfkSgRCiuM1t0nSWUA=; b=rOLBCndKgyLseTZfTRbD/LXwxoox/IMZqvsE0t8eyik5lbWiDOKXUkI4iEzVP/5k4X k3MJfTYbjV1eh+YMGqzhIfkJk9G2P1C8Fm2W4XDH1ce7tMHoVC/Q6E4/PVe83JmMPyfR IIY998VXfpgBqEIJUvONY8Bo/xSMjIA4gxnD2dIY8wC3s/TFDq7wch+dWQ1Oo5qv1K9E 4vYcPbdlGdw8NHAt7lHWO+fZLq2gXf4Q2NAcGxJJdCK4H/6amMOPDjkt3UfItsJLkBkv Uebjo7VkUyCnIn1pI3R4oVlZa4tm7fLUhlMuBpNs26k70OBa50cgbynMSZyKePWLD/BJ 76Uw== X-Gm-Message-State: AGRZ1gIHI02FwV3T2UxvuwDJZKXE75711d+jl5lF3vHQMLI9g9pgdwet K4xfFLOxFE8Tbx/Ba4TkZZmLOgsjQ57kWQ== X-Google-Smtp-Source: AJdET5fvEkjY9C9JRbVdHYCCB4OBoPf1V9Y0uZmFgrgCPmpkxWFXVu2k8bRX/E7ZkdEDPfFE2r03Jw== X-Received: by 2002:a17:902:8bc6:: with SMTP id r6-v6mr12752575plo.0.1540783136783; Sun, 28 Oct 2018 20:18:56 -0700 (PDT) Received: from cascade.Home (71-212-17-184.tukw.qwest.net. [71.212.17.184]) by smtp.gmail.com with ESMTPSA id r18-v6sm19061587pgv.17.2018.10.28.20.18.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 28 Oct 2018 20:18:56 -0700 (PDT) From: Martin Kelly X-Google-Original-From: Martin Kelly , Jonathan Cameron , Lorenzo Bianconi , Martin Kelly Subject: [PATCH] iio:st_magn: enable device after trigger Date: Sun, 28 Oct 2018 20:18:53 -0700 Message-Id: <20181029031853.11747-1-martin@martingkelly.com> X-Mailer: git-send-email 2.11.0 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Martin Kelly Currently, we enable the device before we enable the device trigger. At high frequencies, this can cause interrupts that don't yet have a poll function associated with them and are thus treated as spurious. At high frequencies with level interrupts, this can even cause an interrupt storm of repeated spurious interrupts (~100,000 on my Beagleboard with the LSM9DS1 magnetometer). If these repeat too much, the interrupt will get disabled and the device will stop functioning. To prevent these problems, enable the device prior to enabling the device trigger, and disable the divec prior to disabling the trigger. This means there's no window of time during which the device creates interrupts but we have no trigger to answer them. Fixes: 90efe055629 ("iio: st_sensors: harden interrupt handling") Signed-off-by: Martin Kelly Tested-by: Denis Ciocca --- Note that, during testing of this change, Denis Ciocca noticed that when we fail to disable the IIO buffer, we bail immediately and don't disable the sensor. This commit does not fix that issue, but that should be fixed in a follow-up commit. I will leave it to Denis, since he noticed the issue, but I'd be happy to send a patch for it if he doesn't. drivers/iio/magnetometer/st_magn_buffer.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) -- 2.11.0 diff --git a/drivers/iio/magnetometer/st_magn_buffer.c b/drivers/iio/magnetometer/st_magn_buffer.c index 0a9e8fadfa9d..37ab30566464 100644 --- a/drivers/iio/magnetometer/st_magn_buffer.c +++ b/drivers/iio/magnetometer/st_magn_buffer.c @@ -30,11 +30,6 @@ int st_magn_trig_set_state(struct iio_trigger *trig, bool state) return st_sensors_set_dataready_irq(indio_dev, state); } -static int st_magn_buffer_preenable(struct iio_dev *indio_dev) -{ - return st_sensors_set_enable(indio_dev, true); -} - static int st_magn_buffer_postenable(struct iio_dev *indio_dev) { int err; @@ -50,7 +45,7 @@ static int st_magn_buffer_postenable(struct iio_dev *indio_dev) if (err < 0) goto st_magn_buffer_postenable_error; - return err; + return st_sensors_set_enable(indio_dev, true); st_magn_buffer_postenable_error: kfree(mdata->buffer_data); @@ -63,11 +58,11 @@ static int st_magn_buffer_predisable(struct iio_dev *indio_dev) int err; struct st_sensor_data *mdata = iio_priv(indio_dev); - err = iio_triggered_buffer_predisable(indio_dev); + err = st_sensors_set_enable(indio_dev, false); if (err < 0) goto st_magn_buffer_predisable_error; - err = st_sensors_set_enable(indio_dev, false); + err = iio_triggered_buffer_predisable(indio_dev); st_magn_buffer_predisable_error: kfree(mdata->buffer_data); @@ -75,7 +70,6 @@ static int st_magn_buffer_predisable(struct iio_dev *indio_dev) } static const struct iio_buffer_setup_ops st_magn_buffer_setup_ops = { - .preenable = &st_magn_buffer_preenable, .postenable = &st_magn_buffer_postenable, .predisable = &st_magn_buffer_predisable, };