[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <5365cf30-042e-4b71-87ea-3766c6f16bcb@baylibre.com>
Date: Mon, 1 Sep 2025 15:37:41 -0500
From: David Lechner <dlechner@...libre.com>
To: Mohammad Amin Hosseini <moahmmad.hosseinii@...il.com>,
linux-iio@...r.kernel.org, linux-staging@...ts.linux.dev
Cc: linux-kernel@...r.kernel.org, gregkh@...uxfoundation.org,
jic23@...nel.org, lars@...afoo.de, Michael.Hennerich@...log.com,
nuno.sa@...log.com, andy@...nel.org, sonic.zhang@...log.com,
vapier@...too.org, dan.carpenter@...aro.org
Subject: Re: [PATCH v5] staging: iio: adc: ad7816: fix race condition in SPI
operations
On 9/1/25 2:40 PM, Mohammad Amin Hosseini wrote:
> The ad7816 driver lacks proper synchronization around SPI operations
> and device state access. Concurrent access from multiple threads can
> lead to data corruption and inconsistent device state.
>
> The driver performs sequences of GPIO pin manipulations followed by
> SPI transactions without any locking. Device state variables (mode,
> channel_id, oti_data) are also accessed without synchronization.
>
> This bug was found through manual code review using static analysis
> techniques. The review focused on identifying unsynchronized access
> patterns to shared resources. Key indicators were:
> - GPIO pin state changes followed by SPI operations without atomicity
> - Shared state variables accessed from multiple sysfs entry points
> - No mutex or spinlock protection around sections
> - Potential for interleaved execution in multi-threaded environments
>
> The review methodology involved tracing data flow paths and identifying
> points where concurrent access could corrupt device state or SPI
> communication sequences.
>
> Add io_lock mutex to protect:
> - SPI transactions and GPIO sequences in read/write functions
> - Device state variables in sysfs show/store functions
> - Concurrent access to chip configuration
>
> This prevents race conditions when multiple processes access the device
> simultaneously through sysfs attributes or device file operations.
>
> Fixes: 7924425db04a ("staging: iio: adc: new driver for AD7816 devices")
>
> Signed-off-by: Mohammad Amin Hosseini <moahmmad.hosseinii@...il.com>
>
> ---
> Changes in v5:
> - Rebased on top of latest staging tree
> - Dropped unrelated cleanups (sysfs_emit, sysfs_streq, type casts, etc.)
> - Keep only the mutex locking for SPI and GPIO access
> ---
My comments from v1 [1] are still applicable (have not been addressed).
[1]: https://lore.kernel.org/linux-iio/b6c2ac13-2781-49ba-964f-ca821b32e2a2@baylibre.com/
Powered by blists - more mailing lists