Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f91fccde authored by Hans Verkuil's avatar Hans Verkuil Committed by Mauro Carvalho Chehab
Browse files

[media] dt3155v4l: embed video_device



Embed the video_device struct to simplify the error handling and in
order to (eventually) get rid of video_device_alloc/release.

Signed-off-by: default avatarHans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@osg.samsung.com>
parent 54ad7b9d
Loading
Loading
Loading
Loading
+10 −20
Original line number Original line Diff line number Diff line
@@ -244,7 +244,7 @@ dt3155_wait_prepare(struct vb2_queue *q)
{
{
	struct dt3155_priv *pd = vb2_get_drv_priv(q);
	struct dt3155_priv *pd = vb2_get_drv_priv(q);


	mutex_unlock(pd->vdev->lock);
	mutex_unlock(pd->vdev.lock);
}
}


static void
static void
@@ -252,7 +252,7 @@ dt3155_wait_finish(struct vb2_queue *q)
{
{
	struct dt3155_priv *pd = vb2_get_drv_priv(q);
	struct dt3155_priv *pd = vb2_get_drv_priv(q);


	mutex_lock(pd->vdev->lock);
	mutex_lock(pd->vdev.lock);
}
}


static int
static int
@@ -824,7 +824,7 @@ static struct video_device dt3155_vdev = {
	.fops = &dt3155_fops,
	.fops = &dt3155_fops,
	.ioctl_ops = &dt3155_ioctl_ops,
	.ioctl_ops = &dt3155_ioctl_ops,
	.minor = -1,
	.minor = -1,
	.release = video_device_release,
	.release = video_device_release_empty,
	.tvnorms = DT3155_CURRENT_NORM,
	.tvnorms = DT3155_CURRENT_NORM,
};
};


@@ -904,24 +904,21 @@ dt3155_probe(struct pci_dev *pdev, const struct pci_device_id *id)
	pd = devm_kzalloc(&pdev->dev, sizeof(*pd), GFP_KERNEL);
	pd = devm_kzalloc(&pdev->dev, sizeof(*pd), GFP_KERNEL);
	if (!pd)
	if (!pd)
		return -ENOMEM;
		return -ENOMEM;
	pd->vdev = video_device_alloc();
	if (!pd->vdev)
		return -ENOMEM;


	*pd->vdev = dt3155_vdev;
	pd->vdev = dt3155_vdev;
	pci_set_drvdata(pdev, pd);    /* for use in dt3155_remove() */
	pci_set_drvdata(pdev, pd);    /* for use in dt3155_remove() */
	video_set_drvdata(pd->vdev, pd);  /* for use in video_fops */
	video_set_drvdata(&pd->vdev, pd);  /* for use in video_fops */
	pd->users = 0;
	pd->users = 0;
	pd->pdev = pdev;
	pd->pdev = pdev;
	INIT_LIST_HEAD(&pd->dmaq);
	INIT_LIST_HEAD(&pd->dmaq);
	mutex_init(&pd->mux);
	mutex_init(&pd->mux);
	pd->vdev->lock = &pd->mux; /* for locking v4l2_file_operations */
	pd->vdev.lock = &pd->mux; /* for locking v4l2_file_operations */
	spin_lock_init(&pd->lock);
	spin_lock_init(&pd->lock);
	pd->csr2 = csr2_init;
	pd->csr2 = csr2_init;
	pd->config = config_init;
	pd->config = config_init;
	err = pci_enable_device(pdev);
	err = pci_enable_device(pdev);
	if (err)
	if (err)
		goto err_enable_dev;
		return err;
	err = pci_request_region(pdev, 0, pci_name(pdev));
	err = pci_request_region(pdev, 0, pci_name(pdev));
	if (err)
	if (err)
		goto err_req_region;
		goto err_req_region;
@@ -933,13 +930,13 @@ dt3155_probe(struct pci_dev *pdev, const struct pci_device_id *id)
	err = dt3155_init_board(pdev);
	err = dt3155_init_board(pdev);
	if (err)
	if (err)
		goto err_init_board;
		goto err_init_board;
	err = video_register_device(pd->vdev, VFL_TYPE_GRABBER, -1);
	err = video_register_device(&pd->vdev, VFL_TYPE_GRABBER, -1);
	if (err)
	if (err)
		goto err_init_board;
		goto err_init_board;
	if (dt3155_alloc_coherent(&pdev->dev, DT3155_CHUNK_SIZE,
	if (dt3155_alloc_coherent(&pdev->dev, DT3155_CHUNK_SIZE,
							DMA_MEMORY_MAP))
							DMA_MEMORY_MAP))
		dev_info(&pdev->dev, "preallocated 8 buffers\n");
		dev_info(&pdev->dev, "preallocated 8 buffers\n");
	dev_info(&pdev->dev, "/dev/video%i is ready\n", pd->vdev->minor);
	dev_info(&pdev->dev, "/dev/video%i is ready\n", pd->vdev.minor);
	return 0;  /*   success   */
	return 0;  /*   success   */


err_init_board:
err_init_board:
@@ -948,9 +945,6 @@ dt3155_probe(struct pci_dev *pdev, const struct pci_device_id *id)
	pci_release_region(pdev, 0);
	pci_release_region(pdev, 0);
err_req_region:
err_req_region:
	pci_disable_device(pdev);
	pci_disable_device(pdev);
err_enable_dev:
	video_device_release(pd->vdev);

	return err;
	return err;
}
}


@@ -960,14 +954,10 @@ dt3155_remove(struct pci_dev *pdev)
	struct dt3155_priv *pd = pci_get_drvdata(pdev);
	struct dt3155_priv *pd = pci_get_drvdata(pdev);


	dt3155_free_coherent(&pdev->dev);
	dt3155_free_coherent(&pdev->dev);
	video_unregister_device(pd->vdev);
	video_unregister_device(&pd->vdev);
	pci_iounmap(pdev, pd->regs);
	pci_iounmap(pdev, pd->regs);
	pci_release_region(pdev, 0);
	pci_release_region(pdev, 0);
	pci_disable_device(pdev);
	pci_disable_device(pdev);
	/*
	 * video_device_release() is invoked automatically
	 * see: struct video_device dt3155_vdev
	 */
}
}


static const struct pci_device_id pci_ids[] = {
static const struct pci_device_id pci_ids[] = {
+2 −2
Original line number Original line Diff line number Diff line
@@ -178,7 +178,7 @@ struct dt3155_stats {
/**
/**
 * struct dt3155_priv - private data structure
 * struct dt3155_priv - private data structure
 *
 *
 * @vdev:		pointer to video_device structure
 * @vdev:		video_device structure
 * @pdev:		pointer to pci_dev structure
 * @pdev:		pointer to pci_dev structure
 * @q			pointer to vb2_queue structure
 * @q			pointer to vb2_queue structure
 * @curr_buf:		pointer to curren buffer
 * @curr_buf:		pointer to curren buffer
@@ -193,7 +193,7 @@ struct dt3155_stats {
 * @config:		local copy of config register
 * @config:		local copy of config register
 */
 */
struct dt3155_priv {
struct dt3155_priv {
	struct video_device *vdev;
	struct video_device vdev;
	struct pci_dev *pdev;
	struct pci_dev *pdev;
	struct vb2_queue *q;
	struct vb2_queue *q;
	struct vb2_buffer *curr_buf;
	struct vb2_buffer *curr_buf;