* [PATCH -next] iio: core: fix missing mutex_unlock() in iio_device_claim_buffer_mode()
@ 2022-11-04 9:03 Peng Wu
2022-11-04 9:54 ` Andy Shevchenko
0 siblings, 1 reply; 5+ messages in thread
From: Peng Wu @ 2022-11-04 9:03 UTC (permalink / raw)
To: jic23, lars, nuno.sa, andy.shevchenko; +Cc: linux-iio, liwei391, Peng Wu
In the success path of iio_device_claim_buffer_mode(), mutex_unlock()
should be called before return.
Fixes: e6dad5edfb8c ("iio: core: introduce iio_device_{claim|release}_buffer_mode() APIs")
Signed-off-by: Peng Wu <wupeng58@huawei.com>
---
drivers/iio/industrialio-core.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
index 52e690f031cb..88987cdc9e3f 100644
--- a/drivers/iio/industrialio-core.c
+++ b/drivers/iio/industrialio-core.c
@@ -2102,8 +2102,10 @@ int iio_device_claim_buffer_mode(struct iio_dev *indio_dev)
mutex_lock(&iio_dev_opaque->mlock);
- if (iio_buffer_enabled(indio_dev))
+ if (iio_buffer_enabled(indio_dev)) {
+ mutex_unlock(&iio_dev_opaque->mlock);
return 0;
+ }
mutex_unlock(&iio_dev_opaque->mlock);
return -EBUSY;
--
2.17.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH -next] iio: core: fix missing mutex_unlock() in iio_device_claim_buffer_mode()
2022-11-04 9:03 [PATCH -next] iio: core: fix missing mutex_unlock() in iio_device_claim_buffer_mode() Peng Wu
@ 2022-11-04 9:54 ` Andy Shevchenko
2022-11-04 11:13 ` Nuno Sá
0 siblings, 1 reply; 5+ messages in thread
From: Andy Shevchenko @ 2022-11-04 9:54 UTC (permalink / raw)
To: Peng Wu; +Cc: jic23, lars, nuno.sa, linux-iio, liwei391
On Fri, Nov 4, 2022 at 11:05 AM Peng Wu <wupeng58@huawei.com> wrote:
>
> In the success path of iio_device_claim_buffer_mode(), mutex_unlock()
> should be called before return.
Please, understand how the code works.
NAK.
Nuno, perhaps we need to put a comment inside the function to explain this?
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH -next] iio: core: fix missing mutex_unlock() in iio_device_claim_buffer_mode()
2022-11-04 9:54 ` Andy Shevchenko
@ 2022-11-04 11:13 ` Nuno Sá
2022-11-04 12:52 ` Andy Shevchenko
0 siblings, 1 reply; 5+ messages in thread
From: Nuno Sá @ 2022-11-04 11:13 UTC (permalink / raw)
To: Andy Shevchenko, Peng Wu; +Cc: jic23, lars, nuno.sa, linux-iio, liwei391
On Fri, 2022-11-04 at 11:54 +0200, Andy Shevchenko wrote:
> On Fri, Nov 4, 2022 at 11:05 AM Peng Wu <wupeng58@huawei.com> wrote:
> >
> > In the success path of iio_device_claim_buffer_mode(),
> > mutex_unlock()
> > should be called before return.
>
> Please, understand how the code works.
> NAK.
>
> Nuno, perhaps we need to put a comment inside the function to explain
> this?
>
Hmm... I guess we can do that but, honestly, the docs in the function
should be pretty straight. Maybe saying that it's supposed to work as
iio_device_claim_direct_mode() would help (as that one is familiar)...
Alternatively, having sparse annotations could also make it more easy
to understand the intent.
- Nuno Sá
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH -next] iio: core: fix missing mutex_unlock() in iio_device_claim_buffer_mode()
2022-11-04 11:13 ` Nuno Sá
@ 2022-11-04 12:52 ` Andy Shevchenko
2022-11-04 13:38 ` Nuno Sá
0 siblings, 1 reply; 5+ messages in thread
From: Andy Shevchenko @ 2022-11-04 12:52 UTC (permalink / raw)
To: Nuno Sá; +Cc: Peng Wu, jic23, lars, nuno.sa, linux-iio, liwei391
On Fri, Nov 4, 2022 at 1:11 PM Nuno Sá <noname.nuno@gmail.com> wrote:
> On Fri, 2022-11-04 at 11:54 +0200, Andy Shevchenko wrote:
> > On Fri, Nov 4, 2022 at 11:05 AM Peng Wu <wupeng58@huawei.com> wrote:
> > >
> > > In the success path of iio_device_claim_buffer_mode(),
> > > mutex_unlock()
> > > should be called before return.
> >
> > Please, understand how the code works.
> > NAK.
> >
> > Nuno, perhaps we need to put a comment inside the function to explain
> > this?
> >
>
> Hmm... I guess we can do that but, honestly, the docs in the function
> should be pretty straight. Maybe saying that it's supposed to work as
> iio_device_claim_direct_mode() would help (as that one is familiar)...
>
> Alternatively, having sparse annotations could also make it more easy
> to understand the intent.
Maybe simply
/* Yes, we leave it locked here */
before return 0; would suffice?
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH -next] iio: core: fix missing mutex_unlock() in iio_device_claim_buffer_mode()
2022-11-04 12:52 ` Andy Shevchenko
@ 2022-11-04 13:38 ` Nuno Sá
0 siblings, 0 replies; 5+ messages in thread
From: Nuno Sá @ 2022-11-04 13:38 UTC (permalink / raw)
To: Andy Shevchenko; +Cc: Peng Wu, jic23, lars, nuno.sa, linux-iio, liwei391
On Fri, 2022-11-04 at 14:52 +0200, Andy Shevchenko wrote:
> On Fri, Nov 4, 2022 at 1:11 PM Nuno Sá <noname.nuno@gmail.com> wrote:
> > On Fri, 2022-11-04 at 11:54 +0200, Andy Shevchenko wrote:
> > > On Fri, Nov 4, 2022 at 11:05 AM Peng Wu <wupeng58@huawei.com>
> > > wrote:
> > > >
> > > > In the success path of iio_device_claim_buffer_mode(),
> > > > mutex_unlock()
> > > > should be called before return.
> > >
> > > Please, understand how the code works.
> > > NAK.
> > >
> > > Nuno, perhaps we need to put a comment inside the function to
> > > explain
> > > this?
> > >
> >
> > Hmm... I guess we can do that but, honestly, the docs in the
> > function
> > should be pretty straight. Maybe saying that it's supposed to work
> > as
> > iio_device_claim_direct_mode() would help (as that one is
> > familiar)...
> >
> > Alternatively, having sparse annotations could also make it more
> > easy
> > to understand the intent.
>
> Maybe simply
>
> /* Yes, we leave it locked here */
>
> before return 0; would suffice?
Yes, I think so...
- Nuno Sá
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-11-04 13:36 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-04 9:03 [PATCH -next] iio: core: fix missing mutex_unlock() in iio_device_claim_buffer_mode() Peng Wu
2022-11-04 9:54 ` Andy Shevchenko
2022-11-04 11:13 ` Nuno Sá
2022-11-04 12:52 ` Andy Shevchenko
2022-11-04 13:38 ` Nuno Sá
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox