v4l: subdev: Fail graciously when getting try data for NULL state
PATCH 1/1 v4l: subdev: Fail graciously when getting try data for NULL state
The state argument for the functions for obtaining various parts of the state is NULL if it is called by drivers for active state. Fail graciously in that case instead of dereferencing a NULL pointer.
Suggested-by Bingbu Cao <[email protected]>
Signed-off-by Sakari Ailus <[email protected]>
--- include/media/v4l2-subdev.h | 6 ++++++ 1 file changed, 6 insertions(+)
include/media/v4l2-subdev.h +6 -0
@@ -1046,6 +1046,8 @@ v4l2_subdev_get_pad_format(struct v4l2_subdev *sd, struct v4l2_subdev_state *state, unsigned int pad) { + if (WARN_ON(!state)) + return NULL;if (WARN_ON (pad >= sd->entity.num_pads)) pad =0 ;return &state->pads[pad].try_fmt;
@@ -1064,6 +1066,8 @@ v4l2_subdev_get_pad_crop(struct v4l2_subdev *sd, struct v4l2_subdev_state *state, unsigned int pad) { + if (WARN_ON(!state)) + return NULL;if (WARN_ON (pad >= sd->entity.num_pads)) pad =0 ;return &state->pads[pad].try_crop;
@@ -1082,6 +1086,8 @@ v4l2_subdev_get_pad_compose(struct v4l2_subdev *sd, struct v4l2_subdev_state *state, unsigned int pad) { + if (WARN_ON(!state)) + return NULL;if (WARN_ON (pad >= sd->entity.num_pads)) pad =0 ;return &state->pads[pad].try_compose;
Signature · 1 line
2.30.2
Quoted 2 lines · Sakari Ailus
The state argument for the functions for obtaining various parts of the state is NULL if it is called by drivers for active state. Fail graciously
Only for drivers that do not use active state. Which is most of them at the moment.
Quoted 31 lines
in that case instead of dereferencing a NULL pointer.
Suggested-by Bingbu Cao <[email protected]>Signed-off-by Sakari Ailus <[email protected]>--- include/media/v4l2-subdev.h | 6 ++++++ 1 file changed, 6 insertions(+)include/media/v4l2-subdev.h +4
-0@@ -1046,6 +1046,8 @@ v4l2_subdev_get_pad_format(struct v4l2_subdev *sd, struct v4l2_subdev_state *state, unsigned int pad) { + if (WARN_ON(!state)) + return NULL;if (WARN_ON (pad >= sd->entity.num_pads)) pad =0 ;return &state->pads[pad].try_fmt;@@ -1064,6 +1066,8 @@ v4l2_subdev_get_pad_crop(struct v4l2_subdev *sd, struct v4l2_subdev_state *state, unsigned int pad) { + if (WARN_ON(!state)) + return NULL;if (WARN_ON (pad >= sd->entity.num_pads)) pad =0 ;return &state->pads[pad].try_crop;
include/media/v4l2-subdev.h v4l2_subdev_get_pad_compose(struct v4l2_subdev *sd, · line 1093
Quoted 8 lines
include/media/v4l2-subdev.h +2
-0@@ -1082,6 +1086,8 @@ v4l2_subdev_get_pad_compose(struct v4l2_subdev *sd, struct v4l2_subdev_state *state, unsigned int pad) { + if (WARN_ON(!state)) + return NULL;if (WARN_ON (pad >= sd->entity.num_pads)) pad =0 ;return &state->pads[pad].try_compose;
Reviewed-by Tomi Valkeinen <[email protected]>
Tomi