From: Shuangpeng Bai <shuangpeng.kernel@gmail.com>
To: hverkuil@kernel.org, mchehab@kernel.org
Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org,
Shuangpeng Bai <shuangpeng.kernel@gmail.com>
Subject: [PATCH] media: gspca: hold a usb_device reference while registered
Date: Fri, 17 Jul 2026 22:54:34 -0400 [thread overview]
Message-ID: <20260718025434.2259756-1-shuangpeng.kernel@gmail.com> (raw)
gspca keeps a pointer to the probed struct usb_device in
gspca_dev->dev, but it does not hold a reference to it. The
V4L2/video-device reference can keep the outer gspca_dev alive after USB
disconnect, and the streaming queue can then be canceled from the last
file release path.
That late release path still calls into gspca_stream_off(), which may
call sub-driver stop callbacks or usb_set_interface() and dereference
gspca_dev->dev after the USB core has freed the device.
Take a reference to the usb_device when storing it in gspca_dev and drop
it from the final gspca_release() path. Balance the reference in the
probe error path as well.
Fixes: 63eb9546dcb5 ("V4L/DVB (8152): Initial release of gspca with only one driver.")
Cc: stable@vger.kernel.org
Signed-off-by: Shuangpeng Bai <shuangpeng.kernel@gmail.com>
---
drivers/media/usb/gspca/gspca.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/media/usb/gspca/gspca.c b/drivers/media/usb/gspca/gspca.c
index 594d73e50b9f..59eb4cec1aed 100644
--- a/drivers/media/usb/gspca/gspca.c
+++ b/drivers/media/usb/gspca/gspca.c
@@ -1178,6 +1178,7 @@ static void gspca_release(struct v4l2_device *v4l2_device)
v4l2_ctrl_handler_free(gspca_dev->vdev.ctrl_handler);
v4l2_device_unregister(&gspca_dev->v4l2_dev);
kfree(gspca_dev->usb_buf);
+ usb_put_dev(gspca_dev->dev);
kfree(gspca_dev);
}
@@ -1462,7 +1463,7 @@ int gspca_dev_probe2(struct usb_interface *intf,
ret = -ENOMEM;
goto out;
}
- gspca_dev->dev = dev;
+ gspca_dev->dev = usb_get_dev(dev);
gspca_dev->iface = intf->cur_altsetting->desc.bInterfaceNumber;
gspca_dev->xfer_ep = -1;
@@ -1574,6 +1575,7 @@ int gspca_dev_probe2(struct usb_interface *intf,
if (sd_desc->probe_error)
sd_desc->probe_error(gspca_dev);
kfree(gspca_dev->usb_buf);
+ usb_put_dev(gspca_dev->dev);
kfree(gspca_dev);
return ret;
}
--
2.43.0
next reply other threads:[~2026-07-18 2:55 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-18 2:54 Shuangpeng Bai [this message]
2026-07-28 12:33 ` Hans Verkuil
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=20260718025434.2259756-1-shuangpeng.kernel@gmail.com \
--to=shuangpeng.kernel@gmail.com \
--cc=hverkuil@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
all inboxes | Powered by JetHome®