Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795060623; b=HkEoEHJv3JY/4WnpgtBID1XdCn0HFtAZlqWcFFo2M+/wBQMnsIszpkmdTI/OQvy0yyOM EP/bgXvOUGS7SYxE1OTLahvUk7VEm7oiyilnLRYUwaMWllsXE9N5IBBKatxBXY1y8voUU QFPXzBU1UPTpfbtMAIA+B42yZd9tpq6IyQIr9PGrGCYUxkyXtTRnv5ddn1LKVGC/m+5Bt ORWAvRgk5YV1nejOAvXqb+SX7JI2N/+jQEM4fiPv7iAkTo2wivRBIjNw5UC/xuEecsgY7 ltOE2M80xqx7XRJD/0RWmllhNHVn3ZWAqt1ygIJ3Ys3KQOlT2RO0dY1l8KbPHCvcCyA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795060623; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=MumZe+1nFLtirg5vOiiSyyXSpY/Z1w1a9kafY6ndMTM=; b=IjJyOBsEKQAJofOlh9KWnrJrmDlKCxgj3DRgclaa4NfAR+iGtC0zQ++BJzU3CWPsvNZU L/BGkeLpGFt6vZI7INO4pZq+pudlufe7PaDE/lUJHnXKT36juI4KeRnQg1KGAhWfvqhej 5JZEiycZ/Utp+9m0qZFomJjh2mY3DXtg1Jtv2Ale51H7RP28HFtypiPCeeHPsnJ/M4iQE cn8ZuImH6N1gH5cVU1/cNbUJ+4sxf4uPELFZajGwr/xOy7P65vT3j4aihtE+0C5qe8wTc RSY0Sn6QVPdL6y87aiFA0mlU4URs5h2zKtv8pTBSMVDBs776n3IRxbWeAvbL7K/G9Rw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=EQBo+Agj; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EFA23606A325; Thu, 19 Nov 2026 03:57:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=EQBo+Agj Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4C78D1F000C4; Thu, 19 Nov 2026 03:57:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795060622; bh=MumZe+1nFLtirg5vOiiSyyXSpY/Z1w1a9kafY6ndMTM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=EQBo+AgjYKxvMLfhOLb9+cROWd/y8kuOwT1ckqHfBHvG3p2xSudcKScn2n6PQmTkj mDgRtJNrFTOqJG1vKD729tHo0SmTsUu3ZP/mngn/hVurXAJHPXc3KwwwYl13C6gPoZ wDNWaEWP3gsJamdx6TMK3WHbTAr9X/vgTGci3tEs= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Abdelnasser Hussein , Joshua Crofts , Jonathan Cameron , Sasha Levin Subject: [PATCH 5.10 1265/1848] staging: iio: adc: ad7816: Fix DMA safety issues in SPI transfers Date: Wed, 18 Nov 2026 15:55:03 +0100 Message-ID: <20261118150012.645137807@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118145911.150052362@linuxfoundation.org> References: <20261118145911.150052362@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Abdelnasser Hussein [ Upstream commit 69fa76f0af3414cc189c3b0b807cb59e327ecc00 ] The SPI operations in this driver are not DMA safe: 1. spi_read() uses a stack-allocated buffer. 2. spi_write() in ad7816_spi_read() uses a struct member that shares a cacheline with other variables. 3. spi_write() in ad7816_spi_write() passes a stack parameter by reference. Fix these violations by replacing all spi_read() and spi_write() calls with spi_write_then_read(). This safely handles DMA by internally allocating a bounce buffer for the transfers, avoiding cacheline sharing issues without needing dedicated aligned buffers. This implicitly corrects the size argument in read to sizeof(buf). Fixes: 7924425db04a ("staging: iio: adc: new driver for AD7816 devices") Signed-off-by: Abdelnasser Hussein Reviewed-by: Joshua Crofts Signed-off-by: Jonathan Cameron Signed-off-by: Sasha Levin --- 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/ad7816.c index 081b17f498638..a46ca0559b6a2 100644 --- a/drivers/staging/iio/adc/ad7816.c +++ b/drivers/staging/iio/adc/ad7816.c @@ -69,7 +69,7 @@ static int ad7816_spi_read(struct ad7816_chip_info *chip, u16 *data) gpiod_set_value(chip->rdwr_pin, 1); gpiod_set_value(chip->rdwr_pin, 0); - ret = spi_write(spi_dev, &chip->channel_id, sizeof(chip->channel_id)); + ret = spi_write_then_read(spi_dev, &chip->channel_id, sizeof(chip->channel_id), NULL, 0); if (ret < 0) { dev_err(&spi_dev->dev, "SPI channel setting error\n"); return ret; @@ -91,7 +91,7 @@ static int ad7816_spi_read(struct ad7816_chip_info *chip, u16 *data) gpiod_set_value(chip->rdwr_pin, 0); gpiod_set_value(chip->rdwr_pin, 1); - ret = spi_read(spi_dev, &buf, sizeof(*data)); + ret = spi_write_then_read(spi_dev, NULL, 0, &buf, sizeof(buf)); if (ret < 0) { dev_err(&spi_dev->dev, "SPI data read error\n"); return ret; @@ -109,7 +109,7 @@ static int ad7816_spi_write(struct ad7816_chip_info *chip, u8 data) gpiod_set_value(chip->rdwr_pin, 1); gpiod_set_value(chip->rdwr_pin, 0); - ret = spi_write(spi_dev, &data, sizeof(data)); + ret = spi_write_then_read(spi_dev, &data, sizeof(data), NULL, 0); if (ret < 0) dev_err(&spi_dev->dev, "SPI oti data write error\n"); -- 2.53.0