Received: by 10.223.176.5 with SMTP id f5csp227831wra; Tue, 30 Jan 2018 10:31:44 -0800 (PST) X-Google-Smtp-Source: AH8x226i2LNJ32TGGcYJWNalClcxJXNDCAFcKN2isDisBkqjcCfO2E/A1C5nBdx/kD3pP7BHDFXO X-Received: by 2002:a17:902:5303:: with SMTP id b3-v6mr14727385pli.133.1517337104502; Tue, 30 Jan 2018 10:31:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517337104; cv=none; d=google.com; s=arc-20160816; b=oPKioBe5VWLSUJs1PHXHZyxp7F0paPfuI1JiwORVWQO87xshb/YjdaGSvcwT/1kYYn 8Ip4Xl8nNSg9vYePdzbzeSiSzW/iBUXNsFtONOWVJNRxfjFvybOTuvM9eOtyBu4AEN/C 2/h4Np1sayYUoiLaTGs//Av4D6jOlwOZWDvtuvEwWzAoSpnUfJR2Mp/d4lZFLAniK/pX wYjxiSRyw2ognVgZQKah2LoV0/CGku8pQRYaC8TxoJ2TyczsazFtEesUq/F4DNtSzISU gOa/l6fqIwwkm1KZAefaTrhvAEGzTrRsR3FdkZ9FbQExbhgCRvPY07FJWY14Q2LDU5Vo fXHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=lA1Rvv4J0fBecWE2DkYMeNFEAOkPtbsWceY2F6Tauyc=; b=QR45zNllahySwA2CFbdcnappkJhcrH7OOKt6py0+29SRe848QWXLkhTl1uSLmJo9WZ s1AUeeP7NxL/I13IHg7n2+0AEPal4pJdQyWBFIZmgRiMajDToQBbKXk3BhvoCotRAcpP BsoFaiEd+1F4bQ68iVGgRI2upFZ4s7312O/PCSutR9OS5D61x1Ep0zpylLpqgJe8+vfn kYDlROsdMyP6FoDwsPiAp13aVaB4She8ZVUrhL8YyG7V0NouNHoXORF6Usa0bmxG4MfM KLQqmFWs8fQkSTlk3ITEKKWOiM0amq8+bTyFj6lXHLFyRH7xxoHWlGn1NbmXc6obLxp5 pHTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=NnbRty0p; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l71si9568102pgd.305.2018.01.30.10.31.29; Tue, 30 Jan 2018 10:31:44 -0800 (PST) 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=@gmail.com header.s=20161025 header.b=NnbRty0p; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753220AbeA3SA2 (ORCPT + 99 others); Tue, 30 Jan 2018 13:00:28 -0500 Received: from mail-pg0-f67.google.com ([74.125.83.67]:41523 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751584AbeA3SAZ (ORCPT ); Tue, 30 Jan 2018 13:00:25 -0500 Received: by mail-pg0-f67.google.com with SMTP id 136so7839588pgd.8; Tue, 30 Jan 2018 10:00:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=lA1Rvv4J0fBecWE2DkYMeNFEAOkPtbsWceY2F6Tauyc=; b=NnbRty0paS7D9rjERWaOi4LHJPigFQOj2Ljn7tnLxTTksaoYuP7o2E/LRp4XiZDypy co9QNVydbd0oN04U3ka4ebtTIizqDOPa1QlwBt/ngkVM3MbRtBloF+YsDCY4sGyfm+2C oHgRGM7X6lJwHnLPPElhB0ztyLZ2B2C3OUNizcs9PG7pig2WDvocqFdxMuKEn+2Zh5o+ rW4ommmxWnh5vL/9tqw6jYAeI+1d2JpWOIDzN9mJafGpGoNNSUW6RPMBNjEwKJhIPayy XSsJCUFIY/fFVXyD8G0J2HwVaGP/8xeteGz9tvMqiUVvQwGukyDISu+KuFlgusr0TZ9w cOeg== 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=lA1Rvv4J0fBecWE2DkYMeNFEAOkPtbsWceY2F6Tauyc=; b=QuX/BDKwXUR5HvG9nRp/S2UyyBW+msMdd8QaciAG9NMfpg5GZwE87ptqtSrZRa12cL CqkPd3T2eKvzKw9INi1FsLVXHAqE4MOGWoGAXV8hvMYDpkIR1RVkAkSUkOSwsZXwhUrC n5rwJzpMKecE7mA7PToUiz9ozDNYChMm7zFvxvjn7nCUZPtNPAyr8myMs7pxXqozwT8J a2wImlJnmGqd3MrSXayE5R/3Zos96doff8yFaL2CESfVqyqx07fSG6YpxLQMeB09CmJa 0GUV1aQAPP70Za3zpc0mLRyc6+5iqQoNLPt/fZcV5td4MjDK7so4gmCnvS4+B4V4MciT NQzA== X-Gm-Message-State: AKwxytc1W9pYsOhh90TFuDgZM9pAoEIgrVPt/RUq+17Jz7YmYLrkZukU Wfpy/5OtF/OFgEe0grjSeVU= X-Received: by 2002:a17:902:8e86:: with SMTP id bg6-v6mr26988093plb.402.1517335224048; Tue, 30 Jan 2018 10:00:24 -0800 (PST) Received: from shreeya-VirtualBox ([103.212.140.149]) by smtp.gmail.com with ESMTPSA id z9sm22080410pgc.5.2018.01.30.10.00.22 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 30 Jan 2018 10:00:23 -0800 (PST) From: Shreeya Patel To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, knaack.h@gmx.de, pmeerw@pmeerw.net, gregkh@linuxfoundation.org, linux-iio@vger.kernel.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org Cc: Shreeya Patel Subject: [PATCH v3] Staging: iio: ade7758: Expand buf_lock to cover both buffer and state protection Date: Tue, 30 Jan 2018 23:30:17 +0530 Message-Id: <1517335217-6163-1-git-send-email-shreeya.patel23498@gmail.com> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org iio_dev->mlock is to be used only by the IIO core for protecting device mode changes between INDIO_DIRECT and INDIO_BUFFER. This patch replaces the use of mlock with the already established buf_lock mutex. Introducing 'unlocked' forms of read and write registers. The read/write frequency functions now require buf_lock to be held. That's not obvious so avoid this but moving the locking inside the functions where it is then clear that they are taking the unlocked forms of the register read/write. Signed-off-by: Shreeya Patel --- Changes in v2 -Add static keyword to newly introduced functions and remove some added comments which are not required. Changes in v3 -Remove some useless mlocks and send it as another patch. Also make the necessary change in the current patch associated with the new patch with commit id 88eba33. Make commit message more appropriate. drivers/staging/iio/meter/ade7758.h | 2 +- drivers/staging/iio/meter/ade7758_core.c | 40 ++++++++++++++++++++++++-------- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/drivers/staging/iio/meter/ade7758.h b/drivers/staging/iio/meter/ade7758.h index 6ae78d8..2de81b5 100644 --- a/drivers/staging/iio/meter/ade7758.h +++ b/drivers/staging/iio/meter/ade7758.h @@ -111,7 +111,7 @@ * @trig: data ready trigger registered with iio * @tx: transmit buffer * @rx: receive buffer - * @buf_lock: mutex to protect tx and rx + * @buf_lock: mutex to protect tx, rx, read and write frequency **/ struct ade7758_state { struct spi_device *us; diff --git a/drivers/staging/iio/meter/ade7758_core.c b/drivers/staging/iio/meter/ade7758_core.c index 227dbfc..38e5d67 100644 --- a/drivers/staging/iio/meter/ade7758_core.c +++ b/drivers/staging/iio/meter/ade7758_core.c @@ -24,17 +24,25 @@ #include "meter.h" #include "ade7758.h" -int ade7758_spi_write_reg_8(struct device *dev, u8 reg_address, u8 val) +static int __ade7758_spi_write_reg_8(struct device *dev, u8 reg_address, u8 val) { - int ret; struct iio_dev *indio_dev = dev_to_iio_dev(dev); struct ade7758_state *st = iio_priv(indio_dev); - mutex_lock(&st->buf_lock); st->tx[0] = ADE7758_WRITE_REG(reg_address); st->tx[1] = val; - ret = spi_write(st->us, st->tx, 2); + return spi_write(st->us, st->tx, 2); +} + +int ade7758_spi_write_reg_8(struct device *dev, u8 reg_address, u8 val) +{ + int ret; + struct iio_dev *indio_dev = dev_to_iio_dev(dev); + struct ade7758_state *st = iio_priv(indio_dev); + + mutex_lock(&st->buf_lock); + ret = __ade7758_spi_write_reg_8(dev, reg_address, val); mutex_unlock(&st->buf_lock); return ret; @@ -91,7 +99,7 @@ static int ade7758_spi_write_reg_24(struct device *dev, u8 reg_address, return ret; } -int ade7758_spi_read_reg_8(struct device *dev, u8 reg_address, u8 *val) +static int __ade7758_spi_read_reg_8(struct device *dev, u8 reg_address, u8 *val) { struct iio_dev *indio_dev = dev_to_iio_dev(dev); struct ade7758_state *st = iio_priv(indio_dev); @@ -111,7 +119,6 @@ int ade7758_spi_read_reg_8(struct device *dev, u8 reg_address, u8 *val) }, }; - mutex_lock(&st->buf_lock); st->tx[0] = ADE7758_READ_REG(reg_address); st->tx[1] = 0; @@ -124,7 +131,19 @@ int ade7758_spi_read_reg_8(struct device *dev, u8 reg_address, u8 *val) *val = st->rx[0]; error_ret: + return ret; +} + +int ade7758_spi_read_reg_8(struct device *dev, u8 reg_address, u8 *val) +{ + struct iio_dev *indio_dev = dev_to_iio_dev(dev); + struct ade7758_state *st = iio_priv(indio_dev); + int ret; + + mutex_lock(&st->buf_lock); + ret = __ade7758_spi_read_reg_8(dev, reg_address, val); mutex_unlock(&st->buf_lock); + return ret; } @@ -503,14 +522,14 @@ static int ade7758_write_samp_freq(struct device *dev, int val) goto out; } - ret = ade7758_spi_read_reg_8(dev, ADE7758_WAVMODE, ®); + ret = __ade7758_spi_read_reg_8(dev, ADE7758_WAVMODE, ®); if (ret) goto out; reg &= ~(5 << 3); reg |= t << 5; - ret = ade7758_spi_write_reg_8(dev, ADE7758_WAVMODE, reg); + ret = __ade7758_spi_write_reg_8(dev, ADE7758_WAVMODE, reg); out: return ret; @@ -540,14 +559,15 @@ static int ade7758_write_raw(struct iio_dev *indio_dev, int val, int val2, long mask) { int ret; + struct ade7758_state *st = iio_priv(indio_dev); switch (mask) { case IIO_CHAN_INFO_SAMP_FREQ: if (val2) return -EINVAL; - mutex_lock(&indio_dev->mlock); + mutex_lock(&st->buf_lock); ret = ade7758_write_samp_freq(&indio_dev->dev, val); - mutex_unlock(&indio_dev->mlock); + mutex_unlock(&st->buf_lock); return ret; default: return -EINVAL; -- 2.7.4