• Trent Piepho's avatar
    V4L/DVB (10811): videodev: only copy needed part of RW ioctl's parameter · 19c96e4b
    Trent Piepho authored
    There are many RW ioctls() in v4l2 where userspace only supplies one or two
    of the first fields in the structure passed to the ioctl.  The driver then
    fills in the rest of the fields.
    
    Instead of copying the entire structure from userspace to the kernel we
    only need to copy those fields that userspace is actually supposed to
    supply.
    
    What's more, the fields that are meant to be only be output from the driver
    can be zeroed out in the videodev code, in case the driver doesn't fill
    them all in.  Many of the ioctl handlers in v4l2_ioctl do this already, but
    my patch does this at one common point and so all the memsets for each
    ioctl can be deleted.
    
    For VIDIOC_G_SLICED_VBI_CAP, which has one input field ('type') and other
    output-only fields, the input field is near the end of the structure
    instead of at the beginning.  So there is still a memset in it's ioctl
    handler to zero out the beginning of the struct.
    
    There were a couple mistakes with the existing code:
        For VIDIOC_G_AUDIO the index field was preserved, but G_AUDIO is a read
        only ioctl so nothing is copied from userspace to preserve.
    
        For VIDIOC_G_FREQUENCY the tuner field was not preserved like it should
        have been.  This would be a problem if there was any hardware with more
        than one tuner/modulator.
    
        For VIDIOC_ENUM_FRAMESIZES and VIDIOC_ENUM_FRAMEINTERVALS, none of the
        fields were preserved even though each ioctl has several field that are
        supposed to be inputs to the driver!  Obviously these ioctls don't get
        used much.  The index field is needed if the driver has multiple
        discrete sizes/rates and other fields can be used too, e.g. if the size
        depends on pixel format or frame rate depends on image size for
        example.
    Signed-off-by: default avatarTrent Piepho <xyzzy@speakeasy.org>
    Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
    19c96e4b
v4l2-ioctl.c 51.3 KB