Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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")

Signed-off-by: Eugen Hristev <eugen.hristev@microchip.com>
Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>

authored by

Eugen Hristev and committed by
Mauro Carvalho Chehab
aead0ffb 6990570f

+2 -5
+2 -5
drivers/media/v4l2-core/v4l2-device.c
··· 111 111 int v4l2_device_register_subdev(struct v4l2_device *v4l2_dev, 112 112 struct v4l2_subdev *sd) 113 113 { 114 - #if defined(CONFIG_MEDIA_CONTROLLER) 115 - struct media_entity *entity = &sd->entity; 116 - #endif 117 114 int err; 118 115 119 116 /* Check for valid input */ ··· 140 143 #if defined(CONFIG_MEDIA_CONTROLLER) 141 144 /* Register the entity. */ 142 145 if (v4l2_dev->mdev) { 143 - err = media_device_register_entity(v4l2_dev->mdev, entity); 146 + err = media_device_register_entity(v4l2_dev->mdev, &sd->entity); 144 147 if (err < 0) 145 148 goto error_module; 146 149 } ··· 160 163 161 164 error_unregister: 162 165 #if defined(CONFIG_MEDIA_CONTROLLER) 163 - media_device_unregister_entity(entity); 166 + media_device_unregister_entity(&sd->entity); 164 167 #endif 165 168 error_module: 166 169 if (!sd->owner_v4l2_dev)