Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp2780824rdb; Mon, 4 Dec 2023 07:23:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IHE7K2q9VbYSefBoGnb548MwqyJEeXnbxyl87QuTKWVoSk2JTlY7gNop69ScrSjXeQqtZBp X-Received: by 2002:a05:6a20:3d81:b0:18b:c927:d33a with SMTP id s1-20020a056a203d8100b0018bc927d33amr1929423pzi.46.1701703397608; Mon, 04 Dec 2023 07:23:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701703397; cv=none; d=google.com; s=arc-20160816; b=VyOLkksj4p6XR04tpiCTUs4CMrrafKbefuDKKziG0lDm9NELO0xXZE9I1qeHf2Fbur mr5LPbnkimEp5054McL1oIrX4syH6P26ZUG8j6vQRfVB4tjL/E7gzdDziZzhORIXLc8N +REvku02wVFvnBnGzDsaEsmuStGcZxbKa2XZ/ld9tmi+eKxgTUBAK2PVdkyxMJFDFKwD Gzpkkv0o3pWcDFlkCa6MA1XqrAqr5f8gsGpCmqyU/YUJXJ5AO4h5c6A5q6wRqhmu6706 BkKbU0E79GyN8dz6LqfldGquyt2CeD+2fbJv4wsWxFZVPieu+XFpwapXwLXbx9BNW6Uh EPtg== 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 :dkim-signature; bh=cwoETkpBY9vu9iOhSUV9A+fe8YyTjb1lCGMz4AwjtTs=; fh=cdh/zE3CZkKBVPpwlAi1MOirEcAUajw2fxcnBBQCP7U=; b=dX8jr83g2/6UBSERC+deUJptEtZaEJAEZNo+rGO93tXbAbz3btG353T9Imow2rWMc9 h3c3lyASUNHU1TnJYIxWYb5loUwrpsDx6O/9z1lPYbvITm8YPFgMQsT9Z/GDgLHGhTRC ySek5JjcN9PdFf0o6CNHbuYJLDfqRe/ArBtGBSUidEgcUVSCRI+7zH1y3hpiFsh5Wrog b6MqXGoULikptWO3KHK+AUn7bsJOxDlWOJZlz2Q/XDCW5tJLUMeoD2jfaM/izStvG9qA wJ/GscZGK+qEE3z60YpZrYfTXxltNYUSJUXWnBDLFE0K+qfrcMtL8Pg9t7LuZRh5SiCG Pv7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jDBKfr+3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id bh1-20020a056a02020100b0057760853706si8492038pgb.578.2023.12.04.07.23.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 07:23:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jDBKfr+3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 717D0804E825; Mon, 4 Dec 2023 07:23:16 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234374AbjLDPXG (ORCPT + 99 others); Mon, 4 Dec 2023 10:23:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32978 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234336AbjLDPXE (ORCPT ); Mon, 4 Dec 2023 10:23:04 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 44B30C3 for ; Mon, 4 Dec 2023 07:23:11 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7AC14C433C7; Mon, 4 Dec 2023 15:23:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701703390; bh=v9HHvcP+5Qmgs8vOwwtctHKS8YafaG9blaZ4o+1KOkQ=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=jDBKfr+3DhZ3aeR9N1JjGZsaFWKv9q1J/2v3sVT4Pm6kkyE7apm0zJGFeENTzDoUl AGjP4IATo+ytQW9WW3M6zndzZr31v3rrsWjpmL2wzWWL9hSEGIgs8Zq1FSH0FKZY0X mAdZTg0vRjvLLzCRoHCBrBAYRRWtNRyLMKjA5SbKxR4ZapV5Pqu4XOyQydB0MRNYPt 341gpuGi6c/is6XEo+RBDslYzXfGmX3FGsKPZSOV9aZ7uckOKB0LpHDiTVsR9V/6MW 9R392iaMgdn7bd/Eyl1zvuhhRlQyyqMMpXV6YRJu9oIpSirTXhuPHKR6hTGwNPBkR0 elNCR0o1y2cHQ== Date: Mon, 4 Dec 2023 15:23:01 +0000 From: Jonathan Cameron To: Nuno Sa via B4 Relay Cc: , linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-iio@vger.kernel.org, Olivier MOYSAN , Greg Kroah-Hartman , "Rafael J. Wysocki" , Rob Herring , Frank Rowand , Lars-Peter Clausen , Michael Hennerich Subject: Re: [PATCH 06/12] iio: adc: ad9467: add mutex to struct ad9467_state Message-ID: <20231204152301.6c212539@jic23-huawei> In-Reply-To: <20231121-dev-iio-backend-v1-6-6a3d542eba35@analog.com> References: <20231121-dev-iio-backend-v1-0-6a3d542eba35@analog.com> <20231121-dev-iio-backend-v1-6-6a3d542eba35@analog.com> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 04 Dec 2023 07:23:16 -0800 (PST) On Tue, 21 Nov 2023 11:20:19 +0100 Nuno Sa via B4 Relay wrote: > From: Nuno Sa > > When calling ad9467_set_scale(), multiple calls to ad9467_spi_write() > are done which means we need to properly protect the whole operation so > we are sure we will be in a sane state if two concurrent calls occur. > > Fixes: ad6797120238 ("iio: adc: ad9467: add support AD9467 ADC") > Signed-off-by: Nuno Sa > --- > drivers/iio/adc/ad9467.c | 6 +++++- > 1 file changed, 5 insertions(+), 1 deletion(-) > > diff --git a/drivers/iio/adc/ad9467.c b/drivers/iio/adc/ad9467.c > index 04474dbfa631..91821dee03b7 100644 > --- a/drivers/iio/adc/ad9467.c > +++ b/drivers/iio/adc/ad9467.c > @@ -4,7 +4,7 @@ > * > * Copyright 2012-2020 Analog Devices Inc. > */ > - > +#include > #include > #include > #include > @@ -122,6 +122,8 @@ struct ad9467_state { > unsigned int output_mode; > > struct gpio_desc *pwrdown_gpio; > + /* protect against concurrent accesses to the device */ Not very specific. Concurrent access usually fine at granularity of individual read/write as the bus locks protect it. What state is actually being protected? A shared buffer or some state that we need to ensure remains consistent between driver and device? > + struct mutex lock; > }; > > static int ad9467_spi_read(struct spi_device *spi, unsigned int reg) > @@ -162,6 +164,7 @@ static int ad9467_reg_access(struct adi_axi_adc_conv *conv, unsigned int reg, > int ret; > > if (!readval) { > + guard(mutex)(&st->lock); > ret = ad9467_spi_write(spi, reg, writeval); > if (ret) > return ret; > @@ -310,6 +313,7 @@ static int ad9467_set_scale(struct adi_axi_adc_conv *conv, int val, int val2) > if (scale_val[0] != val || scale_val[1] != val2) > continue; > > + guard(mutex)(&st->lock); > ret = ad9467_spi_write(st->spi, AN877_ADC_REG_VREF, > info->scale_table[i][1]); > if (ret < 0) >