Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp625819rdb; Thu, 30 Nov 2023 13:51:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IFTPgvDs9+fQIemFA5ssq1ttcVTYNeB8rkC8SW8aTebKbgS3noFJs8GF6Iq9kE4dnZvrabG X-Received: by 2002:a17:902:c40d:b0:1ce:33b2:a1e0 with SMTP id k13-20020a170902c40d00b001ce33b2a1e0mr29105048plk.33.1701381069126; Thu, 30 Nov 2023 13:51:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701381069; cv=none; d=google.com; s=arc-20160816; b=Tg//YiSYOqfLeey9eFSbauCYgPIdyGHQQTA1wWY0msxPmzTTkRPmx+B7C07NCv8b0B y5nECd7h+aI6Cimn5TiNMIoFC89EI2SP2SA9M7P5XjZG5WLRlgj77qeZflrRTh7FEoW9 XsAhHxcc5aBSWyV6J/E0EwCizJLp0r2sElFscuNWpFQlPMvgsdOIO2EHbfTh8uJqQj1p ZaH2uoaSsa0TAya1mqhsB8QE26qOY/K0B+GwDSSEsSPf0hv2V9R0j7CTDUVtkwd7i0uu lI73ErCWRktCzJeOx0y8ZsbXV5w7h6eJqE2nDPufAEh2nhXq61ttebDy8N9kqsnwBJB0 CXBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=aANyBr2T0t8LeKYSkonqHHH3ddTbNb3vuWdQ0g12q+Q=; fh=ttWv8VCoGF50n4AB/K9MI+yMSg75NE7RBe49baFg6DU=; b=CyzXuSmeDafWYKqaVlQyaX7UuCCouuVyj2ZEDWVnEvGWkScqdYpTtq/rlTIXAjHaUt LOZWREP9O7XZfCRHe4Ukwx8/SZp/2HgB+4ItICNW3PcikGnj2+V5i+tRF78Dl5AY45h7 Jx/jzuUG6JaQ6WCggXJ1I+DVJfeBrW4IXFvniHDGaVnRHPSU96pbFvDBvvOK1klKTn+o SVg1wanm86YiWGetmDu9uoa817GR6C3z6UbQmAoRBFzv8I8WSuMz2Cy6WTHv7v1eB2+Z ZvXwsj2rC4D17lkhv6E0KMGTuI0koAElamB7XkHrUkGwmIRw5ttRKL1+1xJxxcfZit6f F5Iw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=wPqbnp5q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id p1-20020a170902e74100b001d04d395a5dsi484867plf.484.2023.11.30.13.51.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 13:51:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=wPqbnp5q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 99C5A8029A99; Thu, 30 Nov 2023 13:51:06 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376987AbjK3Vux (ORCPT + 99 others); Thu, 30 Nov 2023 16:50:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232317AbjK3Vuw (ORCPT ); Thu, 30 Nov 2023 16:50:52 -0500 Received: from mail-lj1-x232.google.com (mail-lj1-x232.google.com [IPv6:2a00:1450:4864:20::232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 933C510F8 for ; Thu, 30 Nov 2023 13:50:58 -0800 (PST) Received: by mail-lj1-x232.google.com with SMTP id 38308e7fff4ca-2c9bbb30c34so18137991fa.1 for ; Thu, 30 Nov 2023 13:50:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1701381057; x=1701985857; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=aANyBr2T0t8LeKYSkonqHHH3ddTbNb3vuWdQ0g12q+Q=; b=wPqbnp5qRtfp082LnkkE85atm3ai15hClOrgxH6TPBNETyZNCpcH/qjtLUfN7cQKtI bMTA0rqlEolb32uyNkz1HxvbutaB6wTKhJCOGnzKhRi4UewsaSh/QM/8sAHq38spLDzT KLoSUBpSmdV1eJgKTqeAz1Gzps830CBLFa2rMRRgDk/rjfINktB0nKMr8Gx8uRM72f/4 BukNYUQV/kZJRv8+XUYZ/GR3DkLp/+QQZymLbG/bWxIxe/gJSguC/9/mr6WVJO34LClf G8h6xe7nP6ufrCRt3DWIoG52TC7gVCNhPKji9sTmZXB9szz4BnJjER6fF2GPRjdSFCzc ID4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701381057; x=1701985857; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aANyBr2T0t8LeKYSkonqHHH3ddTbNb3vuWdQ0g12q+Q=; b=OnIapn3LcI6OfWa13bspgAqOLwndZamDYaaVGT1i4CCOKrT2bMDABdnode85cXqFZI VoY9VlDj9oszBJeEj0AG9wDwjPxunnIcpXff2DmEZyrs4GgPTAE5AcRZ8iGQFPT2y++n rg7aTCP9f5w+mYp2fYzIkAEDDZR5kYYleUAkqOCBiQt4WdmTUFTy6K+ksd2EILfaUcw+ f7BBK5Uw+5/JxaHHb/NtDn9LE+OoXEFzM2YOtroINQm+PPb24Xbc3RsxlN7h1/QEUHoX T86msXdGAtHcn9AP2HHVw2I29kzlgbUY/fL+Q48h2glT5cDiYDp/RQmiJ3k5CSBt685C KFLA== X-Gm-Message-State: AOJu0YwSGeoLA6qSRV/SSLk0B1MRGnTgddNonpiW2wzkBdOncuxX2uNT ofWFqk3/OcH0zGwVVzdH71Xt1XlFyWxrq4NhSzhr3A== X-Received: by 2002:a2e:8503:0:b0:2c9:bacc:1285 with SMTP id j3-20020a2e8503000000b002c9bacc1285mr117766lji.47.1701381056908; Thu, 30 Nov 2023 13:50:56 -0800 (PST) MIME-Version: 1.0 References: <20231121-dev-iio-backend-v1-0-6a3d542eba35@analog.com> <20231121-dev-iio-backend-v1-6-6a3d542eba35@analog.com> In-Reply-To: <20231121-dev-iio-backend-v1-6-6a3d542eba35@analog.com> From: David Lechner Date: Thu, 30 Nov 2023 15:50:46 -0600 Message-ID: Subject: Re: [PATCH 06/12] iio: adc: ad9467: add mutex to struct ad9467_state To: nuno.sa@analog.com 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 , Jonathan Cameron , Lars-Peter Clausen , Michael Hennerich Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email 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 (fry.vger.email [0.0.0.0]); Thu, 30 Nov 2023 13:51:06 -0800 (PST) On Tue, Nov 21, 2023 at 4:17=E2=80=AFAM 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 Ah, the case of the misplaced header from the previous patch is solved. :-) > #include > @@ -122,6 +122,8 @@ struct ad9467_state { > unsigned int output_mode; > > struct gpio_desc *pwrdown_gpio; > + /* protect against concurrent accesses to the 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 =3D 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] !=3D val || scale_val[1] !=3D val2) > continue; > > + guard(mutex)(&st->lock); > ret =3D ad9467_spi_write(st->spi, AN877_ADC_REG_VREF, > info->scale_table[i][1]); > if (ret < 0) > > -- > 2.42.1 > > Alternately, this could probably be solved with spi_bus_lock/unlock and spi_sync_locked rather than introducing a new mutex.