From nobody Fri Sep 25 12:33:38 2026 Received: from mail-wm2-f12.google.com (mail-wm2-f12.google.com [74.125.225.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1B317376BCD for ; Sat, 12 Sep 2026 13:25:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.225.140 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789219554; cv=none; b=LENk6XcoJRUk68YlfLw5xlKgK0TmpRjV4jbicOq0zK8YyeuhX6B8cSHQ27PXxjiCyKQkB6BMQ8YOdrVijg3c+GyHXXNty5+Frax3BXMzm9frh9Q4r3qQ81tA9snj8SPr9ogFDL7oP9ZcTMbmERmvRO1u6mwJbpNqM+F2/ISJghs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789219554; c=relaxed/simple; bh=wFxXi8Z9WcIxFPd9fUaEH26jlrgztUaT4NJh8D572Es=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iOucwF5/jSVeUhIBz/uxFgkLZCKXW+38Kn7OKwxK/EWiuplNkitvxdCfm9BOv07JVhlc183vywtSx2Y+ZYDpmYX6m76zL2hlxNdBfp87dRUQEfPSS1e72L9CPteD7wJh17d0tSyzohlKXor8wXP9Ag850HWbc+A0SwUk4S8HIBs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=etBpPYNs; arc=none smtp.client-ip=74.125.225.140 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="etBpPYNs" Received: by mail-wm2-f12.google.com with SMTP id 5b1f17b1804b1-49e6598dd44so1630505e9.1 for ; Sat, 12 Sep 2026 06:25:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789219551; x=1789824351; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=PW1ixTgxWimSTTjdthxgReSlmPLPKmDhq2QrwAvzdaI=; b=etBpPYNsF/ubdtDNby7KvNJx4F4IVT3PgBg1+ROGg9f6I/4V8iNYgW/80tykxUlsx+ Is2mrQtMHaDIqXW/otcaB+DbECqTnmeZpBWr35EXK5k6XJhhe6DY2eZllCleCn08t/mA cgdIhgrVMAjrxXhxyQSMF4Z/ZOIyWY/BsKUtfJZC8G1V8VeOkYT0oNs4tjFmwM4/kFca IP1I6Rq4NwrkoOvP6t6Ryb/zqZG3NUyHJhkm+f8tIrr+QULvX536+uFY1y9N5ly4qYyO EZjplgXbMH/R9+T/TuYb0wdFvkBRZqy1aiwRBdyNE9NjBr/Fkgy2+QXap75oGDw4lxOi cy9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1789219551; x=1789824351; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=PW1ixTgxWimSTTjdthxgReSlmPLPKmDhq2QrwAvzdaI=; b=l0y9D7k12joiJbDa07pETYTHwwKyw2DZQoKLNes0DzD1sDkP07DjnDOd7KeQKaqwr3 aemVOukFlNkc6T371afDnv0apVZiPbYn7tFbYb9odRYSyJFv8M3gffIdNFldAdcF/6LC /fiOBTLmUCvdchhe6V8l73jnOwpqSF3EW85v8nF7X+oAim8dp552onOMnphVAqeJyoR2 PsLc0/935TWPAsoLxD18W7ahyzGaPHTRuW3+kdshhd102Dq3zXlsTkFTVSdLfxVhI6Fe pE/ooupHytgk/R/BKgaOESZHiZKA5VQ1vcgFo2RMM28SmVwLkjYrBLLB+N8Nekmj1L1D PntQ== X-Forwarded-Encrypted: i=1; AKwUvBzqD3URo0j9dcaOKipnQ9Nb1wOmq1isONmp31RRvdohd4aJBDG6u0otOBlqEfIVcpc5kZKbAgEAChOO5wU=@vger.kernel.org X-Gm-Message-State: AFuF++nhczBdHlSVpgvJVi7FtwaJkeqEDMzYmggnL5FNe+7tzhPvY3hc SMH1MFnsUNLz7Rh9JFkjcfwtZ2mYRXT1cBX4M8uyD+Fe22N/JxSiDApIXhjm9w== X-Gm-Gg: AYBFou2wlUe0JYlYVkkBxS+LFuvhLinwWwNG5fCIa/qP8ViEOoHLmdEl7HIxk+Bm5dQ eC8svQ0Q3begMOxMLr3BF9Tj+95BjQvtBWQKiTfGTw0vMUZ1jPX0W69IKw6s0kI+uvHtkDySpv5 h+esh6ylxzT1ORzTQyprWQAqI2wkmuWx3pqV+ZdecZGQNAAXuVn7Goj6fkFzwkHq0z3a9/EUJsD O1ohqMxp6YzhsEwMUiVmxqOtzESbW2x719Xz0sqzxjl58wV4y1gXCDNDm0RAohwxb19vgZDbtag FWBwJpectrQw2ahNdWgXIKg7BOvauAGQkUqflvIko/0Jke79YQNEyCsTYy8g1GiBNSqhAtwUqET QDw/QA6/4TEWuivNP6eopzy5jYi1tp98HlU7KDKu2MSl91qnwSMbCPwHOUev/AIg7cAKBt4v9Cs u0Mc0NHwT28qTHXQ2gdyghTlMxReOQ67ol/5k3FbPqnnrmBI8qd3w8f9KPwN02tRtZlHYEF0tNs RRMfGrvV7lQSQrrwA== X-Received: by 2002:a05:600c:19c9:b0:49e:6683:d23c with SMTP id 5b1f17b1804b1-49e6ca4003cmr24788655e9.0.1789219551327; Sat, 12 Sep 2026 06:25:51 -0700 (PDT) Received: from fedora ([154.182.88.3]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-486eb33ee8bsm12684503f8f.15.2026.09.12.06.25.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 12 Sep 2026 06:25:50 -0700 (PDT) From: Abdelnasser Hussein To: jic23@kernel.org, gregkh@linuxfoundation.org, nuno.sa@analog.com, Michael.Hennerich@analog.com Cc: dlechner@baylibre.com, andy@kernel.org, linux@analog.com, linux-iio@vger.kernel.org, linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org, joshua.crofts1@gmail.com, Abdelnasser Hussein Subject: [PATCH v6 1/3] staging: iio: adc: ad7816: Sort headers alphabetically Date: Sat, 12 Sep 2026 16:25:15 +0300 Message-ID: <20260912132517.55686-2-abdelnasserhussein11@gmail.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260912132517.55686-1-abdelnasserhussein11@gmail.com> References: <20260912132517.55686-1-abdelnasserhussein11@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Sort the include directives alphabetically to improve readability and maintainability. This is a precursor cleanup patch to prepare for the addition of new headers in subsequent changes. Signed-off-by: Abdelnasser Hussein --- drivers/staging/iio/adc/ad7816.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/staging/iio/adc/ad7816.c b/drivers/staging/iio/adc/ad7= 816.c index 30644d2d7c54..9e43ce83e071 100644 --- a/drivers/staging/iio/adc/ad7816.c +++ b/drivers/staging/iio/adc/ad7816.c @@ -5,19 +5,19 @@ * Copyright 2010 Analog Devices Inc. */ =20 -#include -#include #include +#include +#include #include -#include -#include #include -#include #include +#include +#include +#include =20 +#include #include #include -#include =20 /* * AD7816 config masks --=20 2.54.0 From nobody Fri Sep 25 12:33:38 2026 Received: from mail-wr2-f12.google.com (mail-wr2-f12.google.com [74.125.225.76]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2AB5B47D95E for ; Sat, 12 Sep 2026 13:26:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.225.76 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789219564; cv=none; b=R16SDKAVxUWRGlKJc/CSj8hbW4Y39oqCY8YTyVUQlUGXeq1sC2e3l7Kwb0hMomkgCG+4VZluInMSo8KnmC+GCSFblyU3rYKB5KQ8KxXMKkvxUokfKjBILKWWsQIsonW5Vv56lA/nIK2l1sy6Lztpf66gTNLXnIpB+6dfBuIGuuQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789219564; c=relaxed/simple; bh=B82+6jWVF+uGKYVaZQYTIbzC69mj2Z9dpEdSNIoCiio=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UlEjrtV5hvgcQurHjzfzbbz6Y9ZndMfTk4RzoprHvQ1SxljE682IAIGIj0IZg33UDYyZiiOUpIqUFr+m3zIgC1J/ZJmBl7kq4v/76jf5qDBmHfw92SImvvldpPB0m20fDqa4tKLV9F21AR+ntiwtudkQrFO/bOakyyt18mBeapU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=TiSnupCS; arc=none smtp.client-ip=74.125.225.76 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="TiSnupCS" Received: by mail-wr2-f12.google.com with SMTP id ffacd0b85a97d-4843378fb37so205537f8f.3 for ; Sat, 12 Sep 2026 06:26:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789219560; x=1789824360; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=BQ4thKSalDZM2rC8wC0NqTstNC8+R0mxz6pCgagXex4=; b=TiSnupCS68OFMTXkq/3G4FXjie3Gf7f5F6lBMBhOpCr9no/jKVqyx2FXvG6lOmTet2 q5MMOinX7dukLo1uEnUaB4Nc8GAF+wURehZ9gj8IrGauBfUjBn5H8F26Yk2I0+iVT0jS yhNXNPl4ohWC4uYHbY50SBxQgURVf9nIeJJ2FGrUr44s1NnfYzOAO2eKYrC74y2a8H6a SwqtRCDFeLlOkjgdbwGQQWtpTNRvRnaT3ZEMUb3KgSziMEz2iOACNVnPrAGYHbsWEqAk 899kaDQ7SXFNLNYQC0IcoYnCU4cK0nlO3xXdsUK8WoEesSXxYQffE2v3CJZwcB/DbNlr JO+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1789219560; x=1789824360; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=BQ4thKSalDZM2rC8wC0NqTstNC8+R0mxz6pCgagXex4=; b=Jla0RuX7DcSl1cNaeHVoLYyJeRLuHNiBFmU7NOB8VRG0ja1e5ruhbOthuMXaFKMc+x k2htLjwao3AwS2bkyhXjqLTDwUCBDDUPDSRekiyNR6T8z+ol8rtQwpa+8pOvQuyDWQNl g6/fW6t6gq5HSuyTsA1oK2CcLc+1iKXNJ1cGWpMMwvLBihMPudOrCmU2mqAwKlveseY2 0LNTyPkTMelx/TM4lBVx6/J8n/128V5DYCpBBphbWvEWZaCEnPdR1xpi/BPdqlA2vQJx r/szjNh7NcThHRsbeASAtegZBJIZymLkPRKBk2OvKbZbakF9+H7tx+gP/1+RFgxLUbN3 A63Q== X-Forwarded-Encrypted: i=1; AKwUvBzuwmYTP5iSZ15Ly9UT5AnklwadRpqFXAaqwykferP2CoUNBlJow1yGXayLIo5Jq9dYFXyWo+L1O4TBZXM=@vger.kernel.org X-Gm-Message-State: AFuF++lWzdj+MdY2ZXfLb1aLLMvSuwD1iWy4kHTAyNN4+fr+UTZRsQTp +ABzNaDUKMtICJwJRTim1I1uUrKJzZjYzb0H0zF81d2gkdGmz+6ZXmRF X-Gm-Gg: AYBFou3Q/9+q1WNEK1a1tIWL7l8J40XxjKR5XKnlRh5yeVOTYNrQfnDcUcFvaUO4ZGJ gTkGEbfWg5WP5Dkpc6CWqOI0TFVRPet1PNQIfcwY1Eq3IKh1cqpyWsZXrpGVmcNZXryQT8Nga/o WreQOdEk8NbPNVRe0hAPBU2QAuVeveghiQ4+WBtbDlOQNSC2ioO2ypuBssZsGVqOSLYQVlEm4GY 1j5I2/TTkg1uzJtjEug1AR6N4xveqsVBl+zxNwjZXiyYztJx3z38x0m8jjdL9JBV4uCtopiI7AY JEAS92YG7k7TTl52zWPLMuWEbQO9BOwOJ14273Daq1LzNqFEsJqEfYJ/7BV8vl2jb/HKHUCwsAi AbvPdfuNvhJcyKK0kEOjXRcwO1YluyLMV6dvGOPXhwy+qOmOXsu5zoD7yzrowlyHZpj4OviY/xe T9SLcy5Tp5zL/p4LAqri4ShcaHiTnzpdLCe4CteV93QMs4iA9En/EAnazFoLoYO8Eehdl2U8NG2 zl1AApLsWHSa8ioyA== X-Received: by 2002:a05:6000:5c8:b0:486:f301:1144 with SMTP id ffacd0b85a97d-486f6beaa59mr2718066f8f.2.1789219560279; Sat, 12 Sep 2026 06:26:00 -0700 (PDT) Received: from fedora ([154.182.88.3]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-486eb33ee8bsm12684503f8f.15.2026.09.12.06.25.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 12 Sep 2026 06:25:59 -0700 (PDT) From: Abdelnasser Hussein To: jic23@kernel.org, gregkh@linuxfoundation.org, nuno.sa@analog.com, Michael.Hennerich@analog.com Cc: dlechner@baylibre.com, andy@kernel.org, linux@analog.com, linux-iio@vger.kernel.org, linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org, joshua.crofts1@gmail.com, Abdelnasser Hussein Subject: [PATCH v6 2/3] staging: iio: adc: ad7816: Serialize SPI read operations Date: Sat, 12 Sep 2026 16:25:16 +0300 Message-ID: <20260912132517.55686-3-abdelnasserhussein11@gmail.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260912132517.55686-1-abdelnasserhussein11@gmail.com> References: <20260912132517.55686-1-abdelnasserhussein11@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The ad7816_spi_read() function performs a sequence of GPIO state changes followed by an SPI transfer. If multiple read operations occur simultaneously, the GPIO state could be changed by one thread while another is in the middle of a read. This leads to a race condition where the sensor state is disrupted. Introduce a mutex to serialize the read sequence, ensuring that the GPIO toggling and the SPI transfer are treated as a single atomic operation. Signed-off-by: Abdelnasser Hussein --- drivers/staging/iio/adc/ad7816.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/staging/iio/adc/ad7816.c b/drivers/staging/iio/adc/ad7= 816.c index 9e43ce83e071..acf26c5a267a 100644 --- a/drivers/staging/iio/adc/ad7816.c +++ b/drivers/staging/iio/adc/ad7816.c @@ -5,12 +5,14 @@ * Copyright 2010 Analog Devices Inc. */ =20 +#include #include #include #include #include #include #include +#include #include #include #include @@ -50,6 +52,7 @@ struct ad7816_chip_info { u8 oti_data[AD7816_CS_MAX + 1]; u8 channel_id; /* 0 always be temperature */ u8 mode; + struct mutex lock; /* protect device state during SPI transfers */ }; =20 enum ad7816_type { @@ -67,6 +70,8 @@ static int ad7816_spi_read(struct ad7816_chip_info *chip,= u16 *data) int ret; __be16 buf; =20 + guard(mutex)(&chip->lock); + gpiod_set_value(chip->rdwr_pin, 1); gpiod_set_value(chip->rdwr_pin, 0); ret =3D spi_write(spi_dev, &chip->channel_id, sizeof(chip->channel_id)); @@ -360,6 +365,10 @@ static int ad7816_probe(struct spi_device *spi_dev) return -ENOMEM; chip =3D iio_priv(indio_dev); =20 + ret =3D devm_mutex_init(&spi_dev->dev, &chip->lock); + if (ret) + return ret; + chip->spi_dev =3D spi_dev; for (i =3D 0; i <=3D AD7816_CS_MAX; i++) chip->oti_data[i] =3D 203; --=20 2.54.0 From nobody Fri Sep 25 12:33:38 2026 Received: from mail-wr2-f12.google.com (mail-wr2-f12.google.com [74.125.225.76]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9F2F247DD4A for ; Sat, 12 Sep 2026 13:26:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.225.76 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789219572; cv=none; b=EnE1nWpniC4iuPljtTn71yGmb81R0f8xtGGWgj3e28pDNcOMZ+DbxwiwkX4HoW//TX5xkT1fH1Z44zxXYDWBvJiQU3r1DbcNzWl1XfJfCzyL58YzAJt9UOhrDxqivv7W8Jg1goauaGHkttUWhYsv3E6QXWhsaWQ394OutO40t0s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789219572; c=relaxed/simple; bh=7CE8YwlilBd1VM+J4eCukboYD8vi5XXt1Ru2qxPspMI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kVX2kpljklw8SAQjHtB6a/pHUmZvGRFs2DHjkypWwaKvO5Gk8MJgT6H9a4f8iQKGgJ6hR5w3axac3LiZEN5s584YJghlW2WuF/NTkWQ2kyXh64dMwkA/1mo+ipyzLbFCb6V0p/cFkRJGjBPPPf0S0nwF22tSpRk4fl0KxJV7yjs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=QsSPNRXH; arc=none smtp.client-ip=74.125.225.76 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QsSPNRXH" Received: by mail-wr2-f12.google.com with SMTP id ffacd0b85a97d-482f6356f6bso554973f8f.2 for ; Sat, 12 Sep 2026 06:26:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789219569; x=1789824369; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=gF6cpu2FDuNRXYtVifufQ0jbLZ5i7EeoWxGFjWtrGA4=; b=QsSPNRXHO3sNcUQcvzjcsDydz/thwet6ipyU+WsKG9HetIrkV1U+5XXooO5xyRSl+G 6H5WJG65U39D84va9vfQ7BvzDkLft3gvSQLGE6yqzk0R096L7s1xWcFmKEUYkKS+7ySM fhfnknkzC0+ZU3bka8d4cI7m9De9YA8m1iSYcNjlW+xf+95+4wB5tuT4Lyebw+E6CwEg W2Ru7o7tVVH0hOlRh2C4QD/cvamqWZGqwj95EItZjW739xlL1Em+6Zzx1KJbxhLs7HwI lsgLXZUc5ggpdmJ5sQz/AtAhg1lGOExmw9rduRa5eEwhv9CFrSvl9CPuU3TJrQlfB06t tiQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1789219569; x=1789824369; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=gF6cpu2FDuNRXYtVifufQ0jbLZ5i7EeoWxGFjWtrGA4=; b=C9XJi+t3jX1SJYBtJmEE8IXHXmU0pdDeYtA7S9mu/bOD8Qfnfi41Zsms8Exn/Qie8G o09ldvvsayfpca81nS4Vh/Oq+02WbC4L6v3deX+8rvGSuanbu1Cydp2zBSjbef/ZPdik 35JHCtBP3VIyI3U0cdjtzQ+dhS7tEVmMZT56Io/I82ORPcMOCLBvq8CdOrzjRwf8AZna 6bYlN5HD4i3R4gl9NFRMcR5px33JUre/6dI7WTj/4A5FY5x7pYCWphWWfI29h36vTiOL /4en0bOBAV6kms3sVlbxDwTigr7vnZbnH3LSBO/h5feDm8/Gy/LdNIs+UpSLFxoSDMW6 sZwQ== X-Forwarded-Encrypted: i=1; AKwUvBwjU/KeneDr6OsyUE6Su9ZLeQR94MwShMEqlktoH367riQc1yroDGoQuLM9IKHOJhj4VhgOsor+ANS3tMI=@vger.kernel.org X-Gm-Message-State: AFuF++kO47kLP8v3aJ899ceLQfYus8NvX1/45rjrRmruFZzdF4jLjfmS sFK+cgYaBK5FWvE1bxxsSRlJQ0GHysYGudOgRTd9lldo44eVUm86Tya0 X-Gm-Gg: AYBFou0mv1B1UntnpfPfObv0Wj7uDr6n1V0Tv+ZUpuNWuqdMG4XYwBW3o0NSRJkRXDi HlaSK7Z68f1afChxbLW28mMCL2cHp2p3l8qiztKXFOw+2o6PLODM+JIt8/qC5S+CVgCGEMyXN3G DUODJ6rEl46RzkgO1d8rFzagLyRwLQnlKlaN+apgWtaTg2ZJ908Z1rwRlxCY/Z4AmziInrQjWdZ Y8823+lQBVzTkdKaqnwQ5DPhrMCjyMYwZDkQ/yoNKHMMyn9xLFzj9mMSm4YW/+qvbSv6CazW1en GfVH0ZV0id5ag5uWRCFlG4ZqxEph/ijXYMY8NzbSwufpRDRRS+bdTNPgN84pcs5tPOduh6ho9wm YffnJsNi2H2aXk+SfFEzVbcZ3RWS2k/yeUR05Z14hhjTtmZOMosghtE0oVQs0M2DvR9Z1xW7Lm5 O+R+TTMRKB4qVviEWsCvJQ/XrpPG7FETHDnoLQGj4eQun/HcEFqoU/KiVnx/ZiP81Jqyj4nHT8t oRIbY39Nm8tR/98p32MjMENqxrh X-Received: by 2002:adf:f9d2:0:b0:486:e6a2:2d7c with SMTP id ffacd0b85a97d-486eb31b1ccmr15058844f8f.15.1789219568859; Sat, 12 Sep 2026 06:26:08 -0700 (PDT) Received: from fedora ([154.182.88.3]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-486eb33ee8bsm12684503f8f.15.2026.09.12.06.26.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 12 Sep 2026 06:26:08 -0700 (PDT) From: Abdelnasser Hussein To: jic23@kernel.org, gregkh@linuxfoundation.org, nuno.sa@analog.com, Michael.Hennerich@analog.com Cc: dlechner@baylibre.com, andy@kernel.org, linux@analog.com, linux-iio@vger.kernel.org, linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org, joshua.crofts1@gmail.com, Abdelnasser Hussein Subject: [PATCH v6 3/3] staging: iio: adc: ad7816: Use DMA-safe buffer for SPI read Date: Sat, 12 Sep 2026 16:25:17 +0300 Message-ID: <20260912132517.55686-4-abdelnasserhussein11@gmail.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260912132517.55686-1-abdelnasserhussein11@gmail.com> References: <20260912132517.55686-1-abdelnasserhussein11@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Stack buffers are unsafe for DMA with VMAP_STACK enabled because they are not physically contiguous and can share cache lines. This causes data corruption. Fix this by using a dedicated rx_buf aligned with IIO_DMA_MINALIGN in the device state structure to ensure cache coherency. This also corrects the size argument in spi_read() to match the new buffer. Fixes: 7024425db64a ("staging: iio: adc: new driver for AD7816 devices") Signed-off-by: Abdelnasser Hussein --- drivers/staging/iio/adc/ad7816.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/staging/iio/adc/ad7816.c b/drivers/staging/iio/adc/ad7= 816.c index acf26c5a267a..2fd2d6796603 100644 --- a/drivers/staging/iio/adc/ad7816.c +++ b/drivers/staging/iio/adc/ad7816.c @@ -53,6 +53,7 @@ struct ad7816_chip_info { u8 channel_id; /* 0 always be temperature */ u8 mode; struct mutex lock; /* protect device state during SPI transfers */ + __be16 rx_buf __aligned(IIO_DMA_MINALIGN); }; =20 enum ad7816_type { @@ -68,7 +69,6 @@ static int ad7816_spi_read(struct ad7816_chip_info *chip,= u16 *data) { struct spi_device *spi_dev =3D chip->spi_dev; int ret; - __be16 buf; =20 guard(mutex)(&chip->lock); =20 @@ -96,13 +96,13 @@ static int ad7816_spi_read(struct ad7816_chip_info *chi= p, u16 *data) =20 gpiod_set_value(chip->rdwr_pin, 0); gpiod_set_value(chip->rdwr_pin, 1); - ret =3D spi_read(spi_dev, &buf, sizeof(*data)); + ret =3D spi_read(spi_dev, &chip->rx_buf, sizeof(chip->rx_buf)); if (ret < 0) { dev_err(&spi_dev->dev, "SPI data read error\n"); return ret; } =20 - *data =3D be16_to_cpu(buf); + *data =3D be16_to_cpu(chip->rx_buf); =20 return ret; } --=20 2.54.0