]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
Input: sur40 - use guard notation when acquiring spinlock
authorDmitry Torokhov <dmitry.torokhov@gmail.com>
Wed, 14 Aug 2024 21:38:11 +0000 (14:38 -0700)
committerDmitry Torokhov <dmitry.torokhov@gmail.com>
Wed, 25 Mar 2026 14:53:59 +0000 (07:53 -0700)
Guard notation simplifies code.

Also use list_first_entry() instead of list_entry() to emphasize intent.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
drivers/input/touchscreen/sur40.c

index 877eae34fb5a0af46a206de2d063fd7692ecf06c..fe63d53d56db00e8ba659500141ac4854f4c49d6 100644 (file)
@@ -538,15 +538,15 @@ static void sur40_process_video(struct sur40_state *sur40)
                return;
 
        /* get a new buffer from the list */
-       spin_lock(&sur40->qlock);
-       if (list_empty(&sur40->buf_list)) {
-               dev_dbg(sur40->dev, "buffer queue empty\n");
-               spin_unlock(&sur40->qlock);
-               return;
+       scoped_guard(spinlock, &sur40->qlock) {
+               if (list_empty(&sur40->buf_list)) {
+                       dev_dbg(sur40->dev, "buffer queue empty\n");
+                       return;
+               }
+               new_buf = list_first_entry(&sur40->buf_list,
+                                          struct sur40_buffer, list);
+               list_del(&new_buf->list);
        }
-       new_buf = list_entry(sur40->buf_list.next, struct sur40_buffer, list);
-       list_del(&new_buf->list);
-       spin_unlock(&sur40->qlock);
 
        dev_dbg(sur40->dev, "buffer acquired\n");
 
@@ -888,9 +888,8 @@ static void sur40_buffer_queue(struct vb2_buffer *vb)
        struct sur40_state *sur40 = vb2_get_drv_priv(vb->vb2_queue);
        struct sur40_buffer *buf = (struct sur40_buffer *)vb;
 
-       spin_lock(&sur40->qlock);
+       guard(spinlock)(&sur40->qlock);
        list_add_tail(&buf->list, &sur40->buf_list);
-       spin_unlock(&sur40->qlock);
 }
 
 static void return_all_buffers(struct sur40_state *sur40,
@@ -898,12 +897,12 @@ static void return_all_buffers(struct sur40_state *sur40,
 {
        struct sur40_buffer *buf, *node;
 
-       spin_lock(&sur40->qlock);
+       guard(spinlock)(&sur40->qlock);
+
        list_for_each_entry_safe(buf, node, &sur40->buf_list, list) {
                vb2_buffer_done(&buf->vb.vb2_buf, state);
                list_del(&buf->list);
        }
-       spin_unlock(&sur40->qlock);
 }
 
 /*