Skip to contentSkip to conversation

media: v4l2-core: fix entity initialization in device_register_subdev

PATCH In review Eugen Hristev 2 participants 2 messages Feb 26, 2020 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 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 61f5db549dde ("[media] v4l: Make v4l2_subdev inherit from media_entity")

---
Changes in v2:
- replaced entity with &sd->entity completely as suggested

 drivers/media/v4l2-core/v4l2-device.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/media/v4l2-core/v4l2-device.c +2 -5
index 63d6b147b21e..fa9c806a8ccd 100644
@@ -111,9 +111,6 @@ EXPORT_SYMBOL_GPL(v4l2_device_unregister);
 int v4l2_device_register_subdev(struct v4l2_device *v4l2_dev,
 				struct v4l2_subdev *sd)
 {
-#if defined(CONFIG_MEDIA_CONTROLLER)
-	struct media_entity *entity = &sd->entity;
-#endif
 	int err;
 
 	/* Check for valid input */
@@ -143,7 +140,7 @@ int v4l2_device_register_subdev(struct v4l2_device *v4l2_dev,
 #if defined(CONFIG_MEDIA_CONTROLLER)
 	/* Register the entity. */
 	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)
 			goto error_module;
 	}
@@ -163,7 +160,7 @@ int v4l2_device_register_subdev(struct v4l2_device *v4l2_dev,
 
 error_unregister:
 #if defined(CONFIG_MEDIA_CONTROLLER)
-	media_device_unregister_entity(entity);
+	media_device_unregister_entity(&sd->entity);
 #endif
 error_module:
 	if (!sd->owner_v4l2_dev)
Signature · 1 line
2.20.1
Acked-by on v2 1/1
#1 lore raw
Quoted 9 lines · Eugen Hristev

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 61f5db549dde ("[media] v4l: Make v4l2_subdev inherit from media_entity")

Thanks!

Signature · 1 line
Sakari Ailus