Skip to content

Commit

Permalink
media: stm32: dcmi: kcalloc v4l2_async_subdev struct
Browse files Browse the repository at this point in the history
Upon cleanup of the v4l2 async notify mechanism in
__v4l2_async_notifier_cleanup, the asd element provided by the
driver is being kfree by the V4L2 framework.

Current code was providing a v4l2_async_subdev struct part of the
stm32_dcmi struct, leading to kmemleak complaining whenever
v4l2_async_notifier_cleanup is called on unbind.

Allocate this structure now to avoid this error.  Allocation is
done via kcalloc (and not devm_kcalloc) on purpose since kfree
is used by the framework.

Signed-off-by: Alain Volmat <[email protected]>
Change-Id: I0159571a792d2009b951e62c768caae17fd9a8da
Reviewed-on: https://gerrit.st.com/c/mpu/oe/st/linux-stm32/+/324941
Tested-by: Hugues FRUCHET <[email protected]>
Domain-Review: Hugues FRUCHET <[email protected]>
Domain-Review: Philippe CORNU <[email protected]>
Reviewed-by: Philippe CORNU <[email protected]>
Reviewed-by: Hugues FRUCHET <[email protected]>
ACI: CITOOLS <[email protected]>
  • Loading branch information
Alain Volmat authored and ashishverma2691 committed Sep 13, 2023
1 parent c55cd25 commit 8904597
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions drivers/media/platform/stm32/stm32-dcmi.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ enum state {
#define OVERRUN_ERROR_THRESHOLD 3

struct dcmi_graph_entity {
struct v4l2_async_subdev asd;
struct v4l2_async_subdev *asd;

struct device_node *remote_node;
struct v4l2_subdev *source;
Expand Down Expand Up @@ -1896,6 +1896,7 @@ static int dcmi_graph_parse(struct stm32_dcmi *dcmi, struct device_node *node)
{
struct device_node *ep = NULL;
struct device_node *remote;
struct v4l2_async_subdev *asd;

ep = of_graph_get_next_endpoint(node, ep);
if (!ep)
Expand All @@ -1906,10 +1907,18 @@ static int dcmi_graph_parse(struct stm32_dcmi *dcmi, struct device_node *node)
if (!remote)
return -EINVAL;

asd = kcalloc(1, sizeof(struct v4l2_async_subdev), GFP_KERNEL);
if (!asd) {
of_node_put(remote);
return -ENOMEM;
}

/* Remote node to connect */
dcmi->entity.remote_node = remote;
dcmi->entity.asd.match_type = V4L2_ASYNC_MATCH_FWNODE;
dcmi->entity.asd.match.fwnode = of_fwnode_handle(remote);
asd->match_type = V4L2_ASYNC_MATCH_FWNODE;
asd->match.fwnode = of_fwnode_handle(remote);
dcmi->entity.asd = asd;

return 0;
}

Expand All @@ -1926,8 +1935,7 @@ static int dcmi_graph_init(struct stm32_dcmi *dcmi)

v4l2_async_notifier_init(&dcmi->notifier);

ret = v4l2_async_notifier_add_subdev(&dcmi->notifier,
&dcmi->entity.asd);
ret = v4l2_async_notifier_add_subdev(&dcmi->notifier, dcmi->entity.asd);
if (ret) {
dev_err(dcmi->dev, "Failed to add subdev notifier\n");
of_node_put(dcmi->entity.remote_node);
Expand Down

0 comments on commit 8904597

Please sign in to comment.