All of lore.kernel.org
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
Cc: Linux Media Mailing List <linux-media@vger.kernel.org>,
	Hans Verkuil <hverkuil@xs4all.nl>
Subject: Re: [PATCH v3] V4L: dynamically allocate video_device nodes in subdevices
Date: Tue, 13 Sep 2011 11:16:35 +0200	[thread overview]
Message-ID: <201109131116.35408.laurent.pinchart@ideasonboard.com> (raw)
In-Reply-To: <Pine.LNX.4.64.1109121253270.9638@axis700.grange>

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

  reply	other threads:[~2011-09-13  9:16 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

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=201109131116.35408.laurent.pinchart@ideasonboard.com \
    --to=laurent.pinchart@ideasonboard.com \
    --cc=g.liakhovetski@gmx.de \
    --cc=hverkuil@xs4all.nl \
    --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 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.