media: v4l: subdev: Fail graciously when getting try data for NULL state
authorSakari Ailus <sakari.ailus@linux.intel.com>
Fri, 26 Aug 2022 11:53:58 +0000 (13:53 +0200)
committerMauro Carvalho Chehab <mchehab@kernel.org>
Sat, 24 Sep 2022 07:05:02 +0000 (09:05 +0200)
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 <bingbu.cao@intel.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Reviewed-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
include/media/v4l2-subdev.h

index 9689f38a0af1fd661d81f9fb4e25644254771d01..ec1896886dbd6609467760c5dd30ca43be228f99 100644 (file)
@@ -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;