Commit aead0ffb authored by Eugen Hristev's avatar Eugen Hristev Committed by Mauro Carvalho Chehab

media: v4l2-core: fix entity initialization in device_register_subdev

The entity variable was being initialized in the wrong place, before the
parameters have been checked.
To solve this, completely removed the entity variable and replaced it
with the initialization value : &sd->entity.
This will avoid dereferencing 'sd' pointer before it's being checked if
it's NULL.

Fixes: 61f5db54 ("[media] v4l: Make v4l2_subdev inherit from media_entity")
Signed-off-by: default avatarEugen Hristev <eugen.hristev@microchip.com>
Acked-by: default avatarSakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+huawei@kernel.org>
parent 6990570f
...@@ -111,9 +111,6 @@ EXPORT_SYMBOL_GPL(v4l2_device_unregister); ...@@ -111,9 +111,6 @@ EXPORT_SYMBOL_GPL(v4l2_device_unregister);
int v4l2_device_register_subdev(struct v4l2_device *v4l2_dev, int v4l2_device_register_subdev(struct v4l2_device *v4l2_dev,
struct v4l2_subdev *sd) struct v4l2_subdev *sd)
{ {
#if defined(CONFIG_MEDIA_CONTROLLER)
struct media_entity *entity = &sd->entity;
#endif
int err; int err;
/* Check for valid input */ /* Check for valid input */
...@@ -143,7 +140,7 @@ int v4l2_device_register_subdev(struct v4l2_device *v4l2_dev, ...@@ -143,7 +140,7 @@ int v4l2_device_register_subdev(struct v4l2_device *v4l2_dev,
#if defined(CONFIG_MEDIA_CONTROLLER) #if defined(CONFIG_MEDIA_CONTROLLER)
/* Register the entity. */ /* Register the entity. */
if (v4l2_dev->mdev) { if (v4l2_dev->mdev) {
err = media_device_register_entity(v4l2_dev->mdev, entity); err = media_device_register_entity(v4l2_dev->mdev, &sd->entity);
if (err < 0) if (err < 0)
goto error_module; goto error_module;
} }
...@@ -163,7 +160,7 @@ int v4l2_device_register_subdev(struct v4l2_device *v4l2_dev, ...@@ -163,7 +160,7 @@ int v4l2_device_register_subdev(struct v4l2_device *v4l2_dev,
error_unregister: error_unregister:
#if defined(CONFIG_MEDIA_CONTROLLER) #if defined(CONFIG_MEDIA_CONTROLLER)
media_device_unregister_entity(entity); media_device_unregister_entity(&sd->entity);
#endif #endif
error_module: error_module:
if (!sd->owner_v4l2_dev) if (!sd->owner_v4l2_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