From patchwork Mon Jan 1 18:54:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 10139201 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1999560362 for ; Mon, 1 Jan 2018 18:55:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0D23A2654B for ; Mon, 1 Jan 2018 18:55:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 01FA128699; Mon, 1 Jan 2018 18:55:05 +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=-6.9 required=2.0 tests=BAYES_00,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 9237E285D5 for ; Mon, 1 Jan 2018 18:55:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751774AbeAASzF (ORCPT ); Mon, 1 Jan 2018 13:55:05 -0500 Received: from mail-wm0-f66.google.com ([74.125.82.66]:39349 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750950AbeAASzE (ORCPT ); Mon, 1 Jan 2018 13:55:04 -0500 Received: by mail-wm0-f66.google.com with SMTP id i11so57798476wmf.4 for ; Mon, 01 Jan 2018 10:55:03 -0800 (PST) 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=z7img6GImXC75J4GxnDO8MOIKZ2RTe+6H+8k31UWTp8=; b=S2hXF0RBuqrrUGFTNXcneOwToa7WcXTwoCtS6N0jOhDO/M7xexUygNnc9Z9ROTgFRP 3XEP4ZGVrl3G2TC+iuGmZLZZcKL8uhYOtskfCrKx02VgcemCjZF7EcVwQycNjDTCJVW8 pEsmEys+ZOedzjYzvuY+8kWgrA+JDgYRBIVVGTw2jJ3YjIXGr/ZSPCIEW/6zi29WkGUz bz9/UeuNFiMToWcxqCvQbcLQqll04a6i+rOo6gtwuqkU7kpw8FpKXy56r+WB4IV7nifn 4kz66pxJk5oNKTk8UQrkDxASU/aB7NlFeTPswyHjii/yDSiOboWJdSAg3OzipHbgb0aY AKjw== X-Gm-Message-State: AKGB3mLYP3R/wkf6YdJWsG4WFgAEMy3rIr57sAKilWFZfb+QxZWXuN8j mlfse5lrdkElt9gTcJQEtuwb8NUzRO4= X-Google-Smtp-Source: ACJfBovZtZIsRSofzYoNFrRNBJdYAB6yCmGadulkPJ4SkjJNCBJv1fZBeSDHRD1gMIdPavkDZkBg2w== X-Received: by 10.28.104.6 with SMTP id d6mr32464275wmc.101.1514832903109; Mon, 01 Jan 2018 10:55:03 -0800 (PST) Received: from localhost.localdomain ([151.66.78.0]) by smtp.gmail.com with ESMTPSA id f4sm57959688wra.75.2018.01.01.10.55.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 01 Jan 2018 10:55:02 -0800 (PST) From: Lorenzo Bianconi To: jic23@kernel.org Cc: linux-iio@vger.kernel.org Subject: [PATCH 2/3] iio: imu: st_lsm6dsx: introduce conf_lock mutex Date: Mon, 1 Jan 2018 19:54:43 +0100 Message-Id: <20180101185444.22045-3-lorenzo.bianconi@redhat.com> X-Mailer: git-send-email 2.15.1 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 Add conf_lock mutex to prevent concurrent FIFO configuration update Fixes: 290a6ce11d93 (iio: imu: add support to lsm6dsx driver) Signed-off-by: Lorenzo Bianconi --- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h | 2 ++ drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c | 21 +++++++++++++-------- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 6 ++++++ 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h index 4fdb7fcc3ea8..cebc6bd31b79 100644 --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h @@ -130,6 +130,7 @@ struct st_lsm6dsx_sensor { * @irq: Device interrupt line (I2C or SPI). * @lock: Mutex to protect read and write operations. * @fifo_lock: Mutex to prevent concurrent access to the hw FIFO. + * @conf_lock: Mutex to prevent concurrent FIFO configuration update. * @fifo_mode: FIFO operating mode supported by the device. * @enable_mask: Enabled sensor bitmask. * @sip: Total number of samples (acc/gyro) in a given pattern. @@ -144,6 +145,7 @@ struct st_lsm6dsx_hw { struct mutex lock; struct mutex fifo_lock; + struct mutex conf_lock; enum st_lsm6dsx_fifo_mode fifo_mode; u8 enable_mask; diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c index 755c472e8a05..c899d658f6be 100644 --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c @@ -325,38 +325,40 @@ static int st_lsm6dsx_update_fifo(struct iio_dev *iio_dev, bool enable) struct st_lsm6dsx_hw *hw = sensor->hw; int err; + mutex_lock(&hw->conf_lock); + if (hw->fifo_mode != ST_LSM6DSX_FIFO_BYPASS) { err = st_lsm6dsx_flush_fifo(hw); if (err < 0) - return err; + goto out; } if (enable) { err = st_lsm6dsx_sensor_enable(sensor); if (err < 0) - return err; + goto out; } else { err = st_lsm6dsx_sensor_disable(sensor); if (err < 0) - return err; + goto out; } err = st_lsm6dsx_set_fifo_odr(sensor, enable); if (err < 0) - return err; + goto out; err = st_lsm6dsx_update_decimators(hw); if (err < 0) - return err; + goto out; err = st_lsm6dsx_update_watermark(sensor, sensor->watermark); if (err < 0) - return err; + goto out; if (hw->enable_mask) { err = st_lsm6dsx_set_fifo_mode(hw, ST_LSM6DSX_FIFO_CONT); if (err < 0) - return err; + goto out; /* * store enable buffer timestamp as reference to compute @@ -365,7 +367,10 @@ static int st_lsm6dsx_update_fifo(struct iio_dev *iio_dev, bool enable) sensor->ts = iio_get_time_ns(iio_dev); } - return 0; +out: + mutex_unlock(&hw->conf_lock); + + return err; } static irqreturn_t st_lsm6dsx_handler_irq(int irq, void *private) diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c index 812cd25f284e..4d43c956d676 100644 --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c @@ -528,7 +528,12 @@ static int st_lsm6dsx_set_watermark(struct iio_dev *iio_dev, unsigned int val) if (val < 1 || val > hw->settings->max_fifo_size) return -EINVAL; + mutex_lock(&hw->conf_lock); + err = st_lsm6dsx_update_watermark(sensor, val); + + mutex_unlock(&hw->conf_lock); + if (err < 0) return err; @@ -739,6 +744,7 @@ int st_lsm6dsx_probe(struct device *dev, int irq, int hw_id, const char *name, mutex_init(&hw->lock); mutex_init(&hw->fifo_lock); + mutex_init(&hw->conf_lock); hw->dev = dev; hw->irq = irq;