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 5CCA6C43461 for ; Wed, 16 Sep 2020 17:55:00 +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 F1BAF2074B for ; Wed, 16 Sep 2020 17:54:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="vPIbX1zs"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="JrVlBOLx" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F1BAF2074B 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=ILW9k454JkGsgEqhwwWaKbXn5ozd6HrW3c43nTi+k7Y=; b=vPIbX1zsAr6wkLuJy1oz8i1Z0 SdssMbQIzJOsJJIkSmR+dVmBy8N5ZshhefrYQSEaoX6YuEjHdvRWPfKjwF538VZwsTdScP6N1/DBA fif4jX75H9E98sdmPKSn8vIS9XIAC5iyWoNNJnCmqUdK8llTxKCRcMBuzl7o8r/G6jleamxhs6jNh mASOgzU2NSoZ2ycWX63+Wo5TtDcjl6+ILP7AoMAkaKAXuxhfqf8ZILALRqXDA2BZb0XwIXswlBE+K LAvWOh7o8fS94CnFm57LshMc8RHqGyTnPyLoCa5MJzsBsEqgAXvI5B7fWPXOxRLDnOmyZWRVoVQAS FMOcrI0Pw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kIbbk-0005YV-Ni; Wed, 16 Sep 2020 17:52:40 +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 1kIbbh-0005Xa-VT for linux-arm-kernel@lists.infradead.org; Wed, 16 Sep 2020 17:52:39 +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 2DA05206F7; Wed, 16 Sep 2020 17:52:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600278755; bh=qtv1VH/lpDHNP4K1hT8rAdmDRzl6jlj/EIejRq6sqbM=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=JrVlBOLxNcilm6sLhM9bAJJOwFcJcdsVCk8k8N5S1f2dOztgBjoFniBlVcxNGf07N ikMhBD9w4QtsOnVMbBvdBylxMa6WEdZ6zney8xAm8/+iu+wtHo0f4vHzypodHRsz9Y O8b76NNvKUPPw+pgOy5YlKh+MBvOVrP/lU5aPFnM= Date: Wed, 16 Sep 2020 18:52:30 +0100 From: Jonathan Cameron To: Fabrice Gasnier Subject: Re: [PATCH v2] iio: stm32-dac: Replace indio_dev->mlock with own device lock Message-ID: <20200916185230.45c0b7d4@archlinux> In-Reply-To: References: <20200826063850.47625-1-alexandru.ardelean@analog.com> <20200916092349.75647-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-20200916_135238_136692_1357CC9C X-CRM114-Status: GOOD ( 26.86 ) 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: olivier.moysan@st.com, alexandre.torgue@st.com, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Sergiu Cuciurean , mcoquelin.stm32@gmail.com, Alexandru Ardelean , linux-stm32@st-md-mailman.stormreply.com, 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:18:02 +0200 Fabrice Gasnier wrote: > On 9/16/20 11:23 AM, Alexandru Ardelean wrote: > > From: Sergiu Cuciurean > > > > As part of the general cleanup of indio_dev->mlock, this change replaces > > it with a local lock. The lock protects against potential races when > > reading the CR reg and then updating, so that the state of pm_runtime > > is consistent between the two operations. > > > > 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 > > --- > > drivers/iio/dac/stm32-dac.c | 13 +++++++++---- > > 1 file changed, 9 insertions(+), 4 deletions(-) > > Hi Alexandru, > > Many thanks for this updated patch, > > Reviewed-by: Fabrice Gasnier Applied to the togreg branch of iio.git and pushed out as testing for the autobuilders to poke at it. Thanks, Jonathan > > Best regards, > Fabrice > > > > > diff --git a/drivers/iio/dac/stm32-dac.c b/drivers/iio/dac/stm32-dac.c > > index 092c796fa3d9..12dec68c16f7 100644 > > --- a/drivers/iio/dac/stm32-dac.c > > +++ b/drivers/iio/dac/stm32-dac.c > > @@ -26,9 +26,12 @@ > > /** > > * struct stm32_dac - private data of DAC driver > > * @common: reference to DAC common data > > + * @lock: lock to protect against potential races when reading > > + * and update CR, to keep it in sync with pm_runtime > > */ > > struct stm32_dac { > > struct stm32_dac_common *common; > > + struct mutex lock; > > }; > > > > static int stm32_dac_is_enabled(struct iio_dev *indio_dev, int channel) > > @@ -58,10 +61,10 @@ static int stm32_dac_set_enable_state(struct iio_dev *indio_dev, int ch, > > int ret; > > > > /* already enabled / disabled ? */ > > - mutex_lock(&indio_dev->mlock); > > + mutex_lock(&dac->lock); > > ret = stm32_dac_is_enabled(indio_dev, ch); > > if (ret < 0 || enable == !!ret) { > > - mutex_unlock(&indio_dev->mlock); > > + mutex_unlock(&dac->lock); > > return ret < 0 ? ret : 0; > > } > > > > @@ -69,13 +72,13 @@ static int stm32_dac_set_enable_state(struct iio_dev *indio_dev, int ch, > > ret = pm_runtime_get_sync(dev); > > if (ret < 0) { > > pm_runtime_put_noidle(dev); > > - mutex_unlock(&indio_dev->mlock); > > + mutex_unlock(&dac->lock); > > return ret; > > } > > } > > > > ret = regmap_update_bits(dac->common->regmap, STM32_DAC_CR, msk, en); > > - mutex_unlock(&indio_dev->mlock); > > + mutex_unlock(&dac->lock); > > if (ret < 0) { > > dev_err(&indio_dev->dev, "%s failed\n", en ? > > "Enable" : "Disable"); > > @@ -327,6 +330,8 @@ static int stm32_dac_probe(struct platform_device *pdev) > > indio_dev->info = &stm32_dac_iio_info; > > indio_dev->modes = INDIO_DIRECT_MODE; > > > > + mutex_init(&dac->lock); > > + > > ret = stm32_dac_chan_of_init(indio_dev); > > if (ret < 0) > > return ret; > > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel