Skip to content

Commit

Permalink
media: imx: Move capture device init to registered
Browse files Browse the repository at this point in the history
If the CSI is unregistered and then registered again without the
driver being removed and re-probed (which will happen when the media
device is removed and re-probed without also removing/re-probing the
CSI), the result is the kobject error and backtrace "tried to init an
initialized object". This is because the video device is left in an
initialized state after being unregistered, thus the video device's
underlying kobject is also left in an initialized state when the device
is registered again.

Fix this by moving imx_media_capture_device_init() and _remove()
into csi_registered() and csi_unregistered(). This will create a new
un-initialized video device when the CSI is re-registered. Do this for
all the subdevices that register a capture device.

Reported-by: Russell King <[email protected]>
Signed-off-by: Steve Longerbeam <[email protected]>
Signed-off-by: Hans Verkuil <[email protected]>
Signed-off-by: Mauro Carvalho Chehab <[email protected]>
  • Loading branch information
slongerbeam authored and mchehab committed Oct 10, 2019
1 parent dbb8d05 commit 1f46424
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 29 deletions.
25 changes: 15 additions & 10 deletions drivers/staging/media/imx/imx-ic-prpencvf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1246,6 +1246,7 @@ static int prp_s_frame_interval(struct v4l2_subdev *sd,
static int prp_registered(struct v4l2_subdev *sd)
{
struct prp_priv *priv = sd_to_priv(sd);
struct imx_ic_priv *ic_priv = priv->ic_priv;
int i, ret;
u32 code;

Expand All @@ -1271,17 +1272,26 @@ static int prp_registered(struct v4l2_subdev *sd)
if (ret)
return ret;

priv->vdev = imx_media_capture_device_init(ic_priv->ipu_dev,
&ic_priv->sd,
PRPENCVF_SRC_PAD);
if (IS_ERR(priv->vdev))
return PTR_ERR(priv->vdev);

ret = imx_media_capture_device_register(priv->vdev);
if (ret)
return ret;
goto remove_vdev;

ret = prp_init_controls(priv);
if (ret)
goto unreg;
goto unreg_vdev;

return 0;
unreg:

unreg_vdev:
imx_media_capture_device_unregister(priv->vdev);
remove_vdev:
imx_media_capture_device_remove(priv->vdev);
return ret;
}

Expand All @@ -1290,6 +1300,8 @@ static void prp_unregistered(struct v4l2_subdev *sd)
struct prp_priv *priv = sd_to_priv(sd);

imx_media_capture_device_unregister(priv->vdev);
imx_media_capture_device_remove(priv->vdev);

v4l2_ctrl_handler_free(&priv->ctrl_hdlr);
}

Expand Down Expand Up @@ -1336,12 +1348,6 @@ static int prp_init(struct imx_ic_priv *ic_priv)
spin_lock_init(&priv->irqlock);
timer_setup(&priv->eof_timeout_timer, prp_eof_timeout, 0);

priv->vdev = imx_media_capture_device_init(ic_priv->ipu_dev,
&ic_priv->sd,
PRPENCVF_SRC_PAD);
if (IS_ERR(priv->vdev))
return PTR_ERR(priv->vdev);

mutex_init(&priv->lock);

return 0;
Expand All @@ -1352,7 +1358,6 @@ static void prp_remove(struct imx_ic_priv *ic_priv)
struct prp_priv *priv = ic_priv->task_priv;

mutex_destroy(&priv->lock);
imx_media_capture_device_remove(priv->vdev);
}

struct imx_ic_ops imx_ic_prpencvf_ops = {
Expand Down
20 changes: 12 additions & 8 deletions drivers/staging/media/imx/imx-media-csi.c
Original file line number Diff line number Diff line change
Expand Up @@ -1797,12 +1797,22 @@ static int csi_registered(struct v4l2_subdev *sd)
if (ret)
goto free_fim;

priv->vdev = imx_media_capture_device_init(priv->sd.dev,
&priv->sd,
CSI_SRC_PAD_IDMAC);
if (IS_ERR(priv->vdev)) {
ret = PTR_ERR(priv->vdev);
goto free_fim;
}

ret = imx_media_capture_device_register(priv->vdev);
if (ret)
goto free_fim;
goto remove_vdev;

return 0;

remove_vdev:
imx_media_capture_device_remove(priv->vdev);
free_fim:
if (priv->fim)
imx_media_fim_free(priv->fim);
Expand All @@ -1816,6 +1826,7 @@ static void csi_unregistered(struct v4l2_subdev *sd)
struct csi_priv *priv = v4l2_get_subdevdata(sd);

imx_media_capture_device_unregister(priv->vdev);
imx_media_capture_device_remove(priv->vdev);

if (priv->fim)
imx_media_fim_free(priv->fim);
Expand Down Expand Up @@ -1963,11 +1974,6 @@ static int imx_csi_probe(struct platform_device *pdev)
imx_media_grp_id_to_sd_name(priv->sd.name, sizeof(priv->sd.name),
priv->sd.grp_id, ipu_get_num(priv->ipu));

priv->vdev = imx_media_capture_device_init(priv->sd.dev, &priv->sd,
CSI_SRC_PAD_IDMAC);
if (IS_ERR(priv->vdev))
return PTR_ERR(priv->vdev);

mutex_init(&priv->lock);

v4l2_ctrl_handler_init(&priv->ctrl_hdlr, 0);
Expand Down Expand Up @@ -1997,7 +2003,6 @@ static int imx_csi_probe(struct platform_device *pdev)
free:
v4l2_ctrl_handler_free(&priv->ctrl_hdlr);
mutex_destroy(&priv->lock);
imx_media_capture_device_remove(priv->vdev);
return ret;
}

Expand All @@ -2008,7 +2013,6 @@ static int imx_csi_remove(struct platform_device *pdev)

v4l2_ctrl_handler_free(&priv->ctrl_hdlr);
mutex_destroy(&priv->lock);
imx_media_capture_device_remove(priv->vdev);
v4l2_async_unregister_subdev(sd);
media_entity_cleanup(&sd->entity);

Expand Down
22 changes: 11 additions & 11 deletions drivers/staging/media/imx/imx7-media-csi.c
Original file line number Diff line number Diff line change
Expand Up @@ -1119,14 +1119,24 @@ static int imx7_csi_registered(struct v4l2_subdev *sd)
if (ret < 0)
return ret;

return imx_media_capture_device_register(csi->vdev);
csi->vdev = imx_media_capture_device_init(csi->sd.dev, &csi->sd,
IMX7_CSI_PAD_SRC);
if (IS_ERR(csi->vdev))
return PTR_ERR(csi->vdev);

ret = imx_media_capture_device_register(csi->vdev);
if (ret)
imx_media_capture_device_remove(csi->vdev);

return ret;
}

static void imx7_csi_unregistered(struct v4l2_subdev *sd)
{
struct imx7_csi *csi = v4l2_get_subdevdata(sd);

imx_media_capture_device_unregister(csi->vdev);
imx_media_capture_device_remove(csi->vdev);
}

static int imx7_csi_init_cfg(struct v4l2_subdev *sd,
Expand Down Expand Up @@ -1251,11 +1261,6 @@ static int imx7_csi_probe(struct platform_device *pdev)
csi->sd.grp_id = IMX_MEDIA_GRP_ID_CSI;
snprintf(csi->sd.name, sizeof(csi->sd.name), "csi");

csi->vdev = imx_media_capture_device_init(csi->sd.dev, &csi->sd,
IMX7_CSI_PAD_SRC);
if (IS_ERR(csi->vdev))
return PTR_ERR(csi->vdev);

v4l2_ctrl_handler_init(&csi->ctrl_hdlr, 0);
csi->sd.ctrl_handler = &csi->ctrl_hdlr;

Expand All @@ -1269,8 +1274,6 @@ static int imx7_csi_probe(struct platform_device *pdev)
return 0;

free:
imx_media_capture_device_unregister(csi->vdev);
imx_media_capture_device_remove(csi->vdev);
v4l2_ctrl_handler_free(&csi->ctrl_hdlr);

cleanup:
Expand Down Expand Up @@ -1298,9 +1301,6 @@ static int imx7_csi_remove(struct platform_device *pdev)
v4l2_device_unregister(&imxmd->v4l2_dev);
media_device_cleanup(&imxmd->md);

imx_media_capture_device_unregister(csi->vdev);
imx_media_capture_device_remove(csi->vdev);

v4l2_async_unregister_subdev(sd);
v4l2_ctrl_handler_free(&csi->ctrl_hdlr);

Expand Down

0 comments on commit 1f46424

Please sign in to comment.