From: Xiaolei Wang <xiaolei.wang@windriver.com>
To: tomi.valkeinen@ideasonboard.com, kernel-list@raspberrypi.com,
mchehab@kernel.org, florian.fainelli@broadcom.com,
bcm-kernel-feedback-list@broadcom.com, hverkuil@xs4all.nl,
sakari.ailus@linux.intel.com, laurent.pinchart@ideasonboard.com,
xiaolei.wang@windriver.com
Cc: linux-media@vger.kernel.org,
linux-rpi-kernel@lists.infradead.org,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org
Subject: [PATCH] media: rp1-cfe: Fix double-free on video device re-registration
Date: Wed, 11 Feb 2026 11:45:01 +0800 [thread overview]
Message-ID: <20260211034501.1815035-1-xiaolei.wang@windriver.com> (raw)
When a sensor driver is unloaded and reloaded (e.g., rmmod/insmod ov5647),
the cfe_async_complete callback is invoked again, attempting to re-register
video nodes that are still registered. This causes multiple issues:
1. KASAN double-free in kfree_const when dev_set_name tries to free the
kobject name that was already freed during video_unregister_device
2. "tried to init an initialized object" warnings because the video_device
kobject is re-initialized before being fully released
Fix this by:
- Adding a check in cfe_probe_complete() to skip nodes already in
NODE_REGISTERED state, preventing duplicate registration attempts
- Implementing cfe_async_unbind() callback to properly clear the
source_sd pointer when the subdevice is unbound
Signed-off-by: Xiaolei Wang <xiaolei.wang@windriver.com>
---
drivers/media/platform/raspberrypi/rp1-cfe/cfe.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/drivers/media/platform/raspberrypi/rp1-cfe/cfe.c b/drivers/media/platform/raspberrypi/rp1-cfe/cfe.c
index 62dca76b468d..d3813c79316d 100644
--- a/drivers/media/platform/raspberrypi/rp1-cfe/cfe.c
+++ b/drivers/media/platform/raspberrypi/rp1-cfe/cfe.c
@@ -2152,6 +2152,9 @@ static int cfe_probe_complete(struct cfe_device *cfe)
cfe->v4l2_dev.notify = cfe_notify;
for (unsigned int i = 0; i < NUM_NODES; i++) {
+ if (check_state(cfe, NODE_REGISTERED, i))
+ continue;
+
ret = cfe_register_node(cfe, i);
if (ret) {
cfe_err(cfe, "Unable to register video node %u.\n", i);
@@ -2204,8 +2207,19 @@ static int cfe_async_complete(struct v4l2_async_notifier *notifier)
return cfe_probe_complete(cfe);
}
+static void cfe_async_unbind(struct v4l2_async_notifier *notifier,
+ struct v4l2_subdev *subdev,
+ struct v4l2_async_connection *asd)
+{
+ struct cfe_device *cfe = to_cfe_device(notifier->v4l2_dev);
+
+ cfe->source_sd = NULL;
+ cfe_info(cfe, "Unbinding subdev %s\n", subdev->name);
+}
+
static const struct v4l2_async_notifier_operations cfe_async_ops = {
.bound = cfe_async_bound,
+ .unbind = cfe_async_unbind,
.complete = cfe_async_complete,
};
--
2.43.0
next reply other threads:[~2026-02-11 3:46 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-11 3:45 Xiaolei Wang [this message]
2026-02-11 8:15 ` [PATCH] media: rp1-cfe: Fix double-free on video device re-registration Laurent Pinchart
2026-02-12 1:51 ` xiaolei wang
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=20260211034501.1815035-1-xiaolei.wang@windriver.com \
--to=xiaolei.wang@windriver.com \
--cc=bcm-kernel-feedback-list@broadcom.com \
--cc=florian.fainelli@broadcom.com \
--cc=hverkuil@xs4all.nl \
--cc=kernel-list@raspberrypi.com \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-rpi-kernel@lists.infradead.org \
--cc=mchehab@kernel.org \
--cc=sakari.ailus@linux.intel.com \
--cc=tomi.valkeinen@ideasonboard.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