mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Shivani Patel <patelshivani2283@gmail.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Parthiban Veerasooran <parthiban.veerasooran@microchip.com>,
	Christian Gromm <christian.gromm@microchip.com>
Cc: linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org,
	Dan Carpenter <error27@gmail.com>,
	Andy Shevchenko <andriy.shevchenko@intel.com>,
	Julia Lawall <julia.lawall@inria.fr>,
	Shivani Patel <patelshivani2283@gmail.com>
Subject: [PATCH v3 1/2] staging: most: video: Protect pending_mbos and mute with list_lock
Date: Tue, 17 Nov 2026 22:35:57 +0530	[thread overview]
Message-ID: <20261117170558.33844-1-patelshivani2283@gmail.com> (raw)

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.

Signed-off-by: Shivani Patel <patelshivani2283@gmail.com>
---
v3:
 - New patch added after inspecting list_lock usage per Dan Carpenter's
   review of v2.

 drivers/staging/most/video/video.c | 34 ++++++++++++++++++++++++------
 1 file changed, 27 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/most/video/video.c b/drivers/staging/most/video/video.c
index 3a0445ff6..92d5fbc9a 100644
--- a/drivers/staging/most/video/video.c
+++ b/drivers/staging/most/video/video.c
@@ -60,14 +60,27 @@ static inline struct comp_fh *to_comp_fh(struct file *filp)
 static LIST_HEAD(video_devices);
 static DEFINE_SPINLOCK(list_lock);
 
-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;
 }
 
-static inline struct mbo *get_top_mbo(struct most_video_dev *mdev)
+static struct mbo *get_top_mbo(struct most_video_dev *mdev)
 {
-	return list_first_entry(&mdev->pending_mbos, struct mbo, list);
+	struct mbo *mbo;
+
+	spin_lock_irq(&mdev->list_lock);
+	mbo = list_first_entry_or_null(&mdev->pending_mbos, struct mbo, list);
+	spin_unlock_irq(&mdev->list_lock);
+
+	return mbo;
 }
 
 static int comp_vdev_open(struct file *filp)
@@ -143,7 +156,9 @@ static int comp_vdev_close(struct file *filp)
 	}
 
 	most_stop_channel(mdev->iface, mdev->ch_idx, &comp);
+	spin_lock_irq(&mdev->list_lock);
 	mdev->mute = false;
+	spin_unlock_irq(&mdev->list_lock);
 
 	v4l2_fh_del(&fh->fh, filp);
 	v4l2_fh_exit(&fh->fh);
@@ -175,10 +190,15 @@ static ssize_t comp_vdev_read(struct file *filp, char __user *buf,
 	if (!data_ready(mdev))
 		return -EAGAIN;
 
-	while (count > 0 && data_ready(mdev)) {
+	while (count > 0) {
 		struct mbo *const mbo = get_top_mbo(mdev);
-		int const rem = mbo->processed_length - fh->offs;
-		int const cnt = rem < count ? rem : count;
+		int rem, cnt;
+
+		if (!mbo)
+			break;
+
+		rem = mbo->processed_length - fh->offs;
+		cnt = rem < count ? rem : count;
 
 		if (copy_to_user(buf, mbo->virt_address + fh->offs, cnt)) {
 			v4l2_err(&mdev->v4l2_dev, "read: copy_to_user failed\n");
-- 
2.50.1 (Apple Git-155)


             reply	other threads:[~2026-11-17 17:06 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17 17:05 Shivani Patel [this message]
2026-11-17 17:05 ` [PATCH v3 2/2] staging: most: video: Document locks in struct most_video_dev Shivani Patel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261117170558.33844-1-patelshivani2283@gmail.com \
    --to=patelshivani2283@gmail.com \
    --cc=andriy.shevchenko@intel.com \
    --cc=christian.gromm@microchip.com \
    --cc=error27@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=julia.lawall@inria.fr \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-staging@lists.linux.dev \
    --cc=parthiban.veerasooran@microchip.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®