From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.6 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_2 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B8221C43461 for ; Thu, 17 Sep 2020 18:28:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 637E2221EE for ; Thu, 17 Sep 2020 18:28:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600367330; bh=x0yrJojLX0QmfsidGFj/TCRgWQNWYafkq8OmMlqEjGo=; h=Date:From:To:Cc:Subject:In-Reply-To:References:List-ID:From; b=nRBi2bzRS8qYQT/aBN1bgQB2OuoOBcP+LUShGx5/FBXnIqfKc8neLQIKV+NUCMd0P OQXcKrPUOaMiKa0V+cY5qTEFeei83EoJuzKwLgpzA7UzA9Amk9W+fjhdlhXOPgrikV VzDF2Qi5Pxh4tpWIWPWth7xAwRDZ5vlXmTNPouVg= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726612AbgIQS2k (ORCPT ); Thu, 17 Sep 2020 14:28:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:33988 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726540AbgIQS1p (ORCPT ); Thu, 17 Sep 2020 14:27:45 -0400 Received: from archlinux (cpc149474-cmbg20-2-0-cust94.5-4.cable.virginm.net [82.4.196.95]) (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 EBD52221EE; Thu, 17 Sep 2020 18:27:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600367264; bh=x0yrJojLX0QmfsidGFj/TCRgWQNWYafkq8OmMlqEjGo=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=btOwzNo+fZeau3dTn6RXwQa+SS26dR/NKoQ00xDO6Z6SDvWshmUBL24SqVqrjP0YV ch20VqkkdQX8ZaEtm+t48MKWGTkGUXtsr+Q61GED7+ASnuJNQkWeXtAuibtlgW6uYR rfDrWi9v43RZgAWuORQ28FD9xnfvAtBLeTAKaxCw= Date: Thu, 17 Sep 2020 19:27:39 +0100 From: Jonathan Cameron To: Alexandru Ardelean Cc: , , , , , , , , Sergiu Cuciurean Subject: Re: [PATCH v2] iio: adc: fsl-imx25-gcq: Replace indio_dev->mlock with own device lock Message-ID: <20200917192739.38a13ae0@archlinux> In-Reply-To: <20200916092928.78026-1-alexandru.ardelean@analog.com> References: <20200826120609.203724-1-alexandru.ardelean@analog.com> <20200916092928.78026-1-alexandru.ardelean@analog.com> X-Mailer: Claws Mail 3.17.6 (GTK+ 2.24.32; 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 Wed, 16 Sep 2020 12:29:28 +0300 Alexandru Ardelean wrote: > From: Sergiu Cuciurean > > As part of the general cleanup of indio_dev->mlock, this change replaces > it with a local lock, to protect against any other accesses during the > reading of sample. Reading a sample requires multiple consecutive regmap > operations and a completion callback, so this requires that no other > read occurs until it completes. > > 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: Alexandru Ardelean This seems simple enough so I've applied it to the togreg branch of iio.git Thanks, Jonathan > --- > drivers/iio/adc/fsl-imx25-gcq.c | 15 +++++++++++++-- > 1 file changed, 13 insertions(+), 2 deletions(-) > > diff --git a/drivers/iio/adc/fsl-imx25-gcq.c b/drivers/iio/adc/fsl-imx25-gcq.c > index 8cb51cf7a816..ab5139e911c3 100644 > --- a/drivers/iio/adc/fsl-imx25-gcq.c > +++ b/drivers/iio/adc/fsl-imx25-gcq.c > @@ -40,6 +40,15 @@ struct mx25_gcq_priv { > int irq; > struct regulator *vref[4]; > u32 channel_vref_mv[MX25_NUM_CFGS]; > + /* > + * 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; > }; > > #define MX25_CQG_CHAN(chan, id) {\ > @@ -137,9 +146,9 @@ static int mx25_gcq_read_raw(struct iio_dev *indio_dev, > > switch (mask) { > case IIO_CHAN_INFO_RAW: > - mutex_lock(&indio_dev->mlock); > + mutex_lock(&priv->lock); > ret = mx25_gcq_get_raw_value(&indio_dev->dev, chan, priv, val); > - mutex_unlock(&indio_dev->mlock); > + mutex_unlock(&priv->lock); > return ret; > > case IIO_CHAN_INFO_SCALE: > @@ -314,6 +323,8 @@ static int mx25_gcq_probe(struct platform_device *pdev) > return PTR_ERR(priv->regs); > } > > + mutex_init(&priv->lock); > + > init_completion(&priv->completed); > > ret = mx25_gcq_setup_cfgs(pdev, priv); From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_2 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C27CBC433E2 for ; Thu, 17 Sep 2020 18:29:16 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4BC30221F1 for ; Thu, 17 Sep 2020 18:29:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="aFN3hV7F"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="btOwzNo+" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4BC30221F1 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=IqQl44x0jQrP1pNDCgfjNG86g/9Z1sQWqr0Vb2lNXZo=; b=aFN3hV7FTwpE7V3AOGU0MBFDR +8YERroMz+K2A8HdPfgrgDuRO40wJJb7LPJfMe6yIsQB9N+QJ5bHcGeSDzuwaPxoKsp+YGv3uXZGN 31gnE7mn0NCWHoked9WI9eUaybI0YCXEQBHcjyvuOPdPo15p5LDy88YQx/gUDnBXSmnizz7PGLLwS YjF9Gi3Zw/imbwMwCe88tei78rNF+18Xs9iH/hBHRisEmnWw7RpC2dQr+W0EbLBg6yGV2XNId0rC7 Lf6Unv/fgaXhfzAaONsBNAY2PEJ4z/vqsjzJX3oAzX1Pms/uVc8Vzg2fnm4+WuDnydxjJV7HuHjzh 6uQvKdfoA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kIydI-0004Ny-GT; Thu, 17 Sep 2020 18:27:48 +0000 Received: from mail.kernel.org ([198.145.29.99]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kIydF-0004NS-PZ for linux-arm-kernel@lists.infradead.org; Thu, 17 Sep 2020 18:27:46 +0000 Received: from archlinux (cpc149474-cmbg20-2-0-cust94.5-4.cable.virginm.net [82.4.196.95]) (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 EBD52221EE; Thu, 17 Sep 2020 18:27:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600367264; bh=x0yrJojLX0QmfsidGFj/TCRgWQNWYafkq8OmMlqEjGo=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=btOwzNo+fZeau3dTn6RXwQa+SS26dR/NKoQ00xDO6Z6SDvWshmUBL24SqVqrjP0YV ch20VqkkdQX8ZaEtm+t48MKWGTkGUXtsr+Q61GED7+ASnuJNQkWeXtAuibtlgW6uYR rfDrWi9v43RZgAWuORQ28FD9xnfvAtBLeTAKaxCw= Date: Thu, 17 Sep 2020 19:27:39 +0100 From: Jonathan Cameron To: Alexandru Ardelean Subject: Re: [PATCH v2] iio: adc: fsl-imx25-gcq: Replace indio_dev->mlock with own device lock Message-ID: <20200917192739.38a13ae0@archlinux> In-Reply-To: <20200916092928.78026-1-alexandru.ardelean@analog.com> References: <20200826120609.203724-1-alexandru.ardelean@analog.com> <20200916092928.78026-1-alexandru.ardelean@analog.com> X-Mailer: Claws Mail 3.17.6 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200917_142745_973145_D505CAE5 X-CRM114-Status: GOOD ( 23.87 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-iio@vger.kernel.org, festevam@gmail.com, s.hauer@pengutronix.de, linux-kernel@vger.kernel.org, Sergiu Cuciurean , linux-imx@nxp.com, kernel@pengutronix.de, shawnguo@kernel.org, linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Wed, 16 Sep 2020 12:29:28 +0300 Alexandru Ardelean wrote: > From: Sergiu Cuciurean > > As part of the general cleanup of indio_dev->mlock, this change replaces > it with a local lock, to protect against any other accesses during the > reading of sample. Reading a sample requires multiple consecutive regmap > operations and a completion callback, so this requires that no other > read occurs until it completes. > > 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: Alexandru Ardelean This seems simple enough so I've applied it to the togreg branch of iio.git Thanks, Jonathan > --- > drivers/iio/adc/fsl-imx25-gcq.c | 15 +++++++++++++-- > 1 file changed, 13 insertions(+), 2 deletions(-) > > diff --git a/drivers/iio/adc/fsl-imx25-gcq.c b/drivers/iio/adc/fsl-imx25-gcq.c > index 8cb51cf7a816..ab5139e911c3 100644 > --- a/drivers/iio/adc/fsl-imx25-gcq.c > +++ b/drivers/iio/adc/fsl-imx25-gcq.c > @@ -40,6 +40,15 @@ struct mx25_gcq_priv { > int irq; > struct regulator *vref[4]; > u32 channel_vref_mv[MX25_NUM_CFGS]; > + /* > + * 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; > }; > > #define MX25_CQG_CHAN(chan, id) {\ > @@ -137,9 +146,9 @@ static int mx25_gcq_read_raw(struct iio_dev *indio_dev, > > switch (mask) { > case IIO_CHAN_INFO_RAW: > - mutex_lock(&indio_dev->mlock); > + mutex_lock(&priv->lock); > ret = mx25_gcq_get_raw_value(&indio_dev->dev, chan, priv, val); > - mutex_unlock(&indio_dev->mlock); > + mutex_unlock(&priv->lock); > return ret; > > case IIO_CHAN_INFO_SCALE: > @@ -314,6 +323,8 @@ static int mx25_gcq_probe(struct platform_device *pdev) > return PTR_ERR(priv->regs); > } > > + mutex_init(&priv->lock); > + > init_completion(&priv->completed); > > ret = mx25_gcq_setup_cfgs(pdev, priv); _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel