All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mauro Carvalho Chehab <mchehab@redhat.com>
To: Laurent Defert <laurent.defert@smartjog.com>
Cc: linux-media@vger.kernel.org
Subject: Re: [PATCH] [media] compat_ioctl: add compat handler for FE_SET_PROPERTY
Date: Mon, 07 Nov 2011 12:19:45 -0200	[thread overview]
Message-ID: <4EB7E901.4000700@redhat.com> (raw)
In-Reply-To: <4EA816E2.8080607@smartjog.com>

Em 26-10-2011 12:19, Laurent Defert  :
> Hello,
> 
> You'll find below a patch that implements the FE_SET_PROPERTY ioctl compat code. This code is reached  when a 32 bit application does the ioctl on a 64 bit kernel.
> There are other dvb ioctl that are missing from the compat layer (FE_GET_PROPERTY and  FE_SET_FRONTEND_TUNE_MODE), if this patch is ok, i'm going to write them as well.

If are there many things, then maybe the better would be to do what we've done with V4L: put the compat stuff
into a separate file (see drivers/media/video/v4l2-compat-ioctl32.c). The glue is done by adding,
at drivers/media/video/v4l2-dev.c:

   .compat_ioctl = v4l2_compat_ioctl32

at struct file_operations.

> 
> Laurent
> 
> commit 6647fda45d70d1947f2dff06c485aa64d78357d7
> Author: Laurent Defert <laurent.defert@smartjog.com>
> Date:   Wed Oct 26 14:32:29 2011 +0200
> 
> [media] compat_ioctl: add compat handler for FE_SET_PROPERTY
> 
> fixes following error seen on x86_64 kernel:
> ioctl32(dvblast:6973): Unknown cmd fd(3) cmd(40086f52){t:'o';sz:8} arg(0805a318) on /dev/dvb/adapter0/frontend0
> 
> The argument (struct dtv_properties) contains a pointer to an array of struct dtv_property.
> Both struct are converted to have proper pointer size.
> 
> Signed-off-by: Laurent Defert <laurent.defert@smartjog.com>
> 
> diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
> index 51352de..6b89ff0 100644
> --- a/fs/compat_ioctl.c
> +++ b/fs/compat_ioctl.c
> @@ -222,6 +222,84 @@ static int do_video_set_spu_palette(unsigned int fd, unsigned int cmd,
>      return err;
>  }
> 
> +struct compat_dtv_property {
> +    __u32 cmd;
> +    __u32 reserved[3];
> +    union {
> +        __u32 data;
> +        struct {
> +            __u8 data[32];
> +            __u32 len;
> +            __u32 reserved1[3];
> +            compat_uptr_t reserved2;
> +        } buffer;
> +    } u;
> +    int result;

Hmm... maybe it would be better to change from "int" to "s32".

> +};
> +
> +struct compat_dtv_properties {
> +    __u32 num;
> +    compat_uptr_t props;
> +};
> +
> +#define FE_SET_PROPERTY32    _IOW('o', 82, struct compat_dtv_properties)
> +
> +static int do_fe_set_property(unsigned int fd, unsigned int cmd,
> +        struct compat_dtv_properties __user *dtv32)
> +{
> +    struct dtv_properties __user *dtv;
> +    struct dtv_property __user *properties;
> +    struct compat_dtv_property __user *properties32;
> +    compat_uptr_t data;
> +
> +    int err;
> +    int i;
> +    __u32 num;
> +
> +    err = get_user(num, &dtv32->num);
> +    err |= get_user(data, &dtv32->props);
> +
> +    if(err)
> +        return -EFAULT;
> +
> +    dtv = compat_alloc_user_space(sizeof(struct dtv_properties) +
> +                    sizeof(struct dtv_property) * num);
> +    properties = (struct dtv_property*)((char*)dtv +
> +                    sizeof(struct dtv_properties));
> +
> +    err = put_user(properties, &dtv->props);
> +    err |= put_user(num, &dtv->num);
> +
> +    properties32 = compat_ptr(data);
> +
> +    if(err)
> +        return -EFAULT;

Please check it with checkpatch.pl. Coding style is wrong here and on a few other places.

> +
> +    for(i = 0; i < num; i++) {
> +        compat_uptr_t reserved2;
> +
> +        err |= copy_in_user(&properties[i], &properties32[i],
> +                (8 * sizeof(__u32)) + (32 * sizeof(__u8)));
> +        err |= get_user(reserved2, &properties32[i].u.buffer.reserved2);
> +        err |= put_user(compat_ptr(reserved2),
> + &properties[i].u.buffer.reserved2);
> +    }
> +
> +    if(err)
> +        return -EFAULT;
> +
> +    err = sys_ioctl(fd, FE_SET_PROPERTY, (unsigned long) dtv);
> +
> +    for(i = 0; i < num; i++) {
> +        if(copy_in_user(&properties[i].result, &properties32[i].result,
> +                                sizeof(int)))
> +            return -EFAULT;
> +    }
> +
> +    return err;
> +}
> +
> +
>  #ifdef CONFIG_BLOCK
>  typedef struct sg_io_hdr32 {
>      compat_int_t interface_id;    /* [i] 'S' for SCSI generic (required) */
> @@ -1470,6 +1548,8 @@ static long do_ioctl_trans(int fd, unsigned int cmd,
>          return do_video_stillpicture(fd, cmd, argp);
>      case VIDEO_SET_SPU_PALETTE:
>          return do_video_set_spu_palette(fd, cmd, argp);
> +    case FE_SET_PROPERTY32:
> +        return do_fe_set_property(fd, cmd, argp);
>      }
> 
>      /*
> 
> -- 
> To unsubscribe from this list: send the line "unsubscribe linux-media" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html


      reply	other threads:[~2011-11-07 14:20 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-26 14:19 [PATCH] [media] compat_ioctl: add compat handler for FE_SET_PROPERTY Laurent Defert
2011-11-07 14:19 ` Mauro Carvalho Chehab [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4EB7E901.4000700@redhat.com \
    --to=mchehab@redhat.com \
    --cc=laurent.defert@smartjog.com \
    --cc=linux-media@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.