* [PATCH] V4L: dynamically allocate video_device nodes in subdevices
@ 2011-09-09 15:02 Guennadi Liakhovetski
2011-09-09 17:45 ` [PATCH v2] " Guennadi Liakhovetski
0 siblings, 1 reply; 15+ messages in thread
From: Guennadi Liakhovetski @ 2011-09-09 15:02 UTC (permalink / raw)
To: Linux Media Mailing List; +Cc: Laurent Pinchart, Hans Verkuil
Currently only very few drivers actually use video_device nodes, embedded
in struct v4l2_subdev. Allocate these nodes dynamically for those drivers
to save memory for the rest.
Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
---
Only compile tested. Please, give it a spin on affected hardware.
drivers/media/video/v4l2-device.c | 28 +++++++++++++++++++++++++---
include/media/v4l2-subdev.h | 10 ++++++++--
2 files changed, 33 insertions(+), 5 deletions(-)
diff --git a/drivers/media/video/v4l2-device.c b/drivers/media/video/v4l2-device.c
index c72856c..0c0f6ba 100644
--- a/drivers/media/video/v4l2-device.c
+++ b/drivers/media/video/v4l2-device.c
@@ -21,6 +21,7 @@
#include <linux/types.h>
#include <linux/ioctl.h>
#include <linux/i2c.h>
+#include <linux/slab.h>
#if defined(CONFIG_SPI)
#include <linux/spi/spi.h>
#endif
@@ -194,6 +195,7 @@ EXPORT_SYMBOL_GPL(v4l2_device_register_subdev);
int v4l2_device_register_subdev_nodes(struct v4l2_device *v4l2_dev)
{
struct video_device *vdev;
+ struct v4l2_devnode *node;
struct v4l2_subdev *sd;
int err;
@@ -204,7 +206,13 @@ int v4l2_device_register_subdev_nodes(struct v4l2_device *v4l2_dev)
if (!(sd->flags & V4L2_SUBDEV_FL_HAS_DEVNODE))
continue;
- vdev = &sd->devnode;
+ node = kzalloc(sizeof(*node), GFP_KERNEL);
+ if (!node) {
+ err = -ENOMEM;
+ goto clean_up;
+ }
+ vdev = &node->vdev;
+
strlcpy(vdev->name, sd->name, sizeof(vdev->name));
vdev->v4l2_dev = v4l2_dev;
vdev->fops = &v4l2_subdev_fops;
@@ -213,13 +221,25 @@ int v4l2_device_register_subdev_nodes(struct v4l2_device *v4l2_dev)
err = __video_register_device(vdev, VFL_TYPE_SUBDEV, -1, 1,
sd->owner);
if (err < 0)
- return err;
+ goto clean_up;
#if defined(CONFIG_MEDIA_CONTROLLER)
sd->entity.v4l.major = VIDEO_MAJOR;
sd->entity.v4l.minor = vdev->minor;
#endif
+ sd->devnode = node;
}
return 0;
+
+clean_up:
+ list_for_each_entry(sd, &v4l2_dev->subdevs, list) {
+ if (!sd->devnode)
+ break;
+ video_unregister_device(&sd->devnode->vdev);
+ kfree(sd->devnode);
+ sd->devnode = NULL;
+ }
+
+ return err;
}
EXPORT_SYMBOL_GPL(v4l2_device_register_subdev_nodes);
@@ -245,7 +265,9 @@ void v4l2_device_unregister_subdev(struct v4l2_subdev *sd)
if (v4l2_dev->mdev)
media_device_unregister_entity(&sd->entity);
#endif
- video_unregister_device(&sd->devnode);
+ video_unregister_device(&sd->devnode->vdev);
+ kfree(sd->devnode);
+ sd->devnode = NULL;
module_put(sd->owner);
}
EXPORT_SYMBOL_GPL(v4l2_device_unregister_subdev);
diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h
index 257da1a..6e958df 100644
--- a/include/media/v4l2-subdev.h
+++ b/include/media/v4l2-subdev.h
@@ -510,6 +510,12 @@ struct v4l2_subdev_internal_ops {
/* Set this flag if this subdev generates events. */
#define V4L2_SUBDEV_FL_HAS_EVENTS (1U << 3)
+/* video_device with a reverse lookup */
+struct v4l2_devnode {
+ struct v4l2_subdev *sd;
+ struct video_device vdev;
+};
+
/* Each instance of a subdev driver should create this struct, either
stand-alone or embedded in a larger struct.
*/
@@ -534,13 +540,13 @@ struct v4l2_subdev {
void *dev_priv;
void *host_priv;
/* subdev device node */
- struct video_device devnode;
+ struct v4l2_devnode *devnode;
};
#define media_entity_to_v4l2_subdev(ent) \
container_of(ent, struct v4l2_subdev, entity)
#define vdev_to_v4l2_subdev(vdev) \
- container_of(vdev, struct v4l2_subdev, devnode)
+ (container_of(vdev, struct v4l2_devnode, vdev)->sd)
/*
* Used for storing subdev information per file handle
--
1.7.2.5
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH v2] V4L: dynamically allocate video_device nodes in subdevices
2011-09-09 15:02 [PATCH] V4L: dynamically allocate video_device nodes in subdevices Guennadi Liakhovetski
@ 2011-09-09 17:45 ` Guennadi Liakhovetski
2011-09-09 21:32 ` Laurent Pinchart
0 siblings, 1 reply; 15+ messages in thread
From: Guennadi Liakhovetski @ 2011-09-09 17:45 UTC (permalink / raw)
To: Linux Media Mailing List; +Cc: Laurent Pinchart, Hans Verkuil
Currently only very few drivers actually use video_device nodes, embedded
in struct v4l2_subdev. Allocate these nodes dynamically for those drivers
to save memory for the rest.
Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
---
v2: Checking for NULL is not always enough, you also have to check the
right thing for it. In this case it was sd->devnode in
v4l2_device_unregister_subdev().
drivers/media/video/v4l2-device.c | 29 ++++++++++++++++++++++++++---
include/media/v4l2-subdev.h | 10 ++++++++--
2 files changed, 34 insertions(+), 5 deletions(-)
diff --git a/drivers/media/video/v4l2-device.c b/drivers/media/video/v4l2-device.c
index c72856c..d4c093f 100644
--- a/drivers/media/video/v4l2-device.c
+++ b/drivers/media/video/v4l2-device.c
@@ -21,6 +21,7 @@
#include <linux/types.h>
#include <linux/ioctl.h>
#include <linux/i2c.h>
+#include <linux/slab.h>
#if defined(CONFIG_SPI)
#include <linux/spi/spi.h>
#endif
@@ -194,6 +195,7 @@ EXPORT_SYMBOL_GPL(v4l2_device_register_subdev);
int v4l2_device_register_subdev_nodes(struct v4l2_device *v4l2_dev)
{
struct video_device *vdev;
+ struct v4l2_devnode *node;
struct v4l2_subdev *sd;
int err;
@@ -204,7 +206,13 @@ int v4l2_device_register_subdev_nodes(struct v4l2_device *v4l2_dev)
if (!(sd->flags & V4L2_SUBDEV_FL_HAS_DEVNODE))
continue;
- vdev = &sd->devnode;
+ node = kzalloc(sizeof(*node), GFP_KERNEL);
+ if (!node) {
+ err = -ENOMEM;
+ goto clean_up;
+ }
+ vdev = &node->vdev;
+
strlcpy(vdev->name, sd->name, sizeof(vdev->name));
vdev->v4l2_dev = v4l2_dev;
vdev->fops = &v4l2_subdev_fops;
@@ -213,13 +221,25 @@ int v4l2_device_register_subdev_nodes(struct v4l2_device *v4l2_dev)
err = __video_register_device(vdev, VFL_TYPE_SUBDEV, -1, 1,
sd->owner);
if (err < 0)
- return err;
+ goto clean_up;
#if defined(CONFIG_MEDIA_CONTROLLER)
sd->entity.v4l.major = VIDEO_MAJOR;
sd->entity.v4l.minor = vdev->minor;
#endif
+ sd->devnode = node;
}
return 0;
+
+clean_up:
+ list_for_each_entry(sd, &v4l2_dev->subdevs, list) {
+ if (!sd->devnode)
+ break;
+ video_unregister_device(&sd->devnode->vdev);
+ kfree(sd->devnode);
+ sd->devnode = NULL;
+ }
+
+ return err;
}
EXPORT_SYMBOL_GPL(v4l2_device_register_subdev_nodes);
@@ -245,7 +265,10 @@ void v4l2_device_unregister_subdev(struct v4l2_subdev *sd)
if (v4l2_dev->mdev)
media_device_unregister_entity(&sd->entity);
#endif
- video_unregister_device(&sd->devnode);
+ if (sd->devnode)
+ video_unregister_device(&sd->devnode->vdev);
+ kfree(sd->devnode);
+ sd->devnode = NULL;
module_put(sd->owner);
}
EXPORT_SYMBOL_GPL(v4l2_device_unregister_subdev);
diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h
index 257da1a..6e958df 100644
--- a/include/media/v4l2-subdev.h
+++ b/include/media/v4l2-subdev.h
@@ -510,6 +510,12 @@ struct v4l2_subdev_internal_ops {
/* Set this flag if this subdev generates events. */
#define V4L2_SUBDEV_FL_HAS_EVENTS (1U << 3)
+/* video_device with a reverse lookup */
+struct v4l2_devnode {
+ struct v4l2_subdev *sd;
+ struct video_device vdev;
+};
+
/* Each instance of a subdev driver should create this struct, either
stand-alone or embedded in a larger struct.
*/
@@ -534,13 +540,13 @@ struct v4l2_subdev {
void *dev_priv;
void *host_priv;
/* subdev device node */
- struct video_device devnode;
+ struct v4l2_devnode *devnode;
};
#define media_entity_to_v4l2_subdev(ent) \
container_of(ent, struct v4l2_subdev, entity)
#define vdev_to_v4l2_subdev(vdev) \
- container_of(vdev, struct v4l2_subdev, devnode)
+ (container_of(vdev, struct v4l2_devnode, vdev)->sd)
/*
* Used for storing subdev information per file handle
--
1.7.2.5
^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [PATCH v2] V4L: dynamically allocate video_device nodes in subdevices
2011-09-09 17:45 ` [PATCH v2] " Guennadi Liakhovetski
@ 2011-09-09 21:32 ` Laurent Pinchart
2011-09-10 10:27 ` Guennadi Liakhovetski
2011-09-12 10:55 ` [PATCH v3] " Guennadi Liakhovetski
0 siblings, 2 replies; 15+ messages in thread
From: Laurent Pinchart @ 2011-09-09 21:32 UTC (permalink / raw)
To: Guennadi Liakhovetski; +Cc: Linux Media Mailing List, Hans Verkuil
Hi Guennadi,
On Friday 09 September 2011 19:45:57 Guennadi Liakhovetski wrote:
> Currently only very few drivers actually use video_device nodes, embedded
> in struct v4l2_subdev. Allocate these nodes dynamically for those drivers
> to save memory for the rest.
Thanks for the patch.
> Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
> ---
>
> v2: Checking for NULL is not always enough, you also have to check the
> right thing for it. In this case it was sd->devnode in
> v4l2_device_unregister_subdev().
>
> drivers/media/video/v4l2-device.c | 29 ++++++++++++++++++++++++++---
> include/media/v4l2-subdev.h | 10 ++++++++--
> 2 files changed, 34 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/media/video/v4l2-device.c
> b/drivers/media/video/v4l2-device.c index c72856c..d4c093f 100644
> --- a/drivers/media/video/v4l2-device.c
> +++ b/drivers/media/video/v4l2-device.c
> @@ -21,6 +21,7 @@
> #include <linux/types.h>
> #include <linux/ioctl.h>
> #include <linux/i2c.h>
> +#include <linux/slab.h>
> #if defined(CONFIG_SPI)
> #include <linux/spi/spi.h>
> #endif
> @@ -194,6 +195,7 @@ EXPORT_SYMBOL_GPL(v4l2_device_register_subdev);
> int v4l2_device_register_subdev_nodes(struct v4l2_device *v4l2_dev)
> {
> struct video_device *vdev;
> + struct v4l2_devnode *node;
> struct v4l2_subdev *sd;
> int err;
>
> @@ -204,7 +206,13 @@ int v4l2_device_register_subdev_nodes(struct
> v4l2_device *v4l2_dev) if (!(sd->flags & V4L2_SUBDEV_FL_HAS_DEVNODE))
> continue;
>
> - vdev = &sd->devnode;
> + node = kzalloc(sizeof(*node), GFP_KERNEL);
> + if (!node) {
> + err = -ENOMEM;
> + goto clean_up;
> + }
> + vdev = &node->vdev;
> +
> strlcpy(vdev->name, sd->name, sizeof(vdev->name));
> vdev->v4l2_dev = v4l2_dev;
> vdev->fops = &v4l2_subdev_fops;
> @@ -213,13 +221,25 @@ int v4l2_device_register_subdev_nodes(struct
> v4l2_device *v4l2_dev) err = __video_register_device(vdev,
> VFL_TYPE_SUBDEV, -1, 1,
> sd->owner);
> if (err < 0)
> - return err;
> + goto clean_up;
> #if defined(CONFIG_MEDIA_CONTROLLER)
> sd->entity.v4l.major = VIDEO_MAJOR;
> sd->entity.v4l.minor = vdev->minor;
> #endif
> + sd->devnode = node;
> }
> return 0;
> +
> +clean_up:
> + list_for_each_entry(sd, &v4l2_dev->subdevs, list) {
> + if (!sd->devnode)
> + break;
> + video_unregister_device(&sd->devnode->vdev);
> + kfree(sd->devnode);
> + sd->devnode = NULL;
> + }
> +
> + return err;
> }
> EXPORT_SYMBOL_GPL(v4l2_device_register_subdev_nodes);
>
> @@ -245,7 +265,10 @@ void v4l2_device_unregister_subdev(struct v4l2_subdev
> *sd) if (v4l2_dev->mdev)
> media_device_unregister_entity(&sd->entity);
> #endif
> - video_unregister_device(&sd->devnode);
> + if (sd->devnode)
> + video_unregister_device(&sd->devnode->vdev);
> + kfree(sd->devnode);
Won't this crash if the node is open ? I think you need to refcount it.
> + sd->devnode = NULL;
> module_put(sd->owner);
> }
> EXPORT_SYMBOL_GPL(v4l2_device_unregister_subdev);
> diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h
> index 257da1a..6e958df 100644
> --- a/include/media/v4l2-subdev.h
> +++ b/include/media/v4l2-subdev.h
> @@ -510,6 +510,12 @@ struct v4l2_subdev_internal_ops {
> /* Set this flag if this subdev generates events. */
> #define V4L2_SUBDEV_FL_HAS_EVENTS (1U << 3)
>
> +/* video_device with a reverse lookup */
> +struct v4l2_devnode {
> + struct v4l2_subdev *sd;
> + struct video_device vdev;
> +};
> +
Instead of that, why don't you store the subdev pointer in the video_device
driver data ?
> /* Each instance of a subdev driver should create this struct, either
> stand-alone or embedded in a larger struct.
> */
> @@ -534,13 +540,13 @@ struct v4l2_subdev {
> void *dev_priv;
> void *host_priv;
> /* subdev device node */
> - struct video_device devnode;
> + struct v4l2_devnode *devnode;
> };
>
> #define media_entity_to_v4l2_subdev(ent) \
> container_of(ent, struct v4l2_subdev, entity)
> #define vdev_to_v4l2_subdev(vdev) \
> - container_of(vdev, struct v4l2_subdev, devnode)
> + (container_of(vdev, struct v4l2_devnode, vdev)->sd)
>
> /*
> * Used for storing subdev information per file handle
--
Regards,
Laurent Pinchart
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2] V4L: dynamically allocate video_device nodes in subdevices
2011-09-09 21:32 ` Laurent Pinchart
@ 2011-09-10 10:27 ` Guennadi Liakhovetski
2011-09-12 10:55 ` [PATCH v3] " Guennadi Liakhovetski
1 sibling, 0 replies; 15+ messages in thread
From: Guennadi Liakhovetski @ 2011-09-10 10:27 UTC (permalink / raw)
To: Laurent Pinchart; +Cc: Linux Media Mailing List, Hans Verkuil
Hi Laurent
On Fri, 9 Sep 2011, Laurent Pinchart wrote:
> Hi Guennadi,
>
> On Friday 09 September 2011 19:45:57 Guennadi Liakhovetski wrote:
> > Currently only very few drivers actually use video_device nodes, embedded
> > in struct v4l2_subdev. Allocate these nodes dynamically for those drivers
> > to save memory for the rest.
>
> Thanks for the patch.
>
> > Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
> > ---
> >
> > v2: Checking for NULL is not always enough, you also have to check the
> > right thing for it. In this case it was sd->devnode in
> > v4l2_device_unregister_subdev().
> >
> > drivers/media/video/v4l2-device.c | 29 ++++++++++++++++++++++++++---
> > include/media/v4l2-subdev.h | 10 ++++++++--
> > 2 files changed, 34 insertions(+), 5 deletions(-)
> >
> > diff --git a/drivers/media/video/v4l2-device.c
> > b/drivers/media/video/v4l2-device.c index c72856c..d4c093f 100644
> > --- a/drivers/media/video/v4l2-device.c
> > +++ b/drivers/media/video/v4l2-device.c
> > @@ -21,6 +21,7 @@
> > #include <linux/types.h>
> > #include <linux/ioctl.h>
> > #include <linux/i2c.h>
> > +#include <linux/slab.h>
> > #if defined(CONFIG_SPI)
> > #include <linux/spi/spi.h>
> > #endif
> > @@ -194,6 +195,7 @@ EXPORT_SYMBOL_GPL(v4l2_device_register_subdev);
> > int v4l2_device_register_subdev_nodes(struct v4l2_device *v4l2_dev)
> > {
> > struct video_device *vdev;
> > + struct v4l2_devnode *node;
> > struct v4l2_subdev *sd;
> > int err;
> >
> > @@ -204,7 +206,13 @@ int v4l2_device_register_subdev_nodes(struct
> > v4l2_device *v4l2_dev) if (!(sd->flags & V4L2_SUBDEV_FL_HAS_DEVNODE))
> > continue;
> >
> > - vdev = &sd->devnode;
> > + node = kzalloc(sizeof(*node), GFP_KERNEL);
> > + if (!node) {
> > + err = -ENOMEM;
> > + goto clean_up;
> > + }
> > + vdev = &node->vdev;
> > +
> > strlcpy(vdev->name, sd->name, sizeof(vdev->name));
> > vdev->v4l2_dev = v4l2_dev;
> > vdev->fops = &v4l2_subdev_fops;
> > @@ -213,13 +221,25 @@ int v4l2_device_register_subdev_nodes(struct
> > v4l2_device *v4l2_dev) err = __video_register_device(vdev,
> > VFL_TYPE_SUBDEV, -1, 1,
> > sd->owner);
> > if (err < 0)
> > - return err;
> > + goto clean_up;
> > #if defined(CONFIG_MEDIA_CONTROLLER)
> > sd->entity.v4l.major = VIDEO_MAJOR;
> > sd->entity.v4l.minor = vdev->minor;
> > #endif
> > + sd->devnode = node;
> > }
> > return 0;
> > +
> > +clean_up:
> > + list_for_each_entry(sd, &v4l2_dev->subdevs, list) {
> > + if (!sd->devnode)
> > + break;
> > + video_unregister_device(&sd->devnode->vdev);
> > + kfree(sd->devnode);
> > + sd->devnode = NULL;
> > + }
> > +
> > + return err;
> > }
> > EXPORT_SYMBOL_GPL(v4l2_device_register_subdev_nodes);
> >
> > @@ -245,7 +265,10 @@ void v4l2_device_unregister_subdev(struct v4l2_subdev
> > *sd) if (v4l2_dev->mdev)
> > media_device_unregister_entity(&sd->entity);
> > #endif
> > - video_unregister_device(&sd->devnode);
> > + if (sd->devnode)
> > + video_unregister_device(&sd->devnode->vdev);
> > + kfree(sd->devnode);
>
> Won't this crash if the node is open ? I think you need to refcount it.
Hm, I've been thinking about it, but maybe not far enough.
>
> > + sd->devnode = NULL;
> > module_put(sd->owner);
> > }
> > EXPORT_SYMBOL_GPL(v4l2_device_unregister_subdev);
> > diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h
> > index 257da1a..6e958df 100644
> > --- a/include/media/v4l2-subdev.h
> > +++ b/include/media/v4l2-subdev.h
> > @@ -510,6 +510,12 @@ struct v4l2_subdev_internal_ops {
> > /* Set this flag if this subdev generates events. */
> > #define V4L2_SUBDEV_FL_HAS_EVENTS (1U << 3)
> >
> > +/* video_device with a reverse lookup */
> > +struct v4l2_devnode {
> > + struct v4l2_subdev *sd;
> > + struct video_device vdev;
> > +};
> > +
>
> Instead of that, why don't you store the subdev pointer in the video_device
> driver data ?
Is it free yet? Could do, sure.
> > /* Each instance of a subdev driver should create this struct, either
> > stand-alone or embedded in a larger struct.
> > */
> > @@ -534,13 +540,13 @@ struct v4l2_subdev {
> > void *dev_priv;
> > void *host_priv;
> > /* subdev device node */
> > - struct video_device devnode;
> > + struct v4l2_devnode *devnode;
> > };
> >
> > #define media_entity_to_v4l2_subdev(ent) \
> > container_of(ent, struct v4l2_subdev, entity)
> > #define vdev_to_v4l2_subdev(vdev) \
> > - container_of(vdev, struct v4l2_subdev, devnode)
> > + (container_of(vdev, struct v4l2_devnode, vdev)->sd)
> >
> > /*
> > * Used for storing subdev information per file handle
Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH v3] V4L: dynamically allocate video_device nodes in subdevices
2011-09-09 21:32 ` Laurent Pinchart
2011-09-10 10:27 ` Guennadi Liakhovetski
@ 2011-09-12 10:55 ` Guennadi Liakhovetski
2011-09-13 9:16 ` Laurent Pinchart
1 sibling, 1 reply; 15+ messages in thread
From: Guennadi Liakhovetski @ 2011-09-12 10:55 UTC (permalink / raw)
To: Laurent Pinchart; +Cc: Linux Media Mailing List, Hans Verkuil
Currently only very few drivers actually use video_device nodes, embedded
in struct v4l2_subdev. Allocate these nodes dynamically for those drivers
to save memory for the rest.
Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
---
v3: addressed comments from Laurent Pinchart - thanks
1. switch to using a device-release method, instead of freeing directly in
v4l2_device_unregister_subdev()
2. switch to using drvdata instead of a wrapper struct
drivers/media/video/v4l2-device.c | 41 ++++++++++++++++++++++++++++++++----
include/media/v4l2-subdev.h | 4 +-
2 files changed, 38 insertions(+), 7 deletions(-)
diff --git a/drivers/media/video/v4l2-device.c b/drivers/media/video/v4l2-device.c
index c72856c..9bf3d70 100644
--- a/drivers/media/video/v4l2-device.c
+++ b/drivers/media/video/v4l2-device.c
@@ -21,6 +21,7 @@
#include <linux/types.h>
#include <linux/ioctl.h>
#include <linux/i2c.h>
+#include <linux/slab.h>
#if defined(CONFIG_SPI)
#include <linux/spi/spi.h>
#endif
@@ -191,6 +192,13 @@ int v4l2_device_register_subdev(struct v4l2_device *v4l2_dev,
}
EXPORT_SYMBOL_GPL(v4l2_device_register_subdev);
+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;
@@ -204,22 +212,42 @@ int v4l2_device_register_subdev_nodes(struct v4l2_device *v4l2_dev)
if (!(sd->flags & V4L2_SUBDEV_FL_HAS_DEVNODE))
continue;
- vdev = &sd->devnode;
+ vdev = kzalloc(sizeof(*vdev), GFP_KERNEL);
+ if (!vdev) {
+ err = -ENOMEM;
+ goto clean_up;
+ }
+
+ video_set_drvdata(vdev, sd);
strlcpy(vdev->name, sd->name, sizeof(vdev->name));
vdev->v4l2_dev = v4l2_dev;
vdev->fops = &v4l2_subdev_fops;
- vdev->release = video_device_release_empty;
+ vdev->release = v4l2_device_release_subdev_node;
vdev->ctrl_handler = sd->ctrl_handler;
err = __video_register_device(vdev, VFL_TYPE_SUBDEV, -1, 1,
sd->owner);
- if (err < 0)
- return err;
+ if (err < 0) {
+ kfree(vdev);
+ goto clean_up;
+ }
+ get_device(&vdev->dev);
#if defined(CONFIG_MEDIA_CONTROLLER)
sd->entity.v4l.major = VIDEO_MAJOR;
sd->entity.v4l.minor = vdev->minor;
#endif
+ sd->devnode = vdev;
}
return 0;
+
+clean_up:
+ list_for_each_entry(sd, &v4l2_dev->subdevs, list) {
+ if (!sd->devnode)
+ break;
+ video_unregister_device(sd->devnode);
+ put_device(&sd->devnode->dev);
+ }
+
+ return err;
}
EXPORT_SYMBOL_GPL(v4l2_device_register_subdev_nodes);
@@ -245,7 +273,10 @@ void v4l2_device_unregister_subdev(struct v4l2_subdev *sd)
if (v4l2_dev->mdev)
media_device_unregister_entity(&sd->entity);
#endif
- video_unregister_device(&sd->devnode);
+ if (sd->devnode) {
+ video_unregister_device(sd->devnode);
+ put_device(&sd->devnode->dev);
+ }
module_put(sd->owner);
}
EXPORT_SYMBOL_GPL(v4l2_device_unregister_subdev);
diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h
index 257da1a..5dd049a 100644
--- a/include/media/v4l2-subdev.h
+++ b/include/media/v4l2-subdev.h
@@ -534,13 +534,13 @@ struct v4l2_subdev {
void *dev_priv;
void *host_priv;
/* subdev device node */
- struct video_device devnode;
+ struct video_device *devnode;
};
#define media_entity_to_v4l2_subdev(ent) \
container_of(ent, struct v4l2_subdev, entity)
#define vdev_to_v4l2_subdev(vdev) \
- container_of(vdev, struct v4l2_subdev, devnode)
+ video_get_drvdata(vdev)
/*
* Used for storing subdev information per file handle
--
1.7.2.5
^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [PATCH v3] V4L: dynamically allocate video_device nodes in subdevices
2011-09-12 10:55 ` [PATCH v3] " Guennadi Liakhovetski
@ 2011-09-13 9:16 ` Laurent Pinchart
2011-09-13 9:26 ` Guennadi Liakhovetski
2011-09-13 14:48 ` [PATCH v4] " Guennadi Liakhovetski
0 siblings, 2 replies; 15+ messages in thread
From: Laurent Pinchart @ 2011-09-13 9:16 UTC (permalink / raw)
To: Guennadi Liakhovetski; +Cc: Linux Media Mailing List, Hans Verkuil
Hi Guennadi,
On Monday 12 September 2011 12:55:46 Guennadi Liakhovetski wrote:
> Currently only very few drivers actually use video_device nodes, embedded
> in struct v4l2_subdev. Allocate these nodes dynamically for those drivers
> to save memory for the rest.
>
> Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
> ---
>
> v3: addressed comments from Laurent Pinchart - thanks
Thanks for the patch. Just one small comment below.
> 1. switch to using a device-release method, instead of freeing directly in
> v4l2_device_unregister_subdev()
>
> 2. switch to using drvdata instead of a wrapper struct
>
> drivers/media/video/v4l2-device.c | 41
> ++++++++++++++++++++++++++++++++---- include/media/v4l2-subdev.h |
> 4 +-
> 2 files changed, 38 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/media/video/v4l2-device.c
> b/drivers/media/video/v4l2-device.c index c72856c..9bf3d70 100644
> --- a/drivers/media/video/v4l2-device.c
> +++ b/drivers/media/video/v4l2-device.c
> @@ -21,6 +21,7 @@
> #include <linux/types.h>
> #include <linux/ioctl.h>
> #include <linux/i2c.h>
> +#include <linux/slab.h>
> #if defined(CONFIG_SPI)
> #include <linux/spi/spi.h>
> #endif
> @@ -191,6 +192,13 @@ int v4l2_device_register_subdev(struct v4l2_device
> *v4l2_dev, }
> EXPORT_SYMBOL_GPL(v4l2_device_register_subdev);
>
> +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;
> @@ -204,22 +212,42 @@ int v4l2_device_register_subdev_nodes(struct
> v4l2_device *v4l2_dev) if (!(sd->flags & V4L2_SUBDEV_FL_HAS_DEVNODE))
> continue;
>
> - vdev = &sd->devnode;
> + vdev = kzalloc(sizeof(*vdev), GFP_KERNEL);
> + if (!vdev) {
> + err = -ENOMEM;
> + goto clean_up;
> + }
> +
> + video_set_drvdata(vdev, sd);
> strlcpy(vdev->name, sd->name, sizeof(vdev->name));
> vdev->v4l2_dev = v4l2_dev;
> vdev->fops = &v4l2_subdev_fops;
> - vdev->release = video_device_release_empty;
> + vdev->release = v4l2_device_release_subdev_node;
> vdev->ctrl_handler = sd->ctrl_handler;
> err = __video_register_device(vdev, VFL_TYPE_SUBDEV, -1, 1,
> sd->owner);
> - if (err < 0)
> - return err;
> + if (err < 0) {
> + kfree(vdev);
> + goto clean_up;
> + }
> + get_device(&vdev->dev);
Is get_device() (and the corresponding put_device() calls below) required ? I
thought device_register() initialized the reference count to 1 (don't take my
word for it though).
> #if defined(CONFIG_MEDIA_CONTROLLER)
> sd->entity.v4l.major = VIDEO_MAJOR;
> sd->entity.v4l.minor = vdev->minor;
> #endif
> + sd->devnode = vdev;
> }
> return 0;
> +
> +clean_up:
> + list_for_each_entry(sd, &v4l2_dev->subdevs, list) {
> + if (!sd->devnode)
> + break;
> + video_unregister_device(sd->devnode);
> + put_device(&sd->devnode->dev);
> + }
> +
> + return err;
> }
> EXPORT_SYMBOL_GPL(v4l2_device_register_subdev_nodes);
>
> @@ -245,7 +273,10 @@ void v4l2_device_unregister_subdev(struct v4l2_subdev
> *sd) if (v4l2_dev->mdev)
> media_device_unregister_entity(&sd->entity);
> #endif
> - video_unregister_device(&sd->devnode);
> + if (sd->devnode) {
> + video_unregister_device(sd->devnode);
> + put_device(&sd->devnode->dev);
> + }
> module_put(sd->owner);
> }
> EXPORT_SYMBOL_GPL(v4l2_device_unregister_subdev);
> diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h
> index 257da1a..5dd049a 100644
> --- a/include/media/v4l2-subdev.h
> +++ b/include/media/v4l2-subdev.h
> @@ -534,13 +534,13 @@ struct v4l2_subdev {
> void *dev_priv;
> void *host_priv;
> /* subdev device node */
> - struct video_device devnode;
> + struct video_device *devnode;
> };
>
> #define media_entity_to_v4l2_subdev(ent) \
> container_of(ent, struct v4l2_subdev, entity)
> #define vdev_to_v4l2_subdev(vdev) \
> - container_of(vdev, struct v4l2_subdev, devnode)
> + video_get_drvdata(vdev)
>
> /*
> * Used for storing subdev information per file handle
--
Regards,
Laurent Pinchart
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v3] V4L: dynamically allocate video_device nodes in subdevices
2011-09-13 9:16 ` Laurent Pinchart
@ 2011-09-13 9:26 ` Guennadi Liakhovetski
2011-09-13 9:45 ` Laurent Pinchart
2011-09-13 14:48 ` [PATCH v4] " Guennadi Liakhovetski
1 sibling, 1 reply; 15+ messages in thread
From: Guennadi Liakhovetski @ 2011-09-13 9:26 UTC (permalink / raw)
To: Laurent Pinchart; +Cc: Linux Media Mailing List, Hans Verkuil
On Tue, 13 Sep 2011, Laurent Pinchart wrote:
> Hi Guennadi,
>
> On Monday 12 September 2011 12:55:46 Guennadi Liakhovetski wrote:
> > Currently only very few drivers actually use video_device nodes, embedded
> > in struct v4l2_subdev. Allocate these nodes dynamically for those drivers
> > to save memory for the rest.
> >
> > Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
> > ---
> >
> > v3: addressed comments from Laurent Pinchart - thanks
>
> Thanks for the patch. Just one small comment below.
>
> > 1. switch to using a device-release method, instead of freeing directly in
> > v4l2_device_unregister_subdev()
> >
> > 2. switch to using drvdata instead of a wrapper struct
> >
> > drivers/media/video/v4l2-device.c | 41
> > ++++++++++++++++++++++++++++++++---- include/media/v4l2-subdev.h |
> > 4 +-
> > 2 files changed, 38 insertions(+), 7 deletions(-)
> >
> > diff --git a/drivers/media/video/v4l2-device.c
> > b/drivers/media/video/v4l2-device.c index c72856c..9bf3d70 100644
> > --- a/drivers/media/video/v4l2-device.c
> > +++ b/drivers/media/video/v4l2-device.c
> > @@ -21,6 +21,7 @@
> > #include <linux/types.h>
> > #include <linux/ioctl.h>
> > #include <linux/i2c.h>
> > +#include <linux/slab.h>
> > #if defined(CONFIG_SPI)
> > #include <linux/spi/spi.h>
> > #endif
> > @@ -191,6 +192,13 @@ int v4l2_device_register_subdev(struct v4l2_device
> > *v4l2_dev, }
> > EXPORT_SYMBOL_GPL(v4l2_device_register_subdev);
> >
> > +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;
> > @@ -204,22 +212,42 @@ int v4l2_device_register_subdev_nodes(struct
> > v4l2_device *v4l2_dev) if (!(sd->flags & V4L2_SUBDEV_FL_HAS_DEVNODE))
> > continue;
> >
> > - vdev = &sd->devnode;
> > + vdev = kzalloc(sizeof(*vdev), GFP_KERNEL);
> > + if (!vdev) {
> > + err = -ENOMEM;
> > + goto clean_up;
> > + }
> > +
> > + video_set_drvdata(vdev, sd);
> > strlcpy(vdev->name, sd->name, sizeof(vdev->name));
> > vdev->v4l2_dev = v4l2_dev;
> > vdev->fops = &v4l2_subdev_fops;
> > - vdev->release = video_device_release_empty;
> > + vdev->release = v4l2_device_release_subdev_node;
> > vdev->ctrl_handler = sd->ctrl_handler;
> > err = __video_register_device(vdev, VFL_TYPE_SUBDEV, -1, 1,
> > sd->owner);
> > - if (err < 0)
> > - return err;
> > + if (err < 0) {
> > + kfree(vdev);
> > + goto clean_up;
> > + }
> > + get_device(&vdev->dev);
>
> Is get_device() (and the corresponding put_device() calls below) required ? I
> thought device_register() initialized the reference count to 1 (don't take my
> word for it though).
Indeed, I think, you're right. Will update.
Thanks
Guennadi
>
> > #if defined(CONFIG_MEDIA_CONTROLLER)
> > sd->entity.v4l.major = VIDEO_MAJOR;
> > sd->entity.v4l.minor = vdev->minor;
> > #endif
> > + sd->devnode = vdev;
> > }
> > return 0;
> > +
> > +clean_up:
> > + list_for_each_entry(sd, &v4l2_dev->subdevs, list) {
> > + if (!sd->devnode)
> > + break;
> > + video_unregister_device(sd->devnode);
> > + put_device(&sd->devnode->dev);
> > + }
> > +
> > + return err;
> > }
> > EXPORT_SYMBOL_GPL(v4l2_device_register_subdev_nodes);
> >
> > @@ -245,7 +273,10 @@ void v4l2_device_unregister_subdev(struct v4l2_subdev
> > *sd) if (v4l2_dev->mdev)
> > media_device_unregister_entity(&sd->entity);
> > #endif
> > - video_unregister_device(&sd->devnode);
> > + if (sd->devnode) {
> > + video_unregister_device(sd->devnode);
> > + put_device(&sd->devnode->dev);
> > + }
> > module_put(sd->owner);
> > }
> > EXPORT_SYMBOL_GPL(v4l2_device_unregister_subdev);
> > diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h
> > index 257da1a..5dd049a 100644
> > --- a/include/media/v4l2-subdev.h
> > +++ b/include/media/v4l2-subdev.h
> > @@ -534,13 +534,13 @@ struct v4l2_subdev {
> > void *dev_priv;
> > void *host_priv;
> > /* subdev device node */
> > - struct video_device devnode;
> > + struct video_device *devnode;
> > };
> >
> > #define media_entity_to_v4l2_subdev(ent) \
> > container_of(ent, struct v4l2_subdev, entity)
> > #define vdev_to_v4l2_subdev(vdev) \
> > - container_of(vdev, struct v4l2_subdev, devnode)
> > + video_get_drvdata(vdev)
> >
> > /*
> > * Used for storing subdev information per file handle
>
> --
> Regards,
>
> Laurent Pinchart
>
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v3] V4L: dynamically allocate video_device nodes in subdevices
2011-09-13 9:26 ` Guennadi Liakhovetski
@ 2011-09-13 9:45 ` Laurent Pinchart
2011-09-13 14:15 ` Guennadi Liakhovetski
0 siblings, 1 reply; 15+ messages in thread
From: Laurent Pinchart @ 2011-09-13 9:45 UTC (permalink / raw)
To: Guennadi Liakhovetski; +Cc: Linux Media Mailing List, Hans Verkuil
Hi Guennadi,
On Tuesday 13 September 2011 11:26:23 Guennadi Liakhovetski wrote:
> On Tue, 13 Sep 2011, Laurent Pinchart wrote:
> > On Monday 12 September 2011 12:55:46 Guennadi Liakhovetski wrote:
> > > Currently only very few drivers actually use video_device nodes,
> > > embedded in struct v4l2_subdev. Allocate these nodes dynamically for
> > > those drivers to save memory for the rest.
> > >
> > > Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
> > > ---
> > >
> > > v3: addressed comments from Laurent Pinchart - thanks
> >
> > Thanks for the patch. Just one small comment below.
> >
> > > 1. switch to using a device-release method, instead of freeing directly
> > > in v4l2_device_unregister_subdev()
> > >
> > > 2. switch to using drvdata instead of a wrapper struct
> > >
> > > drivers/media/video/v4l2-device.c | 41
> > >
> > > ++++++++++++++++++++++++++++++++---- include/media/v4l2-subdev.h
> > > |
> > >
> > > 4 +-
> > > 2 files changed, 38 insertions(+), 7 deletions(-)
> > >
> > > diff --git a/drivers/media/video/v4l2-device.c
> > > b/drivers/media/video/v4l2-device.c index c72856c..9bf3d70 100644
> > > --- a/drivers/media/video/v4l2-device.c
> > > +++ b/drivers/media/video/v4l2-device.c
> > > @@ -21,6 +21,7 @@
> > >
> > > #include <linux/types.h>
> > > #include <linux/ioctl.h>
> > > #include <linux/i2c.h>
> > >
> > > +#include <linux/slab.h>
> > >
> > > #if defined(CONFIG_SPI)
> > > #include <linux/spi/spi.h>
> > > #endif
> > >
> > > @@ -191,6 +192,13 @@ int v4l2_device_register_subdev(struct v4l2_device
> > > *v4l2_dev, }
> > >
> > > EXPORT_SYMBOL_GPL(v4l2_device_register_subdev);
> > >
> > > +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;
> > >
> > > @@ -204,22 +212,42 @@ int v4l2_device_register_subdev_nodes(struct
> > > v4l2_device *v4l2_dev) if (!(sd->flags & V4L2_SUBDEV_FL_HAS_DEVNODE))
> > >
> > > continue;
> > >
> > > - vdev = &sd->devnode;
> > > + vdev = kzalloc(sizeof(*vdev), GFP_KERNEL);
> > > + if (!vdev) {
> > > + err = -ENOMEM;
> > > + goto clean_up;
> > > + }
> > > +
> > > + video_set_drvdata(vdev, sd);
> > >
> > > strlcpy(vdev->name, sd->name, sizeof(vdev->name));
> > > vdev->v4l2_dev = v4l2_dev;
> > > vdev->fops = &v4l2_subdev_fops;
> > >
> > > - vdev->release = video_device_release_empty;
> > > + vdev->release = v4l2_device_release_subdev_node;
> > >
> > > vdev->ctrl_handler = sd->ctrl_handler;
> > > err = __video_register_device(vdev, VFL_TYPE_SUBDEV, -1, 1,
> > >
> > > sd->owner);
> > >
> > > - if (err < 0)
> > > - return err;
> > > + if (err < 0) {
> > > + kfree(vdev);
> > > + goto clean_up;
> > > + }
> > > + get_device(&vdev->dev);
> >
> > Is get_device() (and the corresponding put_device() calls below) required
> > ? I thought device_register() initialized the reference count to 1
> > (don't take my word for it though).
>
> Indeed, I think, you're right. Will update.
Please test it as well :-)
--
Regards,
Laurent Pinchart
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v3] V4L: dynamically allocate video_device nodes in subdevices
2011-09-13 9:45 ` Laurent Pinchart
@ 2011-09-13 14:15 ` Guennadi Liakhovetski
0 siblings, 0 replies; 15+ messages in thread
From: Guennadi Liakhovetski @ 2011-09-13 14:15 UTC (permalink / raw)
To: Laurent Pinchart; +Cc: Linux Media Mailing List, Hans Verkuil
On Tue, 13 Sep 2011, Laurent Pinchart wrote:
> Hi Guennadi,
>
> On Tuesday 13 September 2011 11:26:23 Guennadi Liakhovetski wrote:
> > On Tue, 13 Sep 2011, Laurent Pinchart wrote:
> > > On Monday 12 September 2011 12:55:46 Guennadi Liakhovetski wrote:
> > > > Currently only very few drivers actually use video_device nodes,
> > > > embedded in struct v4l2_subdev. Allocate these nodes dynamically for
> > > > those drivers to save memory for the rest.
> > > >
> > > > Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
> > > > ---
> > > >
> > > > v3: addressed comments from Laurent Pinchart - thanks
> > >
> > > Thanks for the patch. Just one small comment below.
> > >
> > > > 1. switch to using a device-release method, instead of freeing directly
> > > > in v4l2_device_unregister_subdev()
> > > >
> > > > 2. switch to using drvdata instead of a wrapper struct
> > > >
> > > > drivers/media/video/v4l2-device.c | 41
> > > >
> > > > ++++++++++++++++++++++++++++++++---- include/media/v4l2-subdev.h
> > > > |
> > > >
> > > > 4 +-
> > > > 2 files changed, 38 insertions(+), 7 deletions(-)
> > > >
> > > > diff --git a/drivers/media/video/v4l2-device.c
> > > > b/drivers/media/video/v4l2-device.c index c72856c..9bf3d70 100644
> > > > --- a/drivers/media/video/v4l2-device.c
> > > > +++ b/drivers/media/video/v4l2-device.c
> > > > @@ -21,6 +21,7 @@
> > > >
> > > > #include <linux/types.h>
> > > > #include <linux/ioctl.h>
> > > > #include <linux/i2c.h>
> > > >
> > > > +#include <linux/slab.h>
> > > >
> > > > #if defined(CONFIG_SPI)
> > > > #include <linux/spi/spi.h>
> > > > #endif
> > > >
> > > > @@ -191,6 +192,13 @@ int v4l2_device_register_subdev(struct v4l2_device
> > > > *v4l2_dev, }
> > > >
> > > > EXPORT_SYMBOL_GPL(v4l2_device_register_subdev);
> > > >
> > > > +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;
> > > >
> > > > @@ -204,22 +212,42 @@ int v4l2_device_register_subdev_nodes(struct
> > > > v4l2_device *v4l2_dev) if (!(sd->flags & V4L2_SUBDEV_FL_HAS_DEVNODE))
> > > >
> > > > continue;
> > > >
> > > > - vdev = &sd->devnode;
> > > > + vdev = kzalloc(sizeof(*vdev), GFP_KERNEL);
> > > > + if (!vdev) {
> > > > + err = -ENOMEM;
> > > > + goto clean_up;
> > > > + }
> > > > +
> > > > + video_set_drvdata(vdev, sd);
> > > >
> > > > strlcpy(vdev->name, sd->name, sizeof(vdev->name));
> > > > vdev->v4l2_dev = v4l2_dev;
> > > > vdev->fops = &v4l2_subdev_fops;
> > > >
> > > > - vdev->release = video_device_release_empty;
> > > > + vdev->release = v4l2_device_release_subdev_node;
> > > >
> > > > vdev->ctrl_handler = sd->ctrl_handler;
> > > > err = __video_register_device(vdev, VFL_TYPE_SUBDEV, -1, 1,
> > > >
> > > > sd->owner);
> > > >
> > > > - if (err < 0)
> > > > - return err;
> > > > + if (err < 0) {
> > > > + kfree(vdev);
> > > > + goto clean_up;
> > > > + }
> > > > + get_device(&vdev->dev);
> > >
> > > Is get_device() (and the corresponding put_device() calls below) required
> > > ? I thought device_register() initialized the reference count to 1
> > > (don't take my word for it though).
> >
> > Indeed, I think, you're right. Will update.
>
> Please test it as well :-)
I'm afraid, testing it wouldn't be very easy for me: I only have one
system here, on which MC is used - the beagle-board. And it is not an easy
nor a quick exersize to bring it up and run a test on it;-) But if noone
else finds time to test it and if we're not confident enough in its
correctness, well, we'll have to wait until I find time to do that...
BTW, there's one more improvement to be made for this patch:
-void v4l2_device_release_subdev_node(struct video_device *vdev)
+static void v4l2_device_release_subdev_node(struct video_device *vdev)
My copy-paste from video_device_release_empty() was too precise:-(
Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH v4] V4L: dynamically allocate video_device nodes in subdevices
2011-09-13 9:16 ` Laurent Pinchart
2011-09-13 9:26 ` Guennadi Liakhovetski
@ 2011-09-13 14:48 ` Guennadi Liakhovetski
2011-09-13 17:51 ` Sylwester Nawrocki
2011-09-13 17:52 ` Laurent Pinchart
1 sibling, 2 replies; 15+ messages in thread
From: Guennadi Liakhovetski @ 2011-09-13 14:48 UTC (permalink / raw)
To: Laurent Pinchart; +Cc: Linux Media Mailing List, Hans Verkuil
Currently only very few drivers actually use video_device nodes, embedded
in struct v4l2_subdev. Allocate these nodes dynamically for those drivers
to save memory for the rest.
Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
---
v4:
1. added "static" in v4l2_device_release_subdev_node() definition
2. removed superfluous get_device() and put_device() (thanks to Laurent
for pointing out)
drivers/media/video/v4l2-device.c | 36 +++++++++++++++++++++++++++++++-----
include/media/v4l2-subdev.h | 4 ++--
2 files changed, 33 insertions(+), 7 deletions(-)
diff --git a/drivers/media/video/v4l2-device.c b/drivers/media/video/v4l2-device.c
index c72856c..8abf830 100644
--- a/drivers/media/video/v4l2-device.c
+++ b/drivers/media/video/v4l2-device.c
@@ -21,6 +21,7 @@
#include <linux/types.h>
#include <linux/ioctl.h>
#include <linux/i2c.h>
+#include <linux/slab.h>
#if defined(CONFIG_SPI)
#include <linux/spi/spi.h>
#endif
@@ -191,6 +192,13 @@ 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;
@@ -204,22 +212,40 @@ int v4l2_device_register_subdev_nodes(struct v4l2_device *v4l2_dev)
if (!(sd->flags & V4L2_SUBDEV_FL_HAS_DEVNODE))
continue;
- vdev = &sd->devnode;
+ vdev = kzalloc(sizeof(*vdev), GFP_KERNEL);
+ if (!vdev) {
+ err = -ENOMEM;
+ goto clean_up;
+ }
+
+ video_set_drvdata(vdev, sd);
strlcpy(vdev->name, sd->name, sizeof(vdev->name));
vdev->v4l2_dev = v4l2_dev;
vdev->fops = &v4l2_subdev_fops;
- vdev->release = video_device_release_empty;
+ vdev->release = v4l2_device_release_subdev_node;
vdev->ctrl_handler = sd->ctrl_handler;
err = __video_register_device(vdev, VFL_TYPE_SUBDEV, -1, 1,
sd->owner);
- if (err < 0)
- return err;
+ if (err < 0) {
+ kfree(vdev);
+ goto clean_up;
+ }
#if defined(CONFIG_MEDIA_CONTROLLER)
sd->entity.v4l.major = VIDEO_MAJOR;
sd->entity.v4l.minor = vdev->minor;
#endif
+ sd->devnode = vdev;
}
return 0;
+
+clean_up:
+ list_for_each_entry(sd, &v4l2_dev->subdevs, list) {
+ if (!sd->devnode)
+ break;
+ video_unregister_device(sd->devnode);
+ }
+
+ return err;
}
EXPORT_SYMBOL_GPL(v4l2_device_register_subdev_nodes);
@@ -245,7 +271,7 @@ void v4l2_device_unregister_subdev(struct v4l2_subdev *sd)
if (v4l2_dev->mdev)
media_device_unregister_entity(&sd->entity);
#endif
- video_unregister_device(&sd->devnode);
+ video_unregister_device(sd->devnode);
module_put(sd->owner);
}
EXPORT_SYMBOL_GPL(v4l2_device_unregister_subdev);
diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h
index 257da1a..5dd049a 100644
--- a/include/media/v4l2-subdev.h
+++ b/include/media/v4l2-subdev.h
@@ -534,13 +534,13 @@ struct v4l2_subdev {
void *dev_priv;
void *host_priv;
/* subdev device node */
- struct video_device devnode;
+ struct video_device *devnode;
};
#define media_entity_to_v4l2_subdev(ent) \
container_of(ent, struct v4l2_subdev, entity)
#define vdev_to_v4l2_subdev(vdev) \
- container_of(vdev, struct v4l2_subdev, devnode)
+ video_get_drvdata(vdev)
/*
* Used for storing subdev information per file handle
--
1.7.2.5
^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [PATCH v4] V4L: dynamically allocate video_device nodes in subdevices
2011-09-13 14:48 ` [PATCH v4] " Guennadi Liakhovetski
@ 2011-09-13 17:51 ` Sylwester Nawrocki
2011-09-13 21:18 ` Guennadi Liakhovetski
2011-09-13 17:52 ` Laurent Pinchart
1 sibling, 1 reply; 15+ messages in thread
From: Sylwester Nawrocki @ 2011-09-13 17:51 UTC (permalink / raw)
To: Guennadi Liakhovetski
Cc: Laurent Pinchart, Linux Media Mailing List, Hans Verkuil
Hi Guennadi,
On 09/13/2011 04:48 PM, Guennadi Liakhovetski wrote:
> Currently only very few drivers actually use video_device nodes, embedded
> in struct v4l2_subdev. Allocate these nodes dynamically for those drivers
> to save memory for the rest.
>
> Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
I have tested this patch with Samsung FIMC driver and with MC enabled
sensor driver.
After some hundreds of module load/unload I didn't observe anything unusual.
The patch seem to be safe for device node enabled subdevs. You can stick my:
Tested-by: Sylwester Nawrocki <s.nawrocki@samsung.com>
if you feel so.
Thanks,
Sylwester Nawrocki
Samsung Poland R&D Center
> ---
>
> v4:
>
> 1. added "static" in v4l2_device_release_subdev_node() definition
> 2. removed superfluous get_device() and put_device() (thanks to Laurent
> for pointing out)
>
> drivers/media/video/v4l2-device.c | 36 +++++++++++++++++++++++++++++++-----
> include/media/v4l2-subdev.h | 4 ++--
> 2 files changed, 33 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/media/video/v4l2-device.c b/drivers/media/video/v4l2-device.c
> index c72856c..8abf830 100644
> --- a/drivers/media/video/v4l2-device.c
> +++ b/drivers/media/video/v4l2-device.c
> @@ -21,6 +21,7 @@
> #include <linux/types.h>
> #include <linux/ioctl.h>
> #include <linux/i2c.h>
> +#include <linux/slab.h>
> #if defined(CONFIG_SPI)
> #include <linux/spi/spi.h>
> #endif
> @@ -191,6 +192,13 @@ 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;
> @@ -204,22 +212,40 @@ int v4l2_device_register_subdev_nodes(struct v4l2_device *v4l2_dev)
> if (!(sd->flags & V4L2_SUBDEV_FL_HAS_DEVNODE))
> continue;
>
> - vdev = &sd->devnode;
> + vdev = kzalloc(sizeof(*vdev), GFP_KERNEL);
> + if (!vdev) {
> + err = -ENOMEM;
> + goto clean_up;
> + }
> +
> + video_set_drvdata(vdev, sd);
> strlcpy(vdev->name, sd->name, sizeof(vdev->name));
> vdev->v4l2_dev = v4l2_dev;
> vdev->fops = &v4l2_subdev_fops;
> - vdev->release = video_device_release_empty;
> + vdev->release = v4l2_device_release_subdev_node;
> vdev->ctrl_handler = sd->ctrl_handler;
> err = __video_register_device(vdev, VFL_TYPE_SUBDEV, -1, 1,
> sd->owner);
> - if (err < 0)
> - return err;
> + if (err < 0) {
> + kfree(vdev);
> + goto clean_up;
> + }
> #if defined(CONFIG_MEDIA_CONTROLLER)
> sd->entity.v4l.major = VIDEO_MAJOR;
> sd->entity.v4l.minor = vdev->minor;
> #endif
> + sd->devnode = vdev;
> }
> return 0;
> +
> +clean_up:
> + list_for_each_entry(sd, &v4l2_dev->subdevs, list) {
> + if (!sd->devnode)
> + break;
> + video_unregister_device(sd->devnode);
> + }
> +
> + return err;
> }
> EXPORT_SYMBOL_GPL(v4l2_device_register_subdev_nodes);
>
> @@ -245,7 +271,7 @@ void v4l2_device_unregister_subdev(struct v4l2_subdev *sd)
> if (v4l2_dev->mdev)
> media_device_unregister_entity(&sd->entity);
> #endif
> - video_unregister_device(&sd->devnode);
> + video_unregister_device(sd->devnode);
> module_put(sd->owner);
> }
> EXPORT_SYMBOL_GPL(v4l2_device_unregister_subdev);
> diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h
> index 257da1a..5dd049a 100644
> --- a/include/media/v4l2-subdev.h
> +++ b/include/media/v4l2-subdev.h
> @@ -534,13 +534,13 @@ struct v4l2_subdev {
> void *dev_priv;
> void *host_priv;
> /* subdev device node */
> - struct video_device devnode;
> + struct video_device *devnode;
> };
>
> #define media_entity_to_v4l2_subdev(ent) \
> container_of(ent, struct v4l2_subdev, entity)
> #define vdev_to_v4l2_subdev(vdev) \
> - container_of(vdev, struct v4l2_subdev, devnode)
> + video_get_drvdata(vdev)
>
> /*
> * Used for storing subdev information per file handle
--
Sylwester Nawrocki
Samsung Poland R&D Center
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v4] V4L: dynamically allocate video_device nodes in subdevices
2011-09-13 17:51 ` Sylwester Nawrocki
@ 2011-09-13 21:18 ` Guennadi Liakhovetski
2011-09-14 10:37 ` Sylwester Nawrocki
0 siblings, 1 reply; 15+ messages in thread
From: Guennadi Liakhovetski @ 2011-09-13 21:18 UTC (permalink / raw)
To: Sylwester Nawrocki
Cc: Laurent Pinchart, Linux Media Mailing List, Hans Verkuil
Hi Sylwester
On Tue, 13 Sep 2011, Sylwester Nawrocki wrote:
> Hi Guennadi,
>
> On 09/13/2011 04:48 PM, Guennadi Liakhovetski wrote:
> > Currently only very few drivers actually use video_device nodes, embedded
> > in struct v4l2_subdev. Allocate these nodes dynamically for those drivers
> > to save memory for the rest.
> >
> > Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
>
> I have tested this patch with Samsung FIMC driver and with MC enabled
> sensor driver.
> After some hundreds of module load/unload I didn't observe anything unusual.
> The patch seem to be safe for device node enabled subdevs. You can stick my:
>
> Tested-by: Sylwester Nawrocki <s.nawrocki@samsung.com>
>
> if you feel so.
Thanks very much for testing! However, depending on your test scenario,
you might still not notice a problem by just loading and unloading of
modules. It would, however, be useful to execute just one test:
1. add one line v4l2-device.c:
diff --git a/drivers/media/video/v4l2-device.c b/drivers/media/video/v4l2-device.c
index a3b89f4..33226857 100644
--- a/drivers/media/video/v4l2-device.c
+++ b/drivers/media/video/v4l2-device.c
@@ -195,6 +195,7 @@ 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);
+ dev_info(&vdev->dev, "%s()\n", __func__);
sd->devnode = NULL;
kfree(vdev);
}
2. with this patch start and stop capture
3. check dmesg - v4l2_device_release_subdev_node() output should not be
there yet
4. rmmod modules, then the output should be there
If you could test that - that would be great!
Thanks
Guennadi
> Thanks,
> Sylwester Nawrocki
> Samsung Poland R&D Center
>
> > ---
> >
> > v4:
> >
> > 1. added "static" in v4l2_device_release_subdev_node() definition
> > 2. removed superfluous get_device() and put_device() (thanks to Laurent
> > for pointing out)
> >
> > drivers/media/video/v4l2-device.c | 36 +++++++++++++++++++++++++++++++-----
> > include/media/v4l2-subdev.h | 4 ++--
> > 2 files changed, 33 insertions(+), 7 deletions(-)
> >
> > diff --git a/drivers/media/video/v4l2-device.c b/drivers/media/video/v4l2-device.c
> > index c72856c..8abf830 100644
> > --- a/drivers/media/video/v4l2-device.c
> > +++ b/drivers/media/video/v4l2-device.c
> > @@ -21,6 +21,7 @@
> > #include <linux/types.h>
> > #include <linux/ioctl.h>
> > #include <linux/i2c.h>
> > +#include <linux/slab.h>
> > #if defined(CONFIG_SPI)
> > #include <linux/spi/spi.h>
> > #endif
> > @@ -191,6 +192,13 @@ 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;
> > @@ -204,22 +212,40 @@ int v4l2_device_register_subdev_nodes(struct v4l2_device *v4l2_dev)
> > if (!(sd->flags & V4L2_SUBDEV_FL_HAS_DEVNODE))
> > continue;
> >
> > - vdev = &sd->devnode;
> > + vdev = kzalloc(sizeof(*vdev), GFP_KERNEL);
> > + if (!vdev) {
> > + err = -ENOMEM;
> > + goto clean_up;
> > + }
> > +
> > + video_set_drvdata(vdev, sd);
> > strlcpy(vdev->name, sd->name, sizeof(vdev->name));
> > vdev->v4l2_dev = v4l2_dev;
> > vdev->fops = &v4l2_subdev_fops;
> > - vdev->release = video_device_release_empty;
> > + vdev->release = v4l2_device_release_subdev_node;
> > vdev->ctrl_handler = sd->ctrl_handler;
> > err = __video_register_device(vdev, VFL_TYPE_SUBDEV, -1, 1,
> > sd->owner);
> > - if (err < 0)
> > - return err;
> > + if (err < 0) {
> > + kfree(vdev);
> > + goto clean_up;
> > + }
> > #if defined(CONFIG_MEDIA_CONTROLLER)
> > sd->entity.v4l.major = VIDEO_MAJOR;
> > sd->entity.v4l.minor = vdev->minor;
> > #endif
> > + sd->devnode = vdev;
> > }
> > return 0;
> > +
> > +clean_up:
> > + list_for_each_entry(sd, &v4l2_dev->subdevs, list) {
> > + if (!sd->devnode)
> > + break;
> > + video_unregister_device(sd->devnode);
> > + }
> > +
> > + return err;
> > }
> > EXPORT_SYMBOL_GPL(v4l2_device_register_subdev_nodes);
> >
> > @@ -245,7 +271,7 @@ void v4l2_device_unregister_subdev(struct v4l2_subdev *sd)
> > if (v4l2_dev->mdev)
> > media_device_unregister_entity(&sd->entity);
> > #endif
> > - video_unregister_device(&sd->devnode);
> > + video_unregister_device(sd->devnode);
> > module_put(sd->owner);
> > }
> > EXPORT_SYMBOL_GPL(v4l2_device_unregister_subdev);
> > diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h
> > index 257da1a..5dd049a 100644
> > --- a/include/media/v4l2-subdev.h
> > +++ b/include/media/v4l2-subdev.h
> > @@ -534,13 +534,13 @@ struct v4l2_subdev {
> > void *dev_priv;
> > void *host_priv;
> > /* subdev device node */
> > - struct video_device devnode;
> > + struct video_device *devnode;
> > };
> >
> > #define media_entity_to_v4l2_subdev(ent) \
> > container_of(ent, struct v4l2_subdev, entity)
> > #define vdev_to_v4l2_subdev(vdev) \
> > - container_of(vdev, struct v4l2_subdev, devnode)
> > + video_get_drvdata(vdev)
> >
> > /*
> > * Used for storing subdev information per file handle
>
>
> --
> Sylwester Nawrocki
> Samsung Poland R&D Center
>
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/
^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [PATCH v4] V4L: dynamically allocate video_device nodes in subdevices
2011-09-13 21:18 ` Guennadi Liakhovetski
@ 2011-09-14 10:37 ` Sylwester Nawrocki
0 siblings, 0 replies; 15+ messages in thread
From: Sylwester Nawrocki @ 2011-09-14 10:37 UTC (permalink / raw)
To: Guennadi Liakhovetski
Cc: Laurent Pinchart, Linux Media Mailing List, Hans Verkuil
Hi Guennadi,
On 09/13/2011 11:18 PM, Guennadi Liakhovetski wrote:
> On Tue, 13 Sep 2011, Sylwester Nawrocki wrote:
>> On 09/13/2011 04:48 PM, Guennadi Liakhovetski wrote:
>>> Currently only very few drivers actually use video_device nodes, embedded
>>> in struct v4l2_subdev. Allocate these nodes dynamically for those drivers
>>> to save memory for the rest.
>>>
>>> Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
>>
>> I have tested this patch with Samsung FIMC driver and with MC enabled
>> sensor driver.
>> After some hundreds of module load/unload I didn't observe anything unusual.
>> The patch seem to be safe for device node enabled subdevs. You can stick my:
>>
>> Tested-by: Sylwester Nawrocki <s.nawrocki@samsung.com>
>>
>> if you feel so.
>
> Thanks very much for testing! However, depending on your test scenario,
> you might still not notice a problem by just loading and unloading of
> modules. It would, however, be useful to execute just one test:
>
> 1. add one line v4l2-device.c:
>
> diff --git a/drivers/media/video/v4l2-device.c b/drivers/media/video/v4l2-device.c
> index a3b89f4..33226857 100644
> --- a/drivers/media/video/v4l2-device.c
> +++ b/drivers/media/video/v4l2-device.c
> @@ -195,6 +195,7 @@ 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);
> + dev_info(&vdev->dev, "%s()\n", __func__);
> sd->devnode = NULL;
> kfree(vdev);
> }
>
> 2. with this patch start and stop capture
>
> 3. check dmesg - v4l2_device_release_subdev_node() output should not be
> there yet
>
> 4. rmmod modules, then the output should be there
>
> If you could test that - that would be great!
OK, I double checked if v4l2_device_release_subdev_node() is called at the right
time, i.e. I've also checked if the streaming works in between the module unload/load.
I'd added the printk and everything behaved as expected, other than I've tracked
down a few minor bugs in the drivers in the meantime;)
I'll keep your patch applied in my development tree.
Thanks,
--
Sylwester Nawrocki
Samsung Poland R&D Center
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v4] V4L: dynamically allocate video_device nodes in subdevices
2011-09-13 14:48 ` [PATCH v4] " Guennadi Liakhovetski
2011-09-13 17:51 ` Sylwester Nawrocki
@ 2011-09-13 17:52 ` Laurent Pinchart
2011-09-27 17:05 ` [PATCH v5] " Guennadi Liakhovetski
1 sibling, 1 reply; 15+ messages in thread
From: Laurent Pinchart @ 2011-09-13 17:52 UTC (permalink / raw)
To: Guennadi Liakhovetski; +Cc: Linux Media Mailing List, Hans Verkuil
Hi Guennadi,
On Tuesday 13 September 2011 16:48:10 Guennadi Liakhovetski wrote:
> Currently only very few drivers actually use video_device nodes, embedded
> in struct v4l2_subdev. Allocate these nodes dynamically for those drivers
> to save memory for the rest.
>
> Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
I will try to test the patch tomorrow on an OMAP3 system.
--
Regards,
Laurent Pinchart
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH v5] V4L: dynamically allocate video_device nodes in subdevices
2011-09-13 17:52 ` Laurent Pinchart
@ 2011-09-27 17:05 ` Guennadi Liakhovetski
0 siblings, 0 replies; 15+ messages in thread
From: Guennadi Liakhovetski @ 2011-09-27 17:05 UTC (permalink / raw)
To: Laurent Pinchart
Cc: Linux Media Mailing List, Hans Verkuil, Sylwester Nawrocki
Currently only very few drivers actually use video_device nodes, embedded
in struct v4l2_subdev. Allocate these nodes dynamically for those drivers
to save memory for the rest.
Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Tested-by: Sylwester Nawrocki <s.nawrocki@samsung.com>
---
v5: replace kzalloc() with video_device_alloc() and kfree() with
video_device_release(), no changes otherwise. I hope, I'm entitled to keep
the tested- and acked-by's;-)
drivers/media/video/v4l2-device.c | 36 +++++++++++++++++++++++++++++++-----
include/media/v4l2-subdev.h | 4 ++--
2 files changed, 33 insertions(+), 7 deletions(-)
diff --git a/drivers/media/video/v4l2-device.c b/drivers/media/video/v4l2-device.c
index c72856c..93c0350 100644
--- a/drivers/media/video/v4l2-device.c
+++ b/drivers/media/video/v4l2-device.c
@@ -21,6 +21,7 @@
#include <linux/types.h>
#include <linux/ioctl.h>
#include <linux/i2c.h>
+#include <linux/slab.h>
#if defined(CONFIG_SPI)
#include <linux/spi/spi.h>
#endif
@@ -191,6 +192,13 @@ 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;
+ video_device_release(vdev);
+}
+
int v4l2_device_register_subdev_nodes(struct v4l2_device *v4l2_dev)
{
struct video_device *vdev;
@@ -204,22 +212,40 @@ int v4l2_device_register_subdev_nodes(struct v4l2_device *v4l2_dev)
if (!(sd->flags & V4L2_SUBDEV_FL_HAS_DEVNODE))
continue;
- vdev = &sd->devnode;
+ vdev = video_device_alloc();
+ if (!vdev) {
+ err = -ENOMEM;
+ goto clean_up;
+ }
+
+ video_set_drvdata(vdev, sd);
strlcpy(vdev->name, sd->name, sizeof(vdev->name));
vdev->v4l2_dev = v4l2_dev;
vdev->fops = &v4l2_subdev_fops;
- vdev->release = video_device_release_empty;
+ vdev->release = v4l2_device_release_subdev_node;
vdev->ctrl_handler = sd->ctrl_handler;
err = __video_register_device(vdev, VFL_TYPE_SUBDEV, -1, 1,
sd->owner);
- if (err < 0)
- return err;
+ if (err < 0) {
+ video_device_release(vdev);
+ goto clean_up;
+ }
#if defined(CONFIG_MEDIA_CONTROLLER)
sd->entity.v4l.major = VIDEO_MAJOR;
sd->entity.v4l.minor = vdev->minor;
#endif
+ sd->devnode = vdev;
}
return 0;
+
+clean_up:
+ list_for_each_entry(sd, &v4l2_dev->subdevs, list) {
+ if (!sd->devnode)
+ break;
+ video_unregister_device(sd->devnode);
+ }
+
+ return err;
}
EXPORT_SYMBOL_GPL(v4l2_device_register_subdev_nodes);
@@ -245,7 +271,7 @@ void v4l2_device_unregister_subdev(struct v4l2_subdev *sd)
if (v4l2_dev->mdev)
media_device_unregister_entity(&sd->entity);
#endif
- video_unregister_device(&sd->devnode);
+ video_unregister_device(sd->devnode);
module_put(sd->owner);
}
EXPORT_SYMBOL_GPL(v4l2_device_unregister_subdev);
diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h
index 257da1a..5dd049a 100644
--- a/include/media/v4l2-subdev.h
+++ b/include/media/v4l2-subdev.h
@@ -534,13 +534,13 @@ struct v4l2_subdev {
void *dev_priv;
void *host_priv;
/* subdev device node */
- struct video_device devnode;
+ struct video_device *devnode;
};
#define media_entity_to_v4l2_subdev(ent) \
container_of(ent, struct v4l2_subdev, entity)
#define vdev_to_v4l2_subdev(vdev) \
- container_of(vdev, struct v4l2_subdev, devnode)
+ video_get_drvdata(vdev)
/*
* Used for storing subdev information per file handle
--
1.7.2.5
^ permalink raw reply related [flat|nested] 15+ messages in thread
end of thread, other threads:[~2011-09-27 17:05 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-09 15:02 [PATCH] V4L: dynamically allocate video_device nodes in subdevices Guennadi Liakhovetski
2011-09-09 17:45 ` [PATCH v2] " Guennadi Liakhovetski
2011-09-09 21:32 ` Laurent Pinchart
2011-09-10 10:27 ` Guennadi Liakhovetski
2011-09-12 10:55 ` [PATCH v3] " Guennadi Liakhovetski
2011-09-13 9:16 ` Laurent Pinchart
2011-09-13 9:26 ` Guennadi Liakhovetski
2011-09-13 9:45 ` Laurent Pinchart
2011-09-13 14:15 ` Guennadi Liakhovetski
2011-09-13 14:48 ` [PATCH v4] " Guennadi Liakhovetski
2011-09-13 17:51 ` Sylwester Nawrocki
2011-09-13 21:18 ` Guennadi Liakhovetski
2011-09-14 10:37 ` Sylwester Nawrocki
2011-09-13 17:52 ` Laurent Pinchart
2011-09-27 17:05 ` [PATCH v5] " Guennadi Liakhovetski
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.