Since this method has just been added, use it instead of open coding the
loop. This also has the side effect of dropping the PollCondVarBox
outside of the node_refs lock when two threads initialize it in
parallel.

Suggested-by: Boqun Feng <[email protected]>
Link: https://lore.kernel.org/all/[email protected]/
Signed-off-by: Alice Ryhl <[email protected]>
---
 drivers/android/binder/process.rs | 17 ++++-------------
 1 file changed, 4 insertions(+), 13 deletions(-)

diff --git a/drivers/android/binder/process.rs 
b/drivers/android/binder/process.rs
index d486bf7c0b8a..5f8779badd3d 100644
--- a/drivers/android/binder/process.rs
+++ b/drivers/android/binder/process.rs
@@ -1793,21 +1793,12 @@ pub(crate) fn poll(
         table: PollTable<'_>,
     ) -> Result<u32> {
         let thread = this.get_current_thread()?;
-        {
-            let poll = loop {
-                if let Some(poll) = this.poll.as_ref() {
-                    break poll;
-                }
 
-                let poll = PollCondVarBox::new(c"Process::poll", 
kernel::static_lock_class!())?;
-                // Reuse our existing lock to synchronize callers initializing.
-                let guard = this.node_refs.lock();
-                let _ret = this.poll.populate(poll);
-                drop(guard);
-            };
+        let poll = this.poll.try_get_or_populate(&this.node_refs, || {
+            PollCondVarBox::new(c"Process::poll", kernel::static_lock_class!())
+        })?;
+        table.register_wait(file, poll);
 
-            table.register_wait(file, poll);
-        }
         let (from_proc, mut mask) = thread.poll()?;
         if mask == 0 && from_proc && !this.inner.lock().work.is_empty() {
             mask |= bindings::POLLIN;

-- 
2.55.0.229.g6434b31f56-goog


Reply via email to