From: Praneeth Balasubramanian <praneethb2002@gmail.com>
To: Mauro Carvalho Chehab <mchehab@kernel.org>,
Hans Verkuil <hverkuil+cisco@kernel.org>
Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
Praneeth Balasubramanian <praneethb2002@gmail.com>,
stable@vger.kernel.org
Subject: [PATCH] media: bttv: Let the V4L2 core serialize the ioctls with btv->lock
Date: Fri, 4 Dec 2026 10:49:28 -0800 [thread overview]
Message-ID: <20261204184928.1686871-1-praneethb2002@gmail.com> (raw)
set_tvnorm() and set_input() must be called with btv->lock held, as
their comments say, but bttv_s_std() and bttv_s_input() call them
without it. Commit 587f0d5d6d44 ("[media] bttv: fix mutex use before
init (BZ#24602)") removed the driver's own locking from the ioctl
handlers, saying that the V4L2 core would serialize all ioctls from then
on, but it never set video_device->lock. Only the buffer queue uses
btv->lock (as q->lock since the vb2 conversion), so the core takes no
lock for VIDIOC_S_STD, VIDIOC_S_INPUT and the other ioctls that do not
touch the queue.
Two such calls can therefore run at the same time and leave
btv->tvnorm, btv->input, the cropping state, the timing registers and
the subdevice routing out of sync, for example with the chip programmed
for one standard while the driver reports another.
Set vfd->lock to btv->lock for the video, vbi and radio devices, so the
V4L2 core serializes all ioctls as intended. bttv_try_fmt_vbi_cap() and
bttv_s_fmt_vbi_cap() took btv->lock themselves; drop that, since the
core now holds it when they run.
The missing lock was found by a static check that turns the locking rule
in a function's comment into a Clang context-analysis requirement on its
callers.
Fixes: 587f0d5d6d44 ("[media] bttv: fix mutex use before init (BZ#24602)")
Cc: stable@vger.kernel.org
Signed-off-by: Praneeth Balasubramanian <praneethb2002@gmail.com>
---
Notes:
This was found by a compiler-based check, part of research at UCSB SecLab.
The locking rule stated in the kernel-doc comment of the called function
was turned into a Clang context-analysis requirement (__must_hold) on that
function, and Clang 23 with CONFIG_WARN_CONTEXT_ANALYSIS then checked every
caller. An LLM was used only to turn the comment into a machine-readable
rule; the report itself comes from the compiler. The patch and changelog
were drafted with Claude Opus 5.5. I reviewed the patch and take
responsibility for it.
Testing: builds without new warnings with W=1 (x86_64, clang 23,
allmodconfig). Not runtime-tested; I do not have this hardware, and I
have not observed the race myself.
drivers/media/pci/bt8xx/bttv-driver.c | 1 +
drivers/media/pci/bt8xx/bttv-vbi.c | 8 --------
2 files changed, 1 insertion(+), 8 deletions(-)
diff --git a/drivers/media/pci/bt8xx/bttv-driver.c b/drivers/media/pci/bt8xx/bttv-driver.c
index 8b9ca59f9434..a9d5487cd5f7 100644
--- a/drivers/media/pci/bt8xx/bttv-driver.c
+++ b/drivers/media/pci/bt8xx/bttv-driver.c
@@ -3078,6 +3078,7 @@ static int vdev_init(struct bttv *btv, struct video_device *vfd,
struct vb2_queue *q;
*vfd = *template;
vfd->v4l2_dev = &btv->c.v4l2_dev;
+ vfd->lock = &btv->lock;
vfd->release = video_device_release_empty;
video_set_drvdata(vfd, btv);
snprintf(vfd->name, sizeof(vfd->name), "BT%d%s %s (%s)",
diff --git a/drivers/media/pci/bt8xx/bttv-vbi.c b/drivers/media/pci/bt8xx/bttv-vbi.c
index 0ca88a2400ee..c2ceda4a15a9 100644
--- a/drivers/media/pci/bt8xx/bttv-vbi.c
+++ b/drivers/media/pci/bt8xx/bttv-vbi.c
@@ -247,13 +247,9 @@ int bttv_try_fmt_vbi_cap(struct file *file, void *priv, struct v4l2_format *frt)
const struct bttv_tvnorm *tvnorm;
__s32 crop_start;
- mutex_lock(&btv->lock);
-
tvnorm = &bttv_tvnorms[btv->tvnorm];
crop_start = btv->crop_start;
- mutex_unlock(&btv->lock);
-
return try_fmt(&frt->fmt.vbi, tvnorm, crop_start);
}
@@ -265,8 +261,6 @@ int bttv_s_fmt_vbi_cap(struct file *file, void *priv, struct v4l2_format *frt)
__s32 start1, end;
int rc;
- mutex_lock(&btv->lock);
-
rc = -EBUSY;
if (btv->resources & RESOURCE_VBI)
goto fail;
@@ -295,8 +289,6 @@ int bttv_s_fmt_vbi_cap(struct file *file, void *priv, struct v4l2_format *frt)
rc = 0;
fail:
- mutex_unlock(&btv->lock);
-
return rc;
}
--
2.25.1
reply other threads:[~2026-12-04 18:49 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261204184928.1686871-1-praneethb2002@gmail.com \
--to=praneethb2002@gmail.com \
--cc=hverkuil+cisco@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=stable@vger.kernel.org \
/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