Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp2779803rdb; Mon, 4 Dec 2023 07:21:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IGxQJ1YyKxiZ+kMYBKw3M3cb+0xvriXoPwqu/O8tpokFPCVBH7/q4gsb/dxqfzwCUG5Jkyn X-Received: by 2002:a17:90a:ac14:b0:286:6cc1:8654 with SMTP id o20-20020a17090aac1400b002866cc18654mr1912508pjq.57.1701703301141; Mon, 04 Dec 2023 07:21:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701703301; cv=none; d=google.com; s=arc-20160816; b=GUz5dRYhULGIa0dCom1O3K3eBINl9Jo2rCbNK5IVPuvh9YRGTpVmX+LTY1j/x8WH+y xYoqHBs0sn+/I9GKYsEbgJeRRkTcrre1vAGytidNEBFo0Pr7uDv8o8NX+l6xdoH8CXYJ V7t4vsayMrvKEglnlwzLCU6HjYcqQVpVt+hCXobsjVqgRfLnqIZrhgcdx/PaVVsYwy4a xAeodl311yzPofKVBfIAe5NYO3GbrGE82rhnbIgM+ZCoJYHV+CM4BC+vHtSvyZ56LSjO oow3PU7VFTQSWFYA0eX5ssGg/XZDE8bUH3FzDulKrDrv1qL+qM5TMHuicrcuBNhSVfY9 wMTQ== 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=Fht2AW6a96aXbFgmupEK2f5l6PGOMUUmPB3H6j/7pDU=; fh=sqieTvBxhfIVwhknj5TTCKn6UI71QdImv9DAT3Xqv4g=; b=lLgeOYFl+hh2PZY3OZMP25eYua0wGH+ZsRI6x13QDUYVjf4O3hOima8VP61Dh8NxCp AxiFo35YD32w61AyfI+3Fl+NUjB/eBNoIfguAVik7B6SHi3xXwbS1MCbio0RDyjZM45o IYp+ZfgaxbOZeVqNfZxKTmwlfjUP3Xl6ZmnyoM6P+aHjD0ZIQZ0nCgAHkCXC+PBlXUwL EuzGSzXfiJu4e3v5iyX7q/v+bSR96BPvNSNu6Sof6s961SeOfS5RcMrXEa4fQcxlLNRW 2cUAc5uWX8vbdYPl7XSmEqnE9kIjBHyd0X/GMcbQN2qZqBoj6818lH3v+ZxTE5+TXixm kBrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lDy1RVFr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id x4-20020a17090a970400b002868b9efd49si3020344pjo.36.2023.12.04.07.21.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 07:21:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lDy1RVFr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (Postfix) with ESMTP id 13BA9805793B; Mon, 4 Dec 2023 07:21:38 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234239AbjLDPVX (ORCPT + 99 others); Mon, 4 Dec 2023 10:21:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233714AbjLDPVW (ORCPT ); Mon, 4 Dec 2023 10:21:22 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B5BACA for ; Mon, 4 Dec 2023 07:21:28 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 403E4C433C8; Mon, 4 Dec 2023 15:21:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701703288; bh=73pAaB3mi7c07UkmN0pF09RndH2hCE1ns/C5OrUjhHE=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=lDy1RVFrrYKs9mpINAj6ruU5nicvceF9qfesxbreDv5Ot6A8bB6AK6xSR5dYq2e4V ryMyekOp1QWlMK+tgSDcGtOzFjHky1bvbW1VptgSzUvhGji5mWOxi1S8YAPoNnFaGr 21Xv8Qp1rjs/XzgGDfw9BlE5GxAOwjogqRyZ+wHya6eF6X5M84pkRmQoSyfX1i65nP 7QwKx89Vty9oTA4m9+pi/UBmUQ6dOWgASAwVaxLPpBPBZJ3th+8vTY5q3B3oPkU+yk KzBx5WKDx2m1dy5FfO8xIlqkP1XW+XM5uMQDKTkg6hA8RNADLExl7fnrqwTPxXFCri boSYoVFptp4cA== Date: Mon, 4 Dec 2023 15:21:20 +0000 From: Jonathan Cameron To: Nuno =?UTF-8?B?U8Oh?= Cc: David Lechner , nuno.sa@analog.com, 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: <20231204152120.71455f40@jic23-huawei> In-Reply-To: <2343dacb0ec0a4878c8e41748ed6e586ff53ccd4.camel@gmail.com> References: <20231121-dev-iio-backend-v1-0-6a3d542eba35@analog.com> <20231121-dev-iio-backend-v1-6-6a3d542eba35@analog.com> <2343dacb0ec0a4878c8e41748ed6e586ff53ccd4.camel@gmail.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=UTF-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 pete.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 (pete.vger.email [0.0.0.0]); Mon, 04 Dec 2023 07:21:38 -0800 (PST) On Fri, 01 Dec 2023 09:49:38 +0100 Nuno S=C3=A1 wrote: > On Thu, 2023-11-30 at 15:50 -0600, David Lechner wrote: > > On Tue, Nov 21, 2023 at 4:17=E2=80=AFAM Nuno Sa via B4 Relay > > wrote: =20 > > >=20 > > > From: Nuno Sa > > >=20 > > > 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. > > >=20 > > > Fixes: ad6797120238 ("iio: adc: ad9467: add support AD9467 ADC") > > > Signed-off-by: Nuno Sa > > > --- > > > =C2=A0drivers/iio/adc/ad9467.c | 6 +++++- > > > =C2=A01 file changed, 5 insertions(+), 1 deletion(-) > > >=20 > > > 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 @@ > > > =C2=A0 * > > > =C2=A0 * Copyright 2012-2020 Analog Devices Inc. > > > =C2=A0 */ > > > - > > > +#include > > > =C2=A0#include > > > =C2=A0#include =20 > >=20 > > Ah, the case of the misplaced header from the previous patch is solved.= :-) > > =20 >=20 > Yeps, it needs to be in this patch :) >=20 > > > =C2=A0#include > > > @@ -122,6 +122,8 @@ struct ad9467_state { > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 unsigned int=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 output_mode; > > >=20 > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 struct gpio_desc=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0 *pwrdown_gpio; > > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 /* protect against concurrent a= ccesses to the device */ > > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 struct mutex=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 lock; > > > =C2=A0}; > > >=20 > > > =C2=A0static int ad9467_spi_read(struct spi_device *spi, unsigned int= reg) > > > @@ -162,6 +164,7 @@ static int ad9467_reg_access(struct adi_axi_adc_c= onv *conv, > > > unsigned int reg, > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 int ret; > > >=20 > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (!readval) { > > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 guard(mutex)(&st->lock); > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 ret =3D ad9467_spi_write(spi, reg, writeval); > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 if (ret) > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 retur= n ret; > > > @@ -310,6 +313,7 @@ static int ad9467_set_scale(struct adi_axi_adc_co= nv *conv, > > > int val, int val2) > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 if (scale_val[0] !=3D val || scale_val[1] !=3D val2) > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 conti= nue; > > >=20 > > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 guard(mutex)(&st->lock); > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 ret =3D ad9467_spi_write(st->spi, AN877_ADC_REG_VREF, > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0 info->scale_table[i][1]); > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 if (ret < 0) > > >=20 > > > -- > > > 2.42.1 > > >=20 > > > =20 > >=20 > > Alternately, this could probably be solved with spi_bus_lock/unlock > > and spi_sync_locked rather than introducing a new mutex. =20 >=20 > Hmm, typically you just have your own lock. No reason to lock the spi bus= . And I also > have some plans to eventually change this to regmap :) Bus lock typically implies that we can't let other users grab the bus in be= tween for reasons like the chip select needing to be held. I'm not keen on it bei= ng used if the locking is just needed for a specific driver to deal with its associated device and driver state. Jonathan >=20 > - Nuno S=C3=A1 >=20