[PATCH v3 11/17] media: imx: csi: Embed notifier in struct csi_priv

From: Steve Longerbeam
Date: Tue Feb 04 2020 - 18:50:21 EST


Embed the notifier in 'struct csi_priv', instead of dynamically allocating
it, to make it possible to retrieve csi_priv in a notifier callback op.

Signed-off-by: Steve Longerbeam <slongerbeam@xxxxxxxxx>
---
drivers/staging/media/imx/imx-media-csi.c | 25 +++++++++--------------
1 file changed, 10 insertions(+), 15 deletions(-)

diff --git a/drivers/staging/media/imx/imx-media-csi.c b/drivers/staging/media/imx/imx-media-csi.c
index dc5fe25fe7b8..3e2afdd59276 100644
--- a/drivers/staging/media/imx/imx-media-csi.c
+++ b/drivers/staging/media/imx/imx-media-csi.c
@@ -58,6 +58,8 @@ struct csi_priv {
struct ipu_soc *ipu;
struct v4l2_subdev sd;
struct media_pad pad[CSI_NUM_PADS];
+ struct v4l2_async_notifier notifier;
+
/* the video device at IDMAC output pad */
struct imx_media_video_dev *vdev;
struct imx_media_fim *fim;
@@ -1896,31 +1898,28 @@ static int imx_csi_parse_endpoint(struct device *dev,

static int imx_csi_async_register(struct csi_priv *priv)
{
- struct v4l2_async_notifier *notifier;
struct fwnode_handle *fwnode;
unsigned int port;
int ret;

- notifier = kzalloc(sizeof(*notifier), GFP_KERNEL);
- if (!notifier)
- return -ENOMEM;
-
- v4l2_async_notifier_init(notifier);
+ v4l2_async_notifier_init(&priv->notifier);

fwnode = dev_fwnode(priv->dev);

/* get this CSI's port id */
ret = fwnode_property_read_u32(fwnode, "reg", &port);
if (ret < 0)
- goto out_free;
+ return ret;

ret = v4l2_async_notifier_parse_fwnode_endpoints_by_port(
- priv->dev->parent, notifier, sizeof(struct v4l2_async_subdev),
+ priv->dev->parent, &priv->notifier,
+ sizeof(struct v4l2_async_subdev),
port, imx_csi_parse_endpoint);
if (ret < 0)
goto out_cleanup;

- ret = v4l2_async_subdev_notifier_register(&priv->sd, notifier);
+ ret = v4l2_async_subdev_notifier_register(&priv->sd,
+ &priv->notifier);
if (ret < 0)
goto out_cleanup;

@@ -1928,16 +1927,12 @@ static int imx_csi_async_register(struct csi_priv *priv)
if (ret < 0)
goto out_unregister;

- priv->sd.subdev_notifier = notifier;
-
return 0;

out_unregister:
- v4l2_async_notifier_unregister(notifier);
+ v4l2_async_notifier_unregister(&priv->notifier);
out_cleanup:
- v4l2_async_notifier_cleanup(notifier);
-out_free:
- kfree(notifier);
+ v4l2_async_notifier_cleanup(&priv->notifier);

return ret;
}
--
2.17.1