Commit 9e67f24e authored by Tomi Valkeinen's avatar Tomi Valkeinen Committed by Mauro Carvalho Chehab

media: ti-vpe: cal: fix ctx uninitialization

Somewhere along the way the context uninitialization has gone a bit odd:

* We have cal_ctx_create() but no matching destroy call, but we still
need to call cal_ctx_v4l2_cleanup() for each context.

* We have cal_media_cleanup() which calls cal_ctx_v4l2_cleanup() for all
contexts, but cal_media_init() is not where the contexts are created.

* The order of uninit steps in cal_remove() is different than the error
handling path in cal_probe().

* cal_probe()'s error handling calls cal_ctx_v4l2_cleanup() for each
context, but also calls cal_media_clean(), doing the same context
cleanup twice.

So fix these, by introducing cal_ctx_destroy(), and using that in
appropriate places instead of calling cal_ctx_v4l2_cleanup() in
cal_media_clean(). Also use normal kzalloc (and kfree) instead of devm
version as we anyway do manual cleanup for each context.
Signed-off-by: default avatarTomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: default avatarLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+huawei@kernel.org>
parent b65836f4
...@@ -908,11 +908,6 @@ static int cal_media_init(struct cal_dev *cal) ...@@ -908,11 +908,6 @@ static int cal_media_init(struct cal_dev *cal)
*/ */
static void cal_media_cleanup(struct cal_dev *cal) static void cal_media_cleanup(struct cal_dev *cal)
{ {
unsigned int i;
for (i = 0; i < cal->num_contexts; i++)
cal_ctx_v4l2_cleanup(cal->ctx[i]);
v4l2_device_unregister(&cal->v4l2_dev); v4l2_device_unregister(&cal->v4l2_dev);
media_device_cleanup(&cal->mdev); media_device_cleanup(&cal->mdev);
...@@ -929,7 +924,7 @@ static struct cal_ctx *cal_ctx_create(struct cal_dev *cal, int inst) ...@@ -929,7 +924,7 @@ static struct cal_ctx *cal_ctx_create(struct cal_dev *cal, int inst)
struct cal_ctx *ctx; struct cal_ctx *ctx;
int ret; int ret;
ctx = devm_kzalloc(cal->dev, sizeof(*ctx), GFP_KERNEL); ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
if (!ctx) if (!ctx)
return NULL; return NULL;
...@@ -948,6 +943,13 @@ static struct cal_ctx *cal_ctx_create(struct cal_dev *cal, int inst) ...@@ -948,6 +943,13 @@ static struct cal_ctx *cal_ctx_create(struct cal_dev *cal, int inst)
return ctx; return ctx;
} }
static void cal_ctx_destroy(struct cal_ctx *ctx)
{
cal_ctx_v4l2_cleanup(ctx);
kfree(ctx);
}
static const struct of_device_id cal_of_match[] = { static const struct of_device_id cal_of_match[] = {
{ {
.compatible = "ti,dra72-cal", .compatible = "ti,dra72-cal",
...@@ -1162,7 +1164,7 @@ static int cal_probe(struct platform_device *pdev) ...@@ -1162,7 +1164,7 @@ static int cal_probe(struct platform_device *pdev)
error_context: error_context:
for (i = 0; i < cal->num_contexts; i++) for (i = 0; i < cal->num_contexts; i++)
cal_ctx_v4l2_cleanup(cal->ctx[i]); cal_ctx_destroy(cal->ctx[i]);
error_camerarx: error_camerarx:
for (i = 0; i < cal->data->num_csi2_phy; i++) for (i = 0; i < cal->data->num_csi2_phy; i++)
...@@ -1191,11 +1193,14 @@ static int cal_remove(struct platform_device *pdev) ...@@ -1191,11 +1193,14 @@ static int cal_remove(struct platform_device *pdev)
for (i = 0; i < cal->data->num_csi2_phy; i++) for (i = 0; i < cal->data->num_csi2_phy; i++)
cal_camerarx_disable(cal->phy[i]); cal_camerarx_disable(cal->phy[i]);
cal_media_cleanup(cal); for (i = 0; i < cal->num_contexts; i++)
cal_ctx_destroy(cal->ctx[i]);
for (i = 0; i < cal->data->num_csi2_phy; i++) for (i = 0; i < cal->data->num_csi2_phy; i++)
cal_camerarx_destroy(cal->phy[i]); cal_camerarx_destroy(cal->phy[i]);
cal_media_cleanup(cal);
if (ret >= 0) if (ret >= 0)
pm_runtime_put_sync(&pdev->dev); pm_runtime_put_sync(&pdev->dev);
pm_runtime_disable(&pdev->dev); pm_runtime_disable(&pdev->dev);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment