Received: by 2002:a05:7412:40d:b0:e2:908c:2ebd with SMTP id 13csp275393rdf; Tue, 21 Nov 2023 02:19:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IE7o2SAyM7sz/DFOKxDw2tleAe26X+GMlgS6vsnv8yRmTto3BWM3S7RT1JJsSeK2Ahz5tI/ X-Received: by 2002:a17:90b:3886:b0:283:2932:e912 with SMTP id mu6-20020a17090b388600b002832932e912mr11801586pjb.28.1700561965563; Tue, 21 Nov 2023 02:19:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700561965; cv=none; d=google.com; s=arc-20160816; b=yg0gNOKhTmncd/FOBFb93nyqLniPu+cu6PgvBG9YggW5Toa23Zz6z2UIW7OSv18/Ps 0dkkxjusdUOxAZ/zdVBM5eXSSd6Gb6mHvOhrrk9NpdWhoMVt5gaxsGrG1Ww1wbVDxZn7 wu4Ji8cc7mZMw14gn6g1Cfmyh+my7m9d8yMHv3h8JiVeZh+sUOLvfdMHwZ7zPFqb4wla TZDk+iov3WNfe4WcNj7ncSEVdr+mCoCmGNyYeQaLv4z9NgwfRlIyRnBuhxwzFx3Ti+f0 iu7VVTReCGkfcvptC64M24kVX+JAuDVC/EXUWa4pL2fXhmVyKkZopC8JnKgQdUAoaIDF aERQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:reply-to:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=mPCkF8r2gjDEwjA2exXfcObrLZoc5dRWaBYNS8IwX7w=; fh=phDggtdq/mZScnogaJFJfeRDE2XPpZpUuxL35p15uks=; b=D5q+nraKMVA3MqYsHIDJfmRx+L+VW93s0Yx7hxVvcOu3iUeRi3WpbWztsn46ApOPuz 5bJ8zozjXm+DfWHQp/3LxLv/AIE/qO0iCoJGqR9uPcF4jD2sg3cPiu9wscI58uDECr0d dPX11p3kg8nLstmfjSIoWvbm7o9cjEewy/Pag/COK2hC202cLPYTLWzgrhc7wk6cIiql 6LcVR9zheIjSwXLl5HKAew4otP3AejSdTK1iL9604qTbEaWZ7SAwSy8ZYaQCUVWM8KVC LnU+Z991Ew+Y3pbn4F1qjBTO5L9615wxUX1dxQ2NKgVnC9tCAanoMlKW4MTHQ9XtxFTI eDeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=eM9cxBHG; 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 pt18-20020a17090b3d1200b0028511e48364si6771897pjb.176.2023.11.21.02.19.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 02:19:25 -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=eM9cxBHG; 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 CFEB2810439D; Tue, 21 Nov 2023 02:17:46 -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 S233680AbjKUKRn (ORCPT + 99 others); Tue, 21 Nov 2023 05:17:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232875AbjKUKRY (ORCPT ); Tue, 21 Nov 2023 05:17:24 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1250011C for ; Tue, 21 Nov 2023 02:17:21 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPS id 756A9C433CD; Tue, 21 Nov 2023 10:17:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700561839; bh=0BvXHNAq6MxvTFFypFKVLfm202ysR+MbTta68aDgcfw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=eM9cxBHG3fTojuudhsxbw1lZ7Gau0JELf/VvK07u5vpOTcme0gJ4xu+Itj8nCrBSS pQ69EQgUShyyhjHqyvtNK2fVLPjWzmn3347UIdDPX5pmrsJ9BNyBTiTtY5sWz3020C 1pF2EKHPSBIM7uYjXbgTbtpIiVU8tqs+yJIhruao5qJns1oBXNxyzQgSuqsAuc5rj5 j/4tC4i/BSgLYG/bNh5GL4Lb/bNJZgxQBh9frk9hEv1o+hRZ74LtQrT9pUsmM0NKwJ Mddy82xhpqFXPLV5KIcEOMEJ6uUrRPtQ/JJQjqjP0EiQQXm3lH0T31LaKT20IKzTiv Rj83/7XWraOOw== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 63334C61D92; Tue, 21 Nov 2023 10:17:19 +0000 (UTC) From: Nuno Sa via B4 Relay Date: Tue, 21 Nov 2023 11:20:19 +0100 Subject: [PATCH 06/12] iio: adc: ad9467: add mutex to struct ad9467_state MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20231121-dev-iio-backend-v1-6-6a3d542eba35@analog.com> References: <20231121-dev-iio-backend-v1-0-6a3d542eba35@analog.com> In-Reply-To: <20231121-dev-iio-backend-v1-0-6a3d542eba35@analog.com> To: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-iio@vger.kernel.org Cc: Olivier MOYSAN , Greg Kroah-Hartman , "Rafael J. Wysocki" , Rob Herring , Frank Rowand , Jonathan Cameron , Lars-Peter Clausen , Michael Hennerich , Nuno Sa X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1700562016; l=1622; i=nuno.sa@analog.com; s=20231116; h=from:subject:message-id; bh=g3tcVMAWnAaNpfd4zR0L8lXR29z5KekLRZe6sxMF/hk=; b=c73pLlPBK+gRvwbzpMIaQzg2/RJK0F0Puv/XvfzcIUdIwAgeIeOujPcKeq6HBext2kU07mya6 y+9u9e194XEB1j4VRHh9o3JjEgyQO25ay/PCBtt95QyHrc9TUVacvKt X-Developer-Key: i=nuno.sa@analog.com; a=ed25519; pk=3NQwYA013OUYZsmDFBf8rmyyr5iQlxV/9H4/Df83o1E= X-Endpoint-Received: by B4 Relay for nuno.sa@analog.com/20231116 with auth_id=100 X-Original-From: Nuno Sa Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,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]); Tue, 21 Nov 2023 02:17:47 -0800 (PST) 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 */ + 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) -- 2.42.1