Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1024625pxb; Sun, 21 Feb 2021 08:40:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJy+eQDYGd2PB962rX3AIssXmlpLdgKLp3R+LtiwenhvBHhCvLlpfGEHAMnywuqoF8XmvLke X-Received: by 2002:a17:907:7785:: with SMTP id ky5mr17942933ejc.176.1613925637680; Sun, 21 Feb 2021 08:40:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613925637; cv=none; d=google.com; s=arc-20160816; b=wJI8EbdEtR5ss2WBt0wEUxfd288JRlMnOoBhqRVPdgKnFzLJeEsR/ml8zdnOpAYHUu 1GlzFva2oEI+nAb1pAJCnS4mrQyQjjhnCu65xEp0yy9hPN4EfgLgWnRcDOg6iDXO3nhJ JO0tCHlQA6zaLWoGtPmVlbnYqqcQUkL3kNR/zSuovw4VDNmeATI3xXTpjx0gYln7KumY ZjynGWGZ8TDcjm7h6YFuEx1eqYUJjCJtkNOzZDYPSGo8jX9Ms8TYPpWAjgm6UsL/o5XJ 5rkisXSOxrq2siOo3XKjeRGDcrflLQB6Sd0JwChLbzz4zi4EgIlKE1ShR6w/l/P1hc2X Im1w== 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=tui7G1+i/nV0gr3tSvV4wsN8PfZ8TF2A0XMRxo20M48=; b=hfxpEVHzkITH69yPyunPEGiUvLNNHf1mOhwRCScr/J06V1VB1PEJlMewoO88rWaw6P B6n8u+K6YR/PT5whkS5hhFqrQ3C69MtR1e5m77slTYQwyW9SILi/k6+zxcH+S6WypqaA c+Aj41vGUUQYC4yGjX4HW2tnB3poK80NcSOk+PZHIvkB0+tfHB8cDSQ9cvDg5LFfQv3I L0RWpjqfDRzG5fm2i/EfRSZzgqZxjcNF/2eG6cK6Ak0lBc5oQZI0xm+BZfw3W2TU3xgL sM8aFxOMp+uvXFKTxV7a/MpWmbT7trmmyBkbbd6Hxrdl5DrnNW8y5TiwVR5dBw5+dETW xc7Q== 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 c9si10198028edq.47.2021.02.21.08.40.15; Sun, 21 Feb 2021 08:40:37 -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 S230006AbhBUQjS (ORCPT + 99 others); Sun, 21 Feb 2021 11:39:18 -0500 Received: from mail.kernel.org ([198.145.29.99]:57436 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229926AbhBUQjN (ORCPT ); Sun, 21 Feb 2021 11:39:13 -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 38F8564E2E; Sun, 21 Feb 2021 16:38:30 +0000 (UTC) Date: Sun, 21 Feb 2021 16:38:26 +0000 From: Jonathan Cameron To: Mircea Caprioru Cc: , , , , , , Sergiu Cuciurean Subject: Re: [PATCH 2/5] iio: adc: palmas_gpadc: Replace indio_dev->mlock with own device lock Message-ID: <20210221163826.10ba97be@archlinux> In-Reply-To: <20200928131333.36646-2-mircea.caprioru@analog.com> References: <20200928131333.36646-1-mircea.caprioru@analog.com> <20200928131333.36646-2-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:30 +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/palmas_gpadc.c | 16 +++++++++++++--- > 1 file changed, 13 insertions(+), 3 deletions(-) > > diff --git a/drivers/iio/adc/palmas_gpadc.c b/drivers/iio/adc/palmas_gpadc.c > index 889b88768b63..14874f11614d 100644 > --- a/drivers/iio/adc/palmas_gpadc.c > +++ b/drivers/iio/adc/palmas_gpadc.c > @@ -90,6 +90,12 @@ static struct palmas_gpadc_info palmas_gpadc_info[] = { > * 3: 800 uA > * @extended_delay: enable the gpadc extended delay mode > * @auto_conversion_period: define the auto_conversion_period > + * @lock: 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 completion callback, > + * 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. > * > * This is the palmas_gpadc structure to store run-time information > * and pointers for this driver instance. > @@ -110,6 +116,7 @@ struct palmas_gpadc { > bool wakeup1_enable; > bool wakeup2_enable; > int auto_conversion_period; > + struct mutex lock; > }; > > /* > @@ -388,7 +395,7 @@ static int palmas_gpadc_read_raw(struct iio_dev *indio_dev, > if (adc_chan > PALMAS_ADC_CH_MAX) > return -EINVAL; > > - mutex_lock(&indio_dev->mlock); > + mutex_lock(&adc->lock); > > switch (mask) { > case IIO_CHAN_INFO_RAW: > @@ -414,12 +421,12 @@ static int palmas_gpadc_read_raw(struct iio_dev *indio_dev, > goto out; > } > > - mutex_unlock(&indio_dev->mlock); > + mutex_unlock(&adc->lock); > return ret; > > out: > palmas_gpadc_read_done(adc, adc_chan); > - mutex_unlock(&indio_dev->mlock); > + mutex_unlock(&adc->lock); > > return ret; > } > @@ -516,6 +523,9 @@ static int palmas_gpadc_probe(struct platform_device *pdev) > adc->dev = &pdev->dev; > adc->palmas = dev_get_drvdata(pdev->dev.parent); > adc->adc_info = palmas_gpadc_info; > + > + mutex_init(&adc->lock); > + > init_completion(&adc->conv_completion); > dev_set_drvdata(&pdev->dev, indio_dev); >