Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1024226pxb; Sun, 21 Feb 2021 08:39:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJyg1Q4mQDijD781janu/o0ZGM/A53GFqeY3MMyoYB38asNZz4E1rziyagzmXpT9wY6WGydM X-Received: by 2002:a05:6402:22f6:: with SMTP id dn22mr18525707edb.277.1613925589187; Sun, 21 Feb 2021 08:39:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613925589; cv=none; d=google.com; s=arc-20160816; b=wV4RFLI3thH/oZ2Cpz4u2cJ9W9WYJiABL6ujRTP68P0/SmPDTDvJwhBkgtfaK5d7C2 E3blWEoSwnQ5VRkHpAMs3WtgOZD90h7t2Gfn3pjAUpFl80g0ycu9IR42N480nrDA42F6 R6W1Dm2bjbFagaEpTuLQ77B4QI/ZBKrIfTGaasV/v3gETzgDcsJLO7e39jmS/b2KfoCU BvEDl4IhbG3iJq958Rzys7JLNyMbXfssstE1fR61GEjdN4RMQ23Lzy7X1/DWZqGX71/a PCh5cVD3X3MWHWMFFzko+p4587O45ZxNyzgXsjfYh6oFcJSTVSYdwJQaMZsUs8UdGTJq NaEg== 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=/6paG1RqfoKydEdyZow9f3lrvZ3ATj/gWcAf6cKvJ4I=; b=0aG/zOO38/xk7aG2sQnHGwynnjSjohictlSJ2I8G9qOITge+d3msNExtuCygzx4Fxj 21AE5huWG+moh7mVdyzCUdx+ci3x3nQf7L/gYQ122Lqmy0uoqnMYH1vyzcZ6KwHGuZ35 18NdREprzj0iAt8g6b9DA/3nbx2Kb7EdNutwm7c4E2ZeKcilv6PkcSD2mSEHgQgOC1vm ACNl4oFx6bneHSK1cbdgQhr0NX2OazwQT/lmyWkZoV+J1EeuoMdemM1frGjEtOw3PNVH bA2E9a2JdH4ebgBe95LrRkrZlQLYxEN9t4hg86izO83m1dkJKGRO89F+UI0lHSTTAEhH 9DCw== 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 dj18si9196292edb.422.2021.02.21.08.39.26; Sun, 21 Feb 2021 08:39:49 -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 S229999AbhBUQiN (ORCPT + 99 others); Sun, 21 Feb 2021 11:38:13 -0500 Received: from mail.kernel.org ([198.145.29.99]:57156 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229826AbhBUQiK (ORCPT ); Sun, 21 Feb 2021 11:38:10 -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 5177764E61; Sun, 21 Feb 2021 16:37:27 +0000 (UTC) Date: Sun, 21 Feb 2021 16:37:23 +0000 From: Jonathan Cameron To: Mircea Caprioru Cc: , , , , , , Sergiu Cuciurean Subject: Re: [PATCH 1/5] iio: adc: spear_adc: Replace indio_dev->mlock with own device lock Message-ID: <20210221163723.53d8c7a8@archlinux> In-Reply-To: <20200928131333.36646-1-mircea.caprioru@analog.com> References: <20200928131333.36646-1-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:29 +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 I guess I was waiting for a v2 of the series. Seeing as it has been a while and the first 3 patches are fine on their own, I'll pick them up now. Applied to the togreg branch of iio.git and pushed out as testing for the autobuilders to play with it. Thanks, Jonathan > --- > drivers/iio/adc/spear_adc.c | 20 ++++++++++++++++---- > 1 file changed, 16 insertions(+), 4 deletions(-) > > diff --git a/drivers/iio/adc/spear_adc.c b/drivers/iio/adc/spear_adc.c > index 1bc986a7009d..d93e580b3dc5 100644 > --- a/drivers/iio/adc/spear_adc.c > +++ b/drivers/iio/adc/spear_adc.c > @@ -75,6 +75,15 @@ struct spear_adc_state { > struct adc_regs_spear6xx __iomem *adc_base_spear6xx; > struct clk *clk; > struct completion completion; > + /* > + * 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. > + */ > + struct mutex lock; > u32 current_clk; > u32 sampling_freq; > u32 avg_samples; > @@ -146,7 +155,7 @@ static int spear_adc_read_raw(struct iio_dev *indio_dev, > > switch (mask) { > case IIO_CHAN_INFO_RAW: > - mutex_lock(&indio_dev->mlock); > + mutex_lock(&st->lock); > > status = SPEAR_ADC_STATUS_CHANNEL_NUM(chan->channel) | > SPEAR_ADC_STATUS_AVG_SAMPLE(st->avg_samples) | > @@ -159,7 +168,7 @@ static int spear_adc_read_raw(struct iio_dev *indio_dev, > wait_for_completion(&st->completion); /* set by ISR */ > *val = st->value; > > - mutex_unlock(&indio_dev->mlock); > + mutex_unlock(&st->lock); > > return IIO_VAL_INT; > > @@ -187,7 +196,7 @@ static int spear_adc_write_raw(struct iio_dev *indio_dev, > if (mask != IIO_CHAN_INFO_SAMP_FREQ) > return -EINVAL; > > - mutex_lock(&indio_dev->mlock); > + mutex_lock(&st->lock); > > if ((val < SPEAR_ADC_CLK_MIN) || > (val > SPEAR_ADC_CLK_MAX) || > @@ -199,7 +208,7 @@ static int spear_adc_write_raw(struct iio_dev *indio_dev, > spear_adc_set_clk(st, val); > > out: > - mutex_unlock(&indio_dev->mlock); > + mutex_unlock(&st->lock); > return ret; > } > > @@ -271,6 +280,9 @@ static int spear_adc_probe(struct platform_device *pdev) > } > > st = iio_priv(indio_dev); > + > + mutex_init(&st->lock); > + > st->np = np; > > /*