From patchwork Wed Sep 27 02:17:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aastha Gupta X-Patchwork-Id: 9972971 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 C36E960365 for ; Wed, 27 Sep 2017 02:18:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AA25E29084 for ; Wed, 27 Sep 2017 02:18:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9DCD429087; Wed, 27 Sep 2017 02:18:08 +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.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID 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 3CDB729084 for ; Wed, 27 Sep 2017 02:18:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934942AbdI0CSH (ORCPT ); Tue, 26 Sep 2017 22:18:07 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:36371 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934797AbdI0CSG (ORCPT ); Tue, 26 Sep 2017 22:18:06 -0400 Received: by mail-pf0-f194.google.com with SMTP id f84so5759517pfj.3 for ; Tue, 26 Sep 2017 19:18:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=A/kABDwUF/WExdLXgYioIB6PuGB4B/jpmRioezUbiLo=; b=Po/cl6ZoY+cSwW2Tz+8DdjkQKo5c0PDnTyeaoVt/Xg7UgTOCDMwBggjC2+BP/7O/m8 EeBeAYWQrmWKDf5ebO/X6mo5tx0racyFDpA+EjrBoYoMdyyRdQjpr1zaTnkoaKxJu+DT e/zmA2NCJE8jjsvvLaAKmm/HUNoga0evmcxoNgjX+tRRSzYKncls+CGDJS21wJpYYrq0 SHQ4RoCDYIPYkq/o3Qk9t4lDU59r5CkpLRd8BsyVEqYrwfTy3WLPC/3zAN6Qi88s6jzE 4Ghpe9gONs1c+30PHZuRIMV3YsGuFoIiz48WQluT8YsCFSldQJ2doq03CE++LEk2lSuW 7AHA== 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=A/kABDwUF/WExdLXgYioIB6PuGB4B/jpmRioezUbiLo=; b=cjdeBkH7RzRF+PFrc9rR0SAaUsQaoj/5yUt1UwRFVXQ93FuxxfTemBrN3h357djM8w IzdiBMLPQCqTYCw9kYTjKaPySb9BXTpA8BNQH6+Oh0KBufzn15DJn+jEAttt/yakCY1+ u4kPLKDK+247tfFonONCYIxqwOllsV78JUh+zZWKNijxjKAkR7oA0l6wMtLaho1wxxU+ /5Wt2j3h9V1b8xOIfbXk/nOgapetIbvAuaAdHu15NKBgCuu2NbTThq8hYXaNXr2EsNK6 J8xPI7DFvTV/ZKgOgii2eMBS1FijFKqtTOWfjPycOkT3hrW0FWK2W4pIl+GZUyyXk3ED INGA== X-Gm-Message-State: AHPjjUh0uUgwbPj4B76pHOV0XcDJLDFf2SH2avrqQnSoDR0VC7wV/MzQ TzGfdb683gLIezMKBdsEu+0= X-Google-Smtp-Source: AOwi7QBJFNEdYRiA5d+GT5Nauo9d0R9VLLdUxkTiexts2pPtdqxEpS0n40QHAEUZpU22p2WkOvqY8g== X-Received: by 10.159.197.6 with SMTP id bj6mr12487792plb.178.1506478686430; Tue, 26 Sep 2017 19:18:06 -0700 (PDT) Received: from aastha-HP-Pavilion-15-Notebook-PC ([47.31.7.99]) by smtp.gmail.com with ESMTPSA id m5sm18534326pfg.12.2017.09.26.19.18.04 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 26 Sep 2017 19:18:05 -0700 (PDT) From: Aastha Gupta To: outreachy-kernel@googlegroups.com, hennerich@blackfin.uclinux.org, jic23@kernel.org, knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net, linux-iio@vger.kernel.org Cc: Aastha Gupta Subject: [PATCH v3] staging: iio: adc: ad7192: use driver private lock to protect hardware changes Date: Wed, 27 Sep 2017 07:47:52 +0530 Message-Id: <1506478672-5937-1-git-send-email-aastha.gupta4104@gmail.com> X-Mailer: git-send-email 2.7.4 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 The IIO subsystem is redefining iio_dev->mlock to be used by the IIO core only for protecting device operating mode changes. ie. Changes between INDIO_DIRECT_MODE, INDIO_BUFFER_* modes. In this driver, mlock was being used to protect hardware state changes. Replace it with a lock in the devices global data. Also, private driver lock is being used to protect hardware state changes as here state variables are being changed. Signed-off-by: Aastha Gupta --- changes in v3: - combined patch 1 and patch 2 into one patch drivers/staging/iio/adc/ad7192.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/staging/iio/adc/ad7192.c b/drivers/staging/iio/adc/ad7192.c index d11c6de..609a649 100644 --- a/drivers/staging/iio/adc/ad7192.c +++ b/drivers/staging/iio/adc/ad7192.c @@ -162,6 +162,7 @@ struct ad7192_state { u32 scale_avail[8][2]; u8 gpocon; u8 devid; + struct mutex lock; struct ad_sigma_delta sd; }; @@ -463,10 +464,10 @@ static int ad7192_read_raw(struct iio_dev *indio_dev, case IIO_CHAN_INFO_SCALE: switch (chan->type) { case IIO_VOLTAGE: - mutex_lock(&indio_dev->mlock); + mutex_lock(&st->lock); *val = st->scale_avail[AD7192_CONF_GAIN(st->conf)][0]; *val2 = st->scale_avail[AD7192_CONF_GAIN(st->conf)][1]; - mutex_unlock(&indio_dev->mlock); + mutex_unlock(&st->lock); return IIO_VAL_INT_PLUS_NANO; case IIO_TEMP: *val = 0; @@ -510,6 +511,7 @@ static int ad7192_write_raw(struct iio_dev *indio_dev, switch (mask) { case IIO_CHAN_INFO_SCALE: ret = -EINVAL; + mutex_lock(&st->lock); for (i = 0; i < ARRAY_SIZE(st->scale_avail); i++) if (val2 == st->scale_avail[i][1]) { ret = 0; @@ -523,6 +525,7 @@ static int ad7192_write_raw(struct iio_dev *indio_dev, ad7192_calibrate_all(st); break; } + mutex_unlock(&st->lock); break; case IIO_CHAN_INFO_SAMP_FREQ: if (!val) { @@ -634,6 +637,8 @@ static int ad7192_probe(struct spi_device *spi) st = iio_priv(indio_dev); + mutex_init(&st->lock); + st->avdd = devm_regulator_get(&spi->dev, "avdd"); if (IS_ERR(st->avdd)) return PTR_ERR(st->avdd);