media: imx274: initialize format before v4l2 controls
authorLuca Ceresoli <luca@lucaceresoli.net>
Mon, 11 Jun 2018 11:35:32 +0000 (07:35 -0400)
committerMauro Carvalho Chehab <mchehab+samsung@kernel.org>
Wed, 4 Jul 2018 11:23:54 +0000 (07:23 -0400)
commit438ac1fd5e1e132782795ba474b97fffbc79bbd5
tree98392d17fb9ba0981e4f6b946f27783c481e0150
parent90ee26fb2f50e1e57f9d957a1799af1bcafd9671
media: imx274: initialize format before v4l2 controls

The current probe function calls v4l2_ctrl_handler_setup() before
initializing the format info. This triggers call paths such as:
imx274_probe -> v4l2_ctrl_handler_setup -> imx274_s_ctrl ->
imx274_set_exposure, where priv->mode_index is accessed before being
assigned.

This is wrong but does not trigger a visible bug because priv is
zero-initialized and 0 is the default value for priv->mode_index. But
this would become a crash in follow-up commits when mode_index is
replaced by a pointer that must always be valid.

Fix the bug before it shows up by initializing struct members early.

Signed-off-by: Luca Ceresoli <luca@lucaceresoli.net>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
drivers/media/i2c/imx274.c