On 02/09/18 12:46, Sakari Ailus wrote: > Hi Hans, > > On Thu, Feb 08, 2018 at 09:36:44AM +0100, Hans Verkuil wrote: >> If the subdev did not define any controls, then return -ENOTTY if >> userspace attempts to call these ioctls. >> >> The control framework functions will return -EINVAL, not -ENOTTY if >> vfh->ctrl_handler is NULL. >> >> Several of these framework functions are also called directly from >> drivers, so I don't want to change the error code there. >> >> Found with vimc and v4l2-compliance. >> >> Signed-off-by: Hans Verkuil <hans.verkuil@xxxxxxxxx> > > Thanks for the patch. > > If the handler is NULL, can there be support for the IOCTL at all? I.e. > should the missing handler as such result in returning -ENOTTY from these > functions instead of -EINVAL? I didn't dare change the control framework. Some of these v4l2_... functions are called by drivers and I didn't want to analyze them all. If these functions were only called by v4l2-ioctl.c and v4l2-subdev.c, then I'd have changed it in v4l2-ctrls.c, but that's not the case. It would be a useful project to replace all calls from drivers to these functions (they really shouldn't be used by drivers), but that is out-of-scope of this patch. Regards, Hans > >> --- >> drivers/media/v4l2-core/v4l2-subdev.c | 16 ++++++++++++++++ >> 1 file changed, 16 insertions(+) >> >> diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c >> index 43fefa73e0a3..be7a19272614 100644 >> --- a/drivers/media/v4l2-core/v4l2-subdev.c >> +++ b/drivers/media/v4l2-core/v4l2-subdev.c >> @@ -187,27 +187,43 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg) >> >> switch (cmd) { >> case VIDIOC_QUERYCTRL: >> + if (!vfh->ctrl_handler) >> + return -ENOTTY; >> return v4l2_queryctrl(vfh->ctrl_handler, arg); >> >> case VIDIOC_QUERY_EXT_CTRL: >> + if (!vfh->ctrl_handler) >> + return -ENOTTY; >> return v4l2_query_ext_ctrl(vfh->ctrl_handler, arg); >> >> case VIDIOC_QUERYMENU: >> + if (!vfh->ctrl_handler) >> + return -ENOTTY; >> return v4l2_querymenu(vfh->ctrl_handler, arg); >> >> case VIDIOC_G_CTRL: >> + if (!vfh->ctrl_handler) >> + return -ENOTTY; >> return v4l2_g_ctrl(vfh->ctrl_handler, arg); >> >> case VIDIOC_S_CTRL: >> + if (!vfh->ctrl_handler) >> + return -ENOTTY; >> return v4l2_s_ctrl(vfh, vfh->ctrl_handler, arg); >> >> case VIDIOC_G_EXT_CTRLS: >> + if (!vfh->ctrl_handler) >> + return -ENOTTY; >> return v4l2_g_ext_ctrls(vfh->ctrl_handler, arg); >> >> case VIDIOC_S_EXT_CTRLS: >> + if (!vfh->ctrl_handler) >> + return -ENOTTY; >> return v4l2_s_ext_ctrls(vfh, vfh->ctrl_handler, arg); >> >> case VIDIOC_TRY_EXT_CTRLS: >> + if (!vfh->ctrl_handler) >> + return -ENOTTY; >> return v4l2_try_ext_ctrls(vfh->ctrl_handler, arg); >> >> case VIDIOC_DQEVENT: >