Re: [PATCH v3 1/2] staging: most: video: Protect pending_mbos and mute with list_lock
From: Andy Shevchenko
Date: Wed Nov 18 2026 - 06:22:50 EST
On Wed, Nov 18, 2026 at 12:20:32PM +0300, Dan Carpenter wrote:
> On Tue, Nov 17, 2026 at 10:35:57PM +0530, Shivani Patel wrote:
> > data_ready() and get_top_mbo() read mdev->pending_mbos without holding
> > mdev->list_lock, racing with comp_rx_data() which modifies the list
> > under mdev->list_lock. Also, comp_vdev_close() clears mdev->mute without
> > holding mdev->list_lock.
> >
> > Acquire mdev->list_lock in data_ready(), get_top_mbo(), and when
> > clearing mdev->mute in comp_vdev_close(). Use list_first_entry_or_null()
> > in get_top_mbo() so comp_vdev_read() can drop the redundant data_ready()
> > check inside the read loop.
...
> > -static inline bool data_ready(struct most_video_dev *mdev)
> > +static bool data_ready(struct most_video_dev *mdev)
> > {
> > - return !list_empty(&mdev->pending_mbos);
> > + unsigned long flags;
> > + bool ready;
> > +
> > + spin_lock_irqsave(&mdev->list_lock, flags);
> > + ready = !list_empty(&mdev->pending_mbos);
> > + spin_unlock_irqrestore(&mdev->list_lock, flags);
> > +
> > + return ready;
>
> It doesn't really matter if we take the lock where since we drop it
> right away. The list_empty() doesn't anything that requires locking
> so far as I can see.
Right, but the problem is that we possibly might compare valid pointer
(list head itself) with the stale pointer (head->next and/or head->prev).
Also don't forget that for 8-byte pointers on some architectures it
might be the cross-boundary split (most likely won't happen with struct
list_head as it should be at least 8-byte aligned, but still).
> > }
--
With Best Regards,
Andy Shevchenko