Skip to contentSkip to conversation

v4l: subdev: Fail graciously when getting try data for NULL state

PATCH In review Sakari Ailus 2 participants 2 messages Aug 26, 2022 – Aug 29, 2022 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

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.

---
 include/media/v4l2-subdev.h | 6 ++++++
 1 file changed, 6 insertions(+)
include/media/v4l2-subdev.h +6 -0
index 9689f38a0af1f..ec1896886dbd6 100644
@@ -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
Reviewed-by on v1 1/1
#1 lore raw
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.

---
  include/media/v4l2-subdev.h | 6 ++++++
  1 file changed, 6 insertions(+)
include/media/v4l2-subdev.h +4 -0
index 9689f38a0af1f..ec1896886dbd6 100644
@@ -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;

Tomi