lkml.org 
[lkml]   [2022]   [Nov]   [30]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v4 2/2] gpiolib: protect the GPIO device against being dropped while in use by user-space
On Wed, Nov 30, 2022 at 01:05:30PM +0100, Bartosz Golaszewski wrote:
> On Wed, Nov 30, 2022 at 1:02 PM Andy Shevchenko
> <andriy.shevchenko@linux.intel.com> wrote:
> > On Wed, Nov 30, 2022 at 10:05:56AM +0100, Bartosz Golaszewski wrote:

> > > + down_read(&gdev->sem);
> >
> > Thinking more about this, wouldn't be better to actually
> >
> > ret = down_read_trylock(&gdev->sem);
> > if (ret)
> > return ret;
> >
> > ?
>
> You mean as in: try to take the lock, but if we're already removing
> the device (as the down_write() can only happen in gpiochip_remove()),
> then die right away? Smart! Yeah, I'll do it this way.

But please check return values properly (it seems not obvious what it does
return).

--
With Best Regards,
Andy Shevchenko


\
 
 \ /
  Last update: 2022-11-30 13:32    [W:0.030 / U:0.592 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site