Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1025551pxb; Sun, 21 Feb 2021 08:42:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJzCsdoTOvuUpF6TNBjhmOxOwqWoL0QvhwdlPdYARZYijSf48mj3MOfyRY7kOQKHimd4NxLm X-Received: by 2002:a17:906:d0c3:: with SMTP id bq3mr17132335ejb.424.1613925762048; Sun, 21 Feb 2021 08:42:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613925762; cv=none; d=google.com; s=arc-20160816; b=x8u022HwCncbuiyTci8pFrt2CTuS6DYKwVpHLkpFAXm3bNmbL7wOxw9Cf9+7ikMpn2 WRL/PUr0MTH3I55Sajl7DC1uja6TNK4rATiSK9oMzLPM3YhIgmrIM1tASvXJxgPp5oXu etAnMCFGuVgYwhmpjYPvmmv5GV/Jsx7I4ia6DdLTe8AE1edpgX49JiPai0kWIsOJ51nD OXXaz+NocgqiMqbKbmYX4btP34/UAcxlgt7IR6HcoCzApDdH+/6XxUOqesS+V/TMLGUG ALcZov/Iysv/KLC3YOgXRhzvybMLuJIO5aZLVzgWDB0YnXzemDglgAgqxP/Dya3ErGzN zE7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=oQDdem2qIX6C1TDcVkQ89GaBEmO9mdZ/8XpkXjKfKhM=; b=stEE/XlFJMVRHzq6Fe8jH0oUI7OmNDhshyrASG5S6MhKlBoMt1TkTBUaeij4qnk0HQ NPxuJGBoPBaXKfAmJijbtduSU8VDj1g0fNIXn/hcZYQo9Q934SZAbJN5q5vHf7NqR3Ea DnbHqGJ/QxEUSystpmat6uQXFOZ1umjxp+dgyknCC8/MwdoasziQNqbjNTQDoYtN+IE9 9OpzHYhB/z/mF7I64ImYFtVmbGc8fAOEigZhigKBT6J1a09in/n+Nr63nHhxSghHMmbv ctdmhLOZ/rq4CE/RE9rxVEuypXjdn9ybhMJu4Hoq+QBDtAfysBwQNLCdjDxWiWrNNHrl lH4Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d13si10635217ejr.30.2021.02.21.08.42.19; Sun, 21 Feb 2021 08:42:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230122AbhBUQju (ORCPT + 99 others); Sun, 21 Feb 2021 11:39:50 -0500 Received: from mail.kernel.org ([198.145.29.99]:57658 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230060AbhBUQjt (ORCPT ); Sun, 21 Feb 2021 11:39:49 -0500 Received: from archlinux (cpc108967-cmbg20-2-0-cust86.5-4.cable.virginm.net [81.101.6.87]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C727664DA5; Sun, 21 Feb 2021 16:39:06 +0000 (UTC) Date: Sun, 21 Feb 2021 16:39:02 +0000 From: Jonathan Cameron To: Mircea Caprioru Cc: , , , , , , Sergiu Cuciurean Subject: Re: [PATCH 3/5] iio: adc: npcm_adc: Replace indio_dev->mlock with own device lock Message-ID: <20210221163902.617ee71d@archlinux> In-Reply-To: <20200928131333.36646-3-mircea.caprioru@analog.com> References: <20200928131333.36646-1-mircea.caprioru@analog.com> <20200928131333.36646-3-mircea.caprioru@analog.com> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 28 Sep 2020 16:13:31 +0300 Mircea Caprioru wrote: > From: Sergiu Cuciurean > > As part of the general cleanup of indio_dev->mlock, this change replaces > it with a local lock on the device's state structure. > > This is part of a bigger cleanup. > Link: https://lore.kernel.org/linux-iio/CA+U=Dsoo6YABe5ODLp+eFNPGFDjk5ZeQEceGkqjxXcVEhLWubw@mail.gmail.com/ > > Signed-off-by: Sergiu Cuciurean > Signed-off-by: Mircea Caprioru Applied, thanks, Jonathan > --- > drivers/iio/adc/npcm_adc.c | 15 +++++++++++++-- > 1 file changed, 13 insertions(+), 2 deletions(-) > > diff --git a/drivers/iio/adc/npcm_adc.c b/drivers/iio/adc/npcm_adc.c > index d9d105920001..f7bc0bb7f112 100644 > --- a/drivers/iio/adc/npcm_adc.c > +++ b/drivers/iio/adc/npcm_adc.c > @@ -25,6 +25,15 @@ struct npcm_adc { > wait_queue_head_t wq; > struct regulator *vref; > struct reset_control *reset; > + /* > + * Lock to protect the device state during a potential concurrent > + * read access from userspace. Reading a raw value requires a sequence > + * of register writes, then a wait for a event and finally a register > + * read, during which userspace could issue another read request. > + * This lock protects a read access from ocurring before another one > + * has finished. > + */ > + struct mutex lock; > }; > > /* ADC registers */ > @@ -135,9 +144,9 @@ static int npcm_adc_read_raw(struct iio_dev *indio_dev, > > switch (mask) { > case IIO_CHAN_INFO_RAW: > - mutex_lock(&indio_dev->mlock); > + mutex_lock(&info->lock); > ret = npcm_adc_read(info, val, chan->channel); > - mutex_unlock(&indio_dev->mlock); > + mutex_unlock(&info->lock); > if (ret) { > dev_err(info->dev, "NPCM ADC read failed\n"); > return ret; > @@ -187,6 +196,8 @@ static int npcm_adc_probe(struct platform_device *pdev) > return -ENOMEM; > info = iio_priv(indio_dev); > > + mutex_init(&info->lock); > + > info->dev = &pdev->dev; > > info->regs = devm_platform_ioremap_resource(pdev, 0);