From: Hans Verkuil <hverkuil-cisco@xs4all.nl>
To: linux-media@vger.kernel.org
Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
Helen Koike <helen.koike@collabora.com>,
Hans Verkuil <hverkuil-cisco@xs4all.nl>
Subject: [PATCH 6/7] v4l2-device: v4l2_device_release_subdev_node can't reference sd
Date: Thu, 21 Feb 2019 15:21:47 +0100 [thread overview]
Message-ID: <20190221142148.3412-7-hverkuil-cisco@xs4all.nl> (raw)
In-Reply-To: <20190221142148.3412-1-hverkuil-cisco@xs4all.nl>
When the v4l-subdev device node is released it calls the
v4l2_device_release_subdev_node() function which sets sd->devnode
to NULL.
However, the v4l2_subdev struct may already be released causing this
to write in freed memory.
Instead just use the regular video_device_release release function
(just calls kfree) and set sd->devnode to NULL right after the
video_unregister_device() call.
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
---
drivers/media/v4l2-core/v4l2-device.c | 10 ++--------
1 file changed, 2 insertions(+), 8 deletions(-)
diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
index e0ddb9a52bd1..57a7b220fa4d 100644
--- a/drivers/media/v4l2-core/v4l2-device.c
+++ b/drivers/media/v4l2-core/v4l2-device.c
@@ -216,13 +216,6 @@ int v4l2_device_register_subdev(struct v4l2_device *v4l2_dev,
}
EXPORT_SYMBOL_GPL(v4l2_device_register_subdev);
-static void v4l2_device_release_subdev_node(struct video_device *vdev)
-{
- struct v4l2_subdev *sd = video_get_drvdata(vdev);
- sd->devnode = NULL;
- kfree(vdev);
-}
-
int v4l2_device_register_subdev_nodes(struct v4l2_device *v4l2_dev)
{
struct video_device *vdev;
@@ -250,7 +243,7 @@ int v4l2_device_register_subdev_nodes(struct v4l2_device *v4l2_dev)
vdev->dev_parent = sd->dev;
vdev->v4l2_dev = v4l2_dev;
vdev->fops = &v4l2_subdev_fops;
- vdev->release = v4l2_device_release_subdev_node;
+ vdev->release = video_device_release;
vdev->ctrl_handler = sd->ctrl_handler;
err = __video_register_device(vdev, VFL_TYPE_SUBDEV, -1, 1,
sd->owner);
@@ -319,6 +312,7 @@ void v4l2_device_unregister_subdev(struct v4l2_subdev *sd)
}
#endif
video_unregister_device(sd->devnode);
+ sd->devnode = NULL;
if (!sd->owner_v4l2_dev)
module_put(sd->owner);
}
--
2.20.1
next prev parent reply other threads:[~2019-02-21 14:21 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-21 14:21 [PATCH 0/7] Various core and virtual driver fixes Hans Verkuil
2019-02-21 14:21 ` [PATCH 1/7] cec: fill in cec chardev kobject to ease debugging Hans Verkuil
2019-02-22 11:10 ` Laurent Pinchart
2019-02-21 14:21 ` [PATCH 2/7] media-devnode: fill in media " Hans Verkuil
2019-02-22 11:07 ` Laurent Pinchart
2019-02-21 14:21 ` [PATCH 3/7] vivid: use vzalloc for dev->bitmap_out Hans Verkuil
2019-02-22 11:09 ` Laurent Pinchart
2019-02-21 14:21 ` [PATCH 4/7] media-entity: set ent_enum->bmap to NULL after freeing it Hans Verkuil
2019-02-22 11:17 ` Laurent Pinchart
2019-02-25 11:25 ` Hans Verkuil
2019-02-21 14:21 ` [PATCH 5/7] vim2m: replace devm_kzalloc by kzalloc Hans Verkuil
2019-02-22 11:20 ` Laurent Pinchart
2019-02-25 11:27 ` Hans Verkuil
2019-02-21 14:21 ` Hans Verkuil [this message]
2019-02-22 11:32 ` [PATCH 6/7] v4l2-device: v4l2_device_release_subdev_node can't reference sd Laurent Pinchart
2019-03-01 11:46 ` Hans Verkuil
2019-03-05 19:36 ` Laurent Pinchart
2019-02-21 14:21 ` [PATCH 7/7] vimc: free vimc_cap_device when the last user disappears Hans Verkuil
2019-02-22 11:37 ` Laurent Pinchart
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=20190221142148.3412-7-hverkuil-cisco@xs4all.nl \
--to=hverkuil-cisco@xs4all.nl \
--cc=helen.koike@collabora.com \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-media@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;
as well as URLs for NNTP newsgroup(s).