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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E6E5AC433FE for ; Sun, 9 Oct 2022 11:57:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230095AbiJIL5o (ORCPT ); Sun, 9 Oct 2022 07:57:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229615AbiJIL5n (ORCPT ); Sun, 9 Oct 2022 07:57:43 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 054F627FD6 for ; Sun, 9 Oct 2022 04:57:43 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 96B5960BC1 for ; Sun, 9 Oct 2022 11:57:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1D84EC433D6; Sun, 9 Oct 2022 11:57:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1665316662; bh=n9FVRwbXSzvED7AdqW64tqTXRRb8tZLaditVYDqI4sQ=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=jIfX6Ern8PHcfvI8f6zmSL1YKcbOhFMYtC3vT+u8ebG6l8usNIAZ4tpHaE5jeM6+q 5cTsjpRu8lLQym5HkmUqknill+CrXTRc1bY+e0eFqLl9s/Wh9llDa1bWgrNkRb5N7M ifvSbH7IrgcORWKMpclCYybHv20Vw0dEDxaa+LErIIFRWGswzgJbSIsPwE4aps6v8C 09Gx73mpr1hkJ6NnsjjpWv7FAHjTH0D1TAecUwYrnZPGY3JU9qTKDW9oNmclfl2toN Glw+gFFFt0Sl1jrYsY5B8Z4dgkjTViKhy0DadJJ6T93bJ74/uZdgaiegsJWvq4WLOX sMRxluUgJSTeA== Date: Sun, 9 Oct 2022 12:57:58 +0100 From: Jonathan Cameron To: Nuno =?UTF-8?B?U8Oh?= Cc: , , , , , Heiko Stuebner , Martin Blumenstingl , Neil Armstrong , Shawn Guo , "Lars-Peter Clausen" , Jyoti Bhayana , Hans de Goede , Andriy Tryshnivskyy , Pengutronix Kernel Team , Miquel Raynal , Cixi Geng , Baolin Wang , "Ciprian Regus" , Fabio Estevam , Sascha Hauer , Alexandru Ardelean , "Florian Boor" , Michael Hennerich , Orson Zhai , "Chen-Yu Tsai" , Chunyan Zhang , "Vladimir Zapolskiy" , Andy Shevchenko , "Jerome Brunet" , Haibo Chen , Kevin Hilman Subject: Re: [PATCH v2 04/16] iio: adc: lpc32xx_adc: do not use internal iio_dev lock Message-ID: <20221009125758.77bf84c2@jic23-huawei> In-Reply-To: <20221004134909.1692021-5-nuno.sa@analog.com> References: <20221004134909.1692021-1-nuno.sa@analog.com> <20221004134909.1692021-5-nuno.sa@analog.com> X-Mailer: Claws Mail 4.1.0 (GTK 3.24.34; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org On Tue, 4 Oct 2022 15:48:57 +0200 Nuno S=C3=A1 wrote: > The iio_device lock is only meant for internal use. Hence define a > device local lock to protect against concurrent accesses. >=20 > While at it, properly include "mutex.h" for mutex related APIs. >=20 > Signed-off-by: Nuno S=C3=A1 Applied. Thanks, J > --- > drivers/iio/adc/lpc32xx_adc.c | 11 ++++++++--- > 1 file changed, 8 insertions(+), 3 deletions(-) >=20 > diff --git a/drivers/iio/adc/lpc32xx_adc.c b/drivers/iio/adc/lpc32xx_adc.c > index b56ce15255cf..732c924a976d 100644 > --- a/drivers/iio/adc/lpc32xx_adc.c > +++ b/drivers/iio/adc/lpc32xx_adc.c > @@ -15,6 +15,7 @@ > #include > #include > #include > +#include > #include > #include > =20 > @@ -49,6 +50,8 @@ struct lpc32xx_adc_state { > struct clk *clk; > struct completion completion; > struct regulator *vref; > + /* lock to protect against multiple access to the device */ > + struct mutex lock; > =20 > u32 value; > }; > @@ -64,10 +67,10 @@ static int lpc32xx_read_raw(struct iio_dev *indio_dev, > =20 > switch (mask) { > case IIO_CHAN_INFO_RAW: > - mutex_lock(&indio_dev->mlock); > + mutex_lock(&st->lock); > ret =3D clk_prepare_enable(st->clk); > if (ret) { > - mutex_unlock(&indio_dev->mlock); > + mutex_unlock(&st->lock); > return ret; > } > /* Measurement setup */ > @@ -80,7 +83,7 @@ static int lpc32xx_read_raw(struct iio_dev *indio_dev, > wait_for_completion(&st->completion); /* set by ISR */ > clk_disable_unprepare(st->clk); > *val =3D st->value; > - mutex_unlock(&indio_dev->mlock); > + mutex_unlock(&st->lock); > =20 > return IIO_VAL_INT; > =20 > @@ -201,6 +204,8 @@ static int lpc32xx_adc_probe(struct platform_device *= pdev) > iodev->modes =3D INDIO_DIRECT_MODE; > iodev->num_channels =3D ARRAY_SIZE(lpc32xx_adc_iio_channels); > =20 > + mutex_init(&st->lock); > + > retval =3D devm_iio_device_register(&pdev->dev, iodev); > if (retval) > return retval;