Input: sur40 - use guard notation when acquiring spinlock

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>
This commit is contained in:
Dmitry Torokhov 2024-08-14 14:38:11 -07:00
parent 8665ceb926
commit dc05a01180

View 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);
}
/*