libcamera: camera_sensor: Only access V4L_CID_HBLANK if existing

Correct a crash in CameraSensor::init() when trying to set the
V4L2_CID_HBLANK control on sensor not implementing this control. The
HBLANK sensor not being mandatory for non-RAW sensors, it can happen
that the sensor does not expose this control. Perform check against
availability of the control prior to usage in order to avoid the crash.

Signed-off-by: Alain Volmat <alain.volmat@foss.st.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
Alain Volmat 2023-11-13 11:08:51 +01:00 committed by Laurent Pinchart
parent 34b248c88f
commit 882d04d740

View file

@ -197,17 +197,19 @@ int CameraSensor::init()
* \todo The control API ought to have a flag to specify if a control * \todo The control API ought to have a flag to specify if a control
* is read-only which could be used below. * is read-only which could be used below.
*/ */
const ControlInfo hblank = ctrls.infoMap()->at(V4L2_CID_HBLANK); if (ctrls.infoMap()->find(V4L2_CID_HBLANK) != ctrls.infoMap()->end()) {
const int32_t hblankMin = hblank.min().get<int32_t>(); const ControlInfo hblank = ctrls.infoMap()->at(V4L2_CID_HBLANK);
const int32_t hblankMax = hblank.max().get<int32_t>(); const int32_t hblankMin = hblank.min().get<int32_t>();
const int32_t hblankMax = hblank.max().get<int32_t>();
if (hblankMin != hblankMax) { if (hblankMin != hblankMax) {
ControlList ctrl(subdev_->controls()); ControlList ctrl(subdev_->controls());
ctrl.set(V4L2_CID_HBLANK, hblankMin); ctrl.set(V4L2_CID_HBLANK, hblankMin);
ret = subdev_->setControls(&ctrl); ret = subdev_->setControls(&ctrl);
if (ret) if (ret)
return ret; return ret;
}
} }
return applyTestPatternMode(controls::draft::TestPatternModeEnum::TestPatternModeOff); return applyTestPatternMode(controls::draft::TestPatternModeEnum::TestPatternModeOff);