Skip to contentSkip to conversation

iio: core: fix missing mutex_unlock() in iio_device_claim_buffer_mode()

PATCH In review Peng Wu 3 participants 5 messages Nov 4, 2022 IIO

lore
Share & tools
lore

Peng Wu

author
#0 lore raw

PATCH 1/1 iio: core: fix missing mutex_unlock() in iio_device_claim_buffer_mode()

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")
---
 drivers/iio/industrialio-core.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/iio/industrialio-core.c +3 -1
index 52e690f031cb..88987cdc9e3f 100644
@@ -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;
Signature · 1 line
2.17.1
#1 lore raw
Quoted 3 lines · Peng Wu

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?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#2 lore raw
Quoted 6 lines · Andy Shevchenko
Quoted 4 lines · Peng Wu

In the success path of iio_device_claim_buffer_mode(), mutex_unlock()
should be called before return.

Quoted 6 lines

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á

#3 lore raw
Quoted 14 lines · Nuno Sá
Quoted 6 lines · Andy Shevchenko
Quoted 4 lines · Peng Wu

In the success path of iio_device_claim_buffer_mode(), mutex_unlock()
should be called before return.

Quoted 6 lines

Please, understand how the code works.
NAK.

Nuno, perhaps we need to put a comment inside the function to explain this?

Quoted 6 lines

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?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#4 lore raw
Quoted 28 lines · Andy Shevchenko
Quoted 23 lines · Nuno Sá
Quoted 7 lines · Andy Shevchenko
Quoted 4 lines · Peng Wu

In the success path of iio_device_claim_buffer_mode(), mutex_unlock()
should be called before return.

Quoted 7 lines

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)...

Quoted 3 lines

Alternatively, having sparse annotations could also make it more easy
to understand the intent.

Quoted 5 lines

Maybe simply

/* Yes, we leave it locked here */

before return 0; would suffice?

Yes, I think so...

- Nuno Sá