Received: by 10.213.65.68 with SMTP id h4csp839511imn; Tue, 27 Mar 2018 09:44:13 -0700 (PDT) X-Google-Smtp-Source: AIpwx49jg0WpkjZJL3d7h/MwczAozjhyDK5MWDLq/pSFZDiLTwoHi0xL5PQrS59GELJXoB24Zy7J X-Received: by 10.99.113.25 with SMTP id m25mr59400pgc.164.1522169053270; Tue, 27 Mar 2018 09:44:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522169053; cv=none; d=google.com; s=arc-20160816; b=bYadAJbyG2mnfFG7H8BDfkmFp3Xj0ncsSlVSag132aJ3bDW8DVrDOS526iH2zQ1BAF CMcxse+M9wro+yVvUZH5+bQpa5oz64Iwvvayo+DKU9vlByLzvfuSTIQfnIoKVTQ28jc9 DfDryIs6Mh/ykjDl9Ece1v8ORkv+S/5B0aomRPRCuVJftKg0228KfTwkiHMGXLUOoQ13 0m5Iakh+efIFrftPBv0kxb91BEyVHs4pdv8+arDxo+stVIXwH5ziIJSRsTt7+kxEqUvM CGXbCpMShmO9xb/iFRl5mULwFE28C+hfx5HwCmqaK4X+FnF/yZUtvj7Jze8tNreEzmz3 uQbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=16FTKyBRNLzb1zyjBlpA3Ueeby8c8l5bsReCkLZq4CY=; b=Ir1culVJM3ioDbRhuQTTlf9Udz8lIZIyqdX9s9h7wylZyFlkngY9KoXkpQp2GcH7zt Kx3BlPHnOilpeOw+ql70G4UGPTkkrcVV+CBDU1X9PtAg4WY7Gtn6SYlppaLyGIxub9u3 7mWDuhNje6rCsRkfKTIWE5bePhBKT7ANAu4vUmFm9mQ/yNAG6GhOOqfnMj6bGeDUgCQ5 zZMPYqTbCFvn5bqY9QOmMo9t1r49CkInagRrVRtXDThAxjId1x5UjnlK67f2qXHZoIn7 NRhSYs4lKYDW9lACnSpsC6AJe1cTIUdQdrVxAqFDr9umw7VjLA9luTON9GMuIJQgzDzA 5Rtg== ARC-Authentication-Results: i=1; mx.google.com; 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 j11-v6si1532748plt.266.2018.03.27.09.43.59; Tue, 27 Mar 2018 09:44:13 -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; 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 S1752090AbeC0QnJ (ORCPT + 99 others); Tue, 27 Mar 2018 12:43:09 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:49384 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751082AbeC0QnF (ORCPT ); Tue, 27 Mar 2018 12:43:05 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 4ECC5F48; Tue, 27 Mar 2018 16:43:04 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lorenzo Bianconi , Jonathan Cameron Subject: [PATCH 4.15 101/105] iio: imu: st_lsm6dsx: introduce conf_lock mutex Date: Tue, 27 Mar 2018 18:28:21 +0200 Message-Id: <20180327162804.123578343@linuxfoundation.org> X-Mailer: git-send-email 2.16.3 In-Reply-To: <20180327162757.813009222@linuxfoundation.org> References: <20180327162757.813009222@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Lorenzo Bianconi commit 335eaedce461c9092e133ce0c6247f5a0b0baf69 upstream. Add conf_lock mutex to prevent concurrent FIFO configuration update Fixes: 290a6ce11d93 (iio: imu: add support to lsm6dsx driver) Signed-off-by: Lorenzo Bianconi Signed-off-by: Jonathan Cameron Signed-off-by: Greg Kroah-Hartman --- 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(-) --- 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; --- 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 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 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) --- 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(stru 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, mutex_init(&hw->lock); mutex_init(&hw->fifo_lock); + mutex_init(&hw->conf_lock); hw->dev = dev; hw->irq = irq;