Commit 2ba3e385 authored by Sakari Ailus's avatar Sakari Ailus Committed by Mauro Carvalho Chehab

media: 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: default avatarBingbu Cao <bingbu.cao@intel.com>
Signed-off-by: default avatarSakari Ailus <sakari.ailus@linux.intel.com>
Reviewed-by: default avatarTomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@kernel.org>
parent b9eb3ab6
...@@ -1046,6 +1046,8 @@ v4l2_subdev_get_pad_format(struct v4l2_subdev *sd, ...@@ -1046,6 +1046,8 @@ v4l2_subdev_get_pad_format(struct v4l2_subdev *sd,
struct v4l2_subdev_state *state, struct v4l2_subdev_state *state,
unsigned int pad) unsigned int pad)
{ {
if (WARN_ON(!state))
return NULL;
if (WARN_ON(pad >= sd->entity.num_pads)) if (WARN_ON(pad >= sd->entity.num_pads))
pad = 0; pad = 0;
return &state->pads[pad].try_fmt; return &state->pads[pad].try_fmt;
...@@ -1064,6 +1066,8 @@ v4l2_subdev_get_pad_crop(struct v4l2_subdev *sd, ...@@ -1064,6 +1066,8 @@ v4l2_subdev_get_pad_crop(struct v4l2_subdev *sd,
struct v4l2_subdev_state *state, struct v4l2_subdev_state *state,
unsigned int pad) unsigned int pad)
{ {
if (WARN_ON(!state))
return NULL;
if (WARN_ON(pad >= sd->entity.num_pads)) if (WARN_ON(pad >= sd->entity.num_pads))
pad = 0; pad = 0;
return &state->pads[pad].try_crop; return &state->pads[pad].try_crop;
...@@ -1082,6 +1086,8 @@ v4l2_subdev_get_pad_compose(struct v4l2_subdev *sd, ...@@ -1082,6 +1086,8 @@ v4l2_subdev_get_pad_compose(struct v4l2_subdev *sd,
struct v4l2_subdev_state *state, struct v4l2_subdev_state *state,
unsigned int pad) unsigned int pad)
{ {
if (WARN_ON(!state))
return NULL;
if (WARN_ON(pad >= sd->entity.num_pads)) if (WARN_ON(pad >= sd->entity.num_pads))
pad = 0; pad = 0;
return &state->pads[pad].try_compose; return &state->pads[pad].try_compose;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment