media: ti-vpe: cal: fix a kernel oops when unloading module
Subsystems (2)
PATCH v2 1/1 media: ti-vpe: cal: fix a kernel oops when unloading module
After the switch to use v4l2_async_notifier_add_subdev() and v4l2_async_notifier_cleanup(), unloading the ti_cal module would casue a kernel oops.
This was root cause to the fact that v4l2_async_notifier_cleanup() tries to kfree the asd pointer passed into v4l2_async_notifier_add_subdev().
In our case the asd reference was from a statically allocated struct. So in effect v4l2_async_notifier_cleanup() was trying to free a pointer that was not kalloc.
So here we switch to using a kzalloc struct instead of a static one. To acheive this we re-order some of the calls to prevent asd allocation from leaking.
---
Changes since v1:
- fix asd allocation leak
drivers/media/platform/ti-vpe/cal.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/media/platform/ti-vpe/cal.c +8 -5
@@ -372,8 +372,6 @@ struct cal_ctx {struct v4l2_subdev *sensor;struct v4l2_fwnode_endpoint endpoint; -struct v4l2_async_subdev asd; -struct v4l2_fh fh;struct cal_dev *dev;struct cc_data *cc;
@@ -2032,7 +2030,6 @@ static int of_cal_create_instance(struct cal_ctx *ctx, int inst) parent = pdev->dev.of_node; - asd = &ctx->asd; endpoint = &ctx->endpoint; ep_node =NULL ;
@@ -2079,8 +2076,6 @@ static int of_cal_create_instance(struct cal_ctx *ctx, int inst)ctx_dbg (3 , ctx,"can't get remote parent\n" ); goto cleanup_exit; } - asd->match_type =V4L2_ASYNC_MATCH_FWNODE ; - asd->match.fwnode =of_fwnode_handle (sensor_node);v4l2_fwnode_endpoint_parse (of_fwnode_handle (ep_node), endpoint);
@@ -2110,9 +2105,17 @@ static int of_cal_create_instance(struct cal_ctx *ctx, int inst)v4l2_async_notifier_init (&ctx->notifier); + asd =kzalloc (sizeof (*asd),GFP_KERNEL ); +if (!asd) + goto cleanup_exit; + + asd->match_type =V4L2_ASYNC_MATCH_FWNODE ; + asd->match.fwnode =of_fwnode_handle (sensor_node); + ret =v4l2_async_notifier_add_subdev (&ctx->notifier, asd);if (ret) {ctx_err (ctx,"Error adding asd\n" ); +kfree (asd); goto cleanup_exit; }
Signature · 1 line
2.17.1
Quoted 17 lines · Benoit Parrot
After the switch to use
v4l2_async_notifier_add_subdev()andv4l2_async_notifier_cleanup(), unloading theti_calmodule would casue a kernel oops.This was root cause to the fact that
v4l2_async_notifier_cleanup()tries to kfree the asd pointer passed intov4l2_async_notifier_add_subdev().In our case the asd reference was from a statically allocated struct. So in effect
v4l2_async_notifier_cleanup()was trying to free a pointer that was not kalloc.So here we switch to using a kzalloc struct instead of a static one. To acheive this we re-order some of the calls to prevent asd allocation from leaking.
Fixes d079f94c9046 ("media: platform: Switch to v4l2_async_notifier_add_subdev")
Quoted 8 lines
Signed-off-by Benoit Parrot <[email protected]>---
Changes since v1:
- fix asd allocation leakdrivers/media/platform/ti-vpe/cal.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
Tomi
Signature · 2 lines
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki