From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 10B8377F15; Tue, 23 Jan 2024 02:05:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705975529; cv=none; b=AxJxhPrZ3MXffKKSDvQXkbdAhrngVNDvA3dK0uOl2ytIo/tqgh5sSiH9weES19xxc16DhmmBBVpI18G7VkFOiAUAURrYUSA/84lRIfFcLfgh/raGRrXACjjq3ubwtSgrhWy/sJT3f9VnLsMAwI/PmmSY1SXp7FtTy1t7oMJnRfs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705975529; c=relaxed/simple; bh=ptyeE0mH8sK2KOXZM8c2jH0lLxZ9RGk0NlUHersFYJQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ummyiulte1MfDRqmnCyrQCF0N3iFy/ta8PJqsEyA/g0AdA8d0ltxISH5E+PTkAd6BIvclajsE5COE8ZRIif+LniavA5DAE/gC2xPWIrc7tckOmKXgbOD86XKOQaPLcCnpTBiv7V1wdm1VSgPLP94XBDf1UFUKXey03qM8tX38yI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=KlsvJ3Ii; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="KlsvJ3Ii" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8C5A4C433F1; Tue, 23 Jan 2024 02:05:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1705975528; bh=ptyeE0mH8sK2KOXZM8c2jH0lLxZ9RGk0NlUHersFYJQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KlsvJ3IiV8k++b4aP/NpT7E1Qsh4S/A+uEi4XZeRl7OxpoVNsKIqzGBUVa0g7bGRz sgTIylbc5M7TADgIUdVMLpHWnNzfaR0Bh9NrQ9icR4BePoxGz+ILSMlEIsFeoLIQZf 2+/6ibAt3Y3Sn9ktLAlHcWTDKCXO4Jh0lAVxo1bs= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Nuno Sa , David Lechner , Jonathan Cameron , Sasha Levin Subject: [PATCH 6.6 481/583] iio: adc: ad9467: add mutex to struct ad9467_state Date: Mon, 22 Jan 2024 15:58:52 -0800 Message-ID: <20240122235826.711900310@linuxfoundation.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240122235812.238724226@linuxfoundation.org> References: <20240122235812.238724226@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Nuno Sa [ Upstream commit 737720197be445bb9eec2986101e4a386e019337 ] 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 Reviewed-by: David Lechner Link: https://lore.kernel.org/r/20231207-iio-backend-prep-v2-3-a4a33bc4d70e@analog.com Signed-off-by: Jonathan Cameron Signed-off-by: Sasha Levin --- drivers/iio/adc/ad9467.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/iio/adc/ad9467.c b/drivers/iio/adc/ad9467.c index d3c98c4eccd3..104c6d394a3e 100644 --- a/drivers/iio/adc/ad9467.c +++ b/drivers/iio/adc/ad9467.c @@ -4,8 +4,9 @@ * * Copyright 2012-2020 Analog Devices Inc. */ - +#include #include +#include #include #include #include @@ -121,6 +122,8 @@ struct ad9467_state { unsigned int output_mode; struct gpio_desc *pwrdown_gpio; + /* ensure consistent state obtained on multiple related accesses */ + struct mutex lock; }; static int ad9467_spi_read(struct spi_device *spi, unsigned int reg) @@ -161,6 +164,7 @@ static int ad9467_reg_access(struct adi_axi_adc_conv *conv, unsigned int reg, int ret; if (readval == NULL) { + guard(mutex)(&st->lock); ret = ad9467_spi_write(spi, reg, writeval); if (ret) return ret; @@ -310,6 +314,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.43.0