sd->entity.graph_obj.mdev can be NULL when this function is called, and
that breaks existing drivers (rcar-vin, but probably others as well).

Check if sd->entity.num_pads is non-zero instead since that doesn't depend
on mdev.

Signed-off-by: Hans Verkuil <hverkuil-ci...@xs4all.nl>
Reported-by: Niklas Söderlund <niklas.soderlund+rene...@ragnatech.se>
Fixes: a8fa55078a77 ("media: v4l2-subdev: Verify arguments in 
v4l2_subdev_call()")
---
diff --git a/drivers/media/v4l2-core/v4l2-subdev.c 
b/drivers/media/v4l2-core/v4l2-subdev.c
index 21fb90d66bfc..bc32fc1e0c0b 100644
--- a/drivers/media/v4l2-core/v4l2-subdev.c
+++ b/drivers/media/v4l2-core/v4l2-subdev.c
@@ -124,16 +124,11 @@ static inline int check_which(__u32 which)
 static inline int check_pad(struct v4l2_subdev *sd, __u32 pad)
 {
 #if defined(CONFIG_MEDIA_CONTROLLER)
-       if (sd->entity.graph_obj.mdev) {
-               if (pad >= sd->entity.num_pads)
-                       return -EINVAL;
-               return 0;
-       }
+       if (sd->entity.num_pads)
+               return pad >= sd->entity.num_pads ? -EINVAL : 0;
 #endif
        /* allow pad 0 on subdevices not registered as media entities */
-       if (pad > 0)
-               return -EINVAL;
-       return 0;
+       return pad ? -EINVAL : 0;
 }

 static int check_cfg(__u32 which, struct v4l2_subdev_pad_config *cfg)

Reply via email to