Messages in this thread | | | From | Bartosz Golaszewski <> | Date | Fri, 6 Jan 2023 15:27:57 +0100 | Subject | Re: [PATCH v2 1/2] spi: spidev: fix a race condition when accessing spidev->spi |
| |
On Fri, Jan 6, 2023 at 3:13 PM Mark Brown <broonie@kernel.org> wrote: > > On Fri, Jan 06, 2023 at 11:07:18AM +0100, Bartosz Golaszewski wrote: > > > - use a mutex instead of an RW semaphore (but for the record: I believe that > > the semaphore is the better solution here) > > Why? Like I said in my original reply I'm not clear what the extra > complication is buying us.
Typically, we'd want to keep locking as fine-grained as possible. Logically, there's no reason to exclude concurrent execution of file_operations callbacks. There's a bunch of code in there that could run at the same time that we're now covering by the mutex' critical section. We should only be protecting spidev->spi here so any other locking should be handled elsewhere.
IMO the complication of using an RW semaphore is insignificant and maybe a comment next to its declaration in struct spidev would suffice?
Bart
| |